public Collision(Sprite playerSprite, Alien alien, BulletList bullets, Asteroid asteroids) { this.playerSprite = playerSprite; this.alien = alien; this.bullets = bullets; this.asteroids = asteroids; }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { player = new Sprite(graphics, Content.Load <Texture2D>("playerShip")); alien = new Alien(Content, graphics, player); spriteBatch = new SpriteBatch(GraphicsDevice); background = new Background(graphics.GraphicsDevice, spriteBatch, Content); bullets = new BulletList(); asteroids = new Asteroid(Content, graphics); keyboard = new KeyBoardManager(Content); collision = new Collision(player, alien, bullets, asteroids); font = Content.Load <SpriteFont>("Font"); }
public void Update(KeyboardState state, GraphicsDeviceManager graphics, Sprite playerSprite, BulletList bullets) { _currentKeyboard = state; if (_currentKeyboard.IsKeyDown(Keys.Left)) { playerSprite.Rotation -= 0.05f; } if (_currentKeyboard.IsKeyDown(Keys.Right)) { playerSprite.Rotation += 0.05f; } if (WasJustPressed(Keys.Space)) { Sprite newBullet = new Sprite(graphics, bulletImage); newBullet.velocity = new Vector2((float)Math.Cos(playerSprite.Rotation - MathHelper.PiOver2), (float)Math.Sin(playerSprite.Rotation - MathHelper.PiOver2)) * 4.0f + playerSprite.velocity; newBullet.position = playerSprite.position + newBullet.velocity * 1.75f; newBullet.Rotation = playerSprite.Rotation; bullets.Add(newBullet); } if (_currentKeyboard.IsKeyDown(Keys.Up)) { playerSprite.velocity = new Vector2((float)Math.Cos(playerSprite.Rotation - MathHelper.PiOver2), (float)Math.Sin(playerSprite.Rotation - MathHelper.PiOver2)) / 4.0f + playerSprite.velocity; } //if (_currentKeyboard.IsKeyDown(Keys.Down)) //{ // _movement += Vector2.UnitY * .5f; //} _oldKeyboard = _currentKeyboard; }
public void Update(KeyboardState state, GraphicsDeviceManager graphics, Sprite playerSprite, BulletList bullets) { _currentKeyboard = state; if (_currentKeyboard.IsKeyDown(Keys.Left)) { playerSprite.Rotation -= 0.05f; } if (_currentKeyboard.IsKeyDown(Keys.Right)) { playerSprite.Rotation += 0.05f; } if (WasJustPressed(Keys.Space)) { Sprite newBullet = new Sprite(graphics, bulletImage); newBullet.velocity = new Vector2((float)Math.Cos(playerSprite.Rotation - MathHelper.PiOver2), (float)Math.Sin(playerSprite.Rotation - MathHelper.PiOver2)) * 4.0f + playerSprite.velocity; newBullet.position = playerSprite.position + newBullet.velocity * 1.75f; newBullet.Rotation = playerSprite.Rotation; bullets.Add(newBullet); } if (_currentKeyboard.IsKeyDown(Keys.Up)) { playerSprite.velocity = new Vector2((float)Math.Cos(playerSprite.Rotation - MathHelper.PiOver2), (float)Math.Sin(playerSprite.Rotation - MathHelper.PiOver2)) / 4.0f + playerSprite.velocity; } //if (_currentKeyboard.IsKeyDown(Keys.Down)) //{ // _movement += Vector2.UnitY * .5f; //} _oldKeyboard = _currentKeyboard; }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { player = new Sprite(graphics, Content.Load<Texture2D>("playerShip")); alien = new Alien(Content, graphics, player); spriteBatch = new SpriteBatch(GraphicsDevice); background = new Background(graphics.GraphicsDevice, spriteBatch, Content); bullets = new BulletList(); asteroids = new Asteroid(Content, graphics); keyboard = new KeyBoardManager(Content); collision = new Collision(player, alien, bullets, asteroids); font = Content.Load<SpriteFont>("Font"); }