Futzy
April 27th, 2010, 10:04 PM
Me and DEE want to make apps for Zune HD. I can make all the graphical shits but DEE needs help with coding.
Also need good ideas. Anyone?
DEElekgolo
April 27th, 2010, 10:05 PM
Hi.
XNA is fun but its hard to do anything cool in it.
DEElekgolo
April 29th, 2010, 09:46 AM
So I made a app that basically lets you draw up to 100 dots which bounce around the edge of the screen using a bunch of if statements.
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
namespace ZuneTEST
{
/// <summary>
/// This is the main type for your game
/// </summary>
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Texture2D smallbox;
SpriteFont Kootenay;
List<Dot> dots = new List<Dot>();
class Dot
{
public Vector2 position;
public Vector2 speed;
public Color color;
public Dot(float x, float y)
{
position = new Vector2(x, y);
}
public Color DotColor()
{
color = new Color(speed.X*5, speed.Y*5, 255);
return color;
}
}
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
// Frame rate is 30 fps by default for Zune.
TargetElapsedTime = TimeSpan.FromSeconds(1 / 30.0);
}
/// <summary>
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
/// </summary>
protected override void Initialize()
{
Vector2 centerscreen = new Vector2(graphics.GraphicsDevice.Viewport.Width / 2, graphics.GraphicsDevice.Viewport.Height / 2);
dots.Add(new Dot(centerscreen.X,centerscreen.Y));
// TODO: Add your initialization logic here
base.Initialize();
}
/// <summary>
/// LoadContent will be called once per game and is the place to load
/// all of your content.
/// </summary>
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
smallbox = CreateRectangle(2, 2);
Kootenay = Content.Load<SpriteFont>("Kootenay");
// TODO: use this.Content to load your game content here
}
/// <summary>
/// UnloadContent will be called once per game and is the place to unload
/// all content.
/// </summary>
protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
}
/// <summary>
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
//add dots by touch
TouchCollection touchCollect = TouchPanel.GetState();//touch
AccelerometerState accelState = Accelerometer.GetState();//acceleration
float time = gameTime.ElapsedGameTime.Milliseconds;//time
float movefactor = 0.01f;//physics movement factor
int maxDots = 100;
foreach (TouchLocation tl in touchCollect)
{
dots.Add(new Dot(tl.Position.X,tl.Position.Y));
if (dots.Count > maxDots)
{
dots.RemoveAt(0);
}
}
//shit physics
foreach (Dot d in dots)
{
float gravityMul = 2.0f;
//bounce if it hits the edge of the screen
d.speed.X += (accelState.Acceleration.X)*gravityMul * movefactor;
d.speed.Y -= (accelState.Acceleration.Y)*gravityMul * movefactor;
d.position += d.speed * time;
d.position = Vector2.Clamp(d.position, new Vector2(0, 0), new Vector2(graphics.GraphicsDevice.Viewport.Width-1, graphics.GraphicsDevice.Viewport.Height-1));
//all these if statements negate the velocity of the dots if they touch the edge of teh screen
float bounceMul = 0.5f;
Random random = new Random();
//on the x axis
if (d.position.X <= 0.0f)
{
d.speed.X = (d.speed.X * -1)*bounceMul;
}
if (d.position.X >= graphics.GraphicsDevice.Viewport.Width-1)
{
d.speed.X = (d.speed.X * -1)*bounceMul;
}
//and the y axis
if (d.position.Y <= 0.0f)
{
d.speed.Y = (d.speed.Y * -1)*bounceMul;
}
if (d.position.Y >= graphics.GraphicsDevice.Viewport.Height-1)
{
d.speed.Y = (d.speed.Y * -1)*bounceMul;
}
}
// TODO: Add your update logic here
base.Update(gameTime);
}
/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.Black);
// TODO: Add your drawing code here
spriteBatch.Begin();
//spriteBatch.Draw(smallbox, centerscreen, Color.Red);
foreach (Dot d in dots)
{
spriteBatch.Draw(smallbox, d.position, d.DotColor());
}
//DrawText("Particle simulator",new Vector2(graphics.GraphicsDevice.Viewport.Width/2,20));
spriteBatch.End();
base.Draw(gameTime);
}
/////////////////////ADD COOL METHODS HERE/////////////////////////////////////
//makes white rectangle textures
private Texture2D CreateRectangle(int width, int height)
{
Texture2D rectangleTexture = new Texture2D(GraphicsDevice, width, height, 1, TextureUsage.None,
SurfaceFormat.Color);// create the rectangle texture, ,but it will have no color! lets fix that
Color[] color = new Color[width * height];//set the color to the amount of pixels in the textures
for (int i = 0; i < color.Length; i++)//loop through all the colors setting them to whatever values we want
{
color[i] = Color.White;
}
rectangleTexture.SetData(color);//set the color data on the texture
return rectangleTexture;//return the texture
}
//Gets the zune acceleration yeyeyeye
private Vector3 Acceleration()
{
Vector3 acceleration = new Vector3();
AccelerometerState accelState = Accelerometer.GetState();
acceleration = new Vector3(accelState.Acceleration.X, accelState.Acceleration.Y, accelState.Acceleration.Z);
return acceleration;
}
//makes a 1x1 white pixel. It will not show. Tegra's lowest supported texture is 4x4
private Texture2D GetWhitePixel()
{
Texture2D pixel = new Texture2D(graphics.GraphicsDevice, 1, 1);
pixel.SetData<uint>(new uint[] { 0xFFFFFFFF });
return pixel;
}
//random color
private Color randomColor()
{
Random random = new Random();
Color color = new Color();
color.R = (byte)random.Next(255);
color.B = (byte)random.Next(255);
color.G = (byte)random.Next(255);
return color;
}
//draw text
private void DrawText(String text, Vector2 atWhere)
{
Vector2 textOrigin = Kootenay.MeasureString(text) / 2;
spriteBatch.DrawString(Kootenay, text, atWhere, Color.White,
0.0f, textOrigin, 1, SpriteEffects.None, 0.5f);
}
}
}
How would I make it so the "dots" would each apply force outwards so that the dots' position maintain a certain distance. I don't mean to just stop once they are at a certain distance. I mean that they would "try" to maintain a distance by emitting force in all directions. I'm trying to make it seem like fluid.
Warsaw
May 1st, 2010, 01:37 AM
^ Needs moar whitespace. @_@
Also, what are you interested in doing for the Zune HD in particular?
Limited
May 1st, 2010, 10:20 AM
Zune uses XNA? :O I've always wanted to code accelerometer/touch screen.
By the way, what your asking to do is a lot more difficult than just bouncing the walls of the edge of the screen. A it wouldnt be a quick implementation
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.