SpaceInvaders (Linkedlist)
Hej. Er lige gået igang med et spaceinvaders spil, er ikke nået så langt, og har rodet lidt med linkedlists til at opbevare mine Vector2 skud i.Men hvordan kan jeg gå ind og ændre values i den liste så skudene bevæger sig opad? Har hele min kildekode her:
namespace SpaceInvaders
{
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Texture2D Tex_Ship;
Vector2 Vec_Ship = new Vector2(450.0f, 660.0f);
Texture2D Tex_Rock;
Vector2 Vec_Rock = new Vector2(200.0f,100.0f);
Texture2D Tex_Shot;
Vector2 Vec_Shot;
LinkedList<Vector2> List_Rock = new LinkedList<Vector2>();
LinkedList<Vector2> List_Shot = new LinkedList<Vector2>();
Random randomizer = new Random();
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
graphics.PreferredBackBufferWidth = 1024;
graphics.PreferredBackBufferHeight = 768;
graphics.IsFullScreen = true;
graphics.ApplyChanges();
Window.Title = "Space Invaders";
base.Initialize();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
Tex_Ship = Content.Load<Texture2D>("ship");
Tex_Shot = Content.Load<Texture2D>("shot");
}
protected override void UnloadContent()
{
}
protected override void Update(GameTime gameTime)
{
if (Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.Escape)) this.Exit();
if (Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.Right)) Vec_Ship.X += 5.0f;
if (Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.Left)) Vec_Ship.X -= 5.0f;
if (Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.Space)) List_Shot.AddLast(new Vector2(Vec_Ship.X, Vec_Ship.Y));
CheckColl();
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.Black);
spriteBatch.Begin(SpriteBlendMode.AlphaBlend);
spriteBatch.Draw(Tex_Ship, Vec_Ship, Color.White);
MoveShots();
spriteBatch.End();
base.Draw(gameTime);
}
void CheckColl()
{
if (Vec_Ship.X <= 0) Vec_Ship.X = 1;
// Also check Righthand side
}
void MoveShots()
{
foreach (Vector2 Vec_Shot in List_Shot)
{
spriteBatch.Draw(Tex_Shot,Vec_Shot,Color.White);
}
}
}
}