public void Shoot() { //add bullet to list //bullet delay is more than 0 take away from bullet delay //what bullet is and its position //bullet count is more that 5 add bullet to list if (bulletDelay <= 0) { Bullet newBullet = new Bullet(bulletTexture); newBullet.position = new Vector2(position.X + texture.Width / 2 - bulletTexture.Width / 2, position.Y + 30); newBullet.isVisible = true; bulletDelay = 80; if (EnemyBulletList.Count < 5) { EnemyBulletList.Add(newBullet); } } if (bulletDelay >= 0) { bulletDelay--; } }
public bool TryShoot(GameTime gameTime, List<Bullet> shots) { // Check fire time if (gameTime.TotalGameTime.TotalMilliseconds - lastShootTime < ShootDelay) { return false; } lastShootTime = gameTime.TotalGameTime.TotalMilliseconds; // Calculate bullet position Vector2 bulletPosition = new Vector2( Position.X + Width / 2 - bulletAnimation.Width / 2, Position.Y + Height - bulletAnimation.Height); // Create bullet Bullet bullet = new Bullet(); bullet.Initialize((Animation)bulletAnimation.Clone(), bulletPosition, Direction.Up, Bullet.DefaultSpeed, bulletDamage); shots.Add(bullet); if (bulletSound != null) bulletSound.Play(); return true; }
public void Shoot() { if (bulletDelay <= 0) { Bullet newBullet = new Bullet(bulletTexture); newBullet.position = new Vector2(position.X + texture.Width / 2 - bulletTexture.Width / 2, position.Y + 30); newBullet.isVisible = true; bulletDelay = 80; if (bulletList.Count < 5) { bulletList.Add(newBullet); } } if (bulletDelay >= 0) { bulletDelay--; } }
public void Shoot() { //shoot only if the bullet delay resets if (bulletDelay >= 0) { bulletDelay--; } //if bullet delay has reset, draw new bullet and make it visible if (bulletDelay <= 0) { //sound Bullet newBullet = new Bullet(bulletTexture); newBullet.position = new Vector2(position.X + shipWidth / 2 - newBullet.texture.Width / 2, position.Y + 30); //positions bullet center of the player ship newBullet.isVisible = true; gs.playerShootSound.Play(); if (bulletList.Count() < 5) { bulletList.Add(newBullet); } } //resetting bullet delay if (bulletDelay == 0) { bulletDelay = 10;//10 } }
public void Update(GameTime gameTime) { if (Direction == Direction.Left) { Position.X -= MoveSpeed; if (Position.X < 0) { Position.X = 0; nextDirection = Direction.Right; Direction = Direction.Down; downStartPosition = Position.Y; } } else if (Direction == Direction.Right) { Position.X += MoveSpeed; if (Position.X + Width > ScreenSize.Width) { Position.X = ScreenSize.Width - Width; nextDirection = Direction.Left; Direction = Direction.Down; downStartPosition = Position.Y; } } else if (Direction == Direction.Down) { Position.Y += MoveSpeed; if (Position.Y > downStartPosition + stepDown) { Position.Y = downStartPosition + stepDown; Direction = nextDirection; } } for (int i = Invaders.Count - 1; i >= 0; i--) { Invaders[i].Position = CalcInvaderPosition(Position, Invaders[i].SquadPositionX, Invaders[i].SquadPositionY); Invaders[i].Update(gameTime); if (Invaders[i].IsCrossedBottom) IsCrossedBottom = true; if (!Invaders[i].Active) Invaders.RemoveAt(i); } // Shooting if (Bullets.Count < maxShot && ShootDelay < gameTime.TotalGameTime.TotalMilliseconds - lastShootTime) { Random r = new Random((int)gameTime.TotalGameTime.TotalMilliseconds); int f = r.Next(0, Invaders.Count); Vector2 bulletPosition = Invaders[f].Position; bulletPosition.X += Invaders[f].Width / 2; bulletPosition.Y += Invaders[f].Height; Bullet bullet = new Bullet(); bullet.Initialize((Animation)BulletAnimation.Clone(), bulletPosition, Direction.Down, Bullet.DefaultSpeed * 0.25f, 1); Bullets.Add(bullet); BulletSound.Play(); lastShootTime = gameTime.TotalGameTime.TotalMilliseconds; } }