Пример #1
0
 private void CreateBullet(GameTime gameTime)
 {
     if (gameTime.TotalGameTime - previousBulletSpawnTime > bulletSpawnTime)
     {
         previousBulletSpawnTime = gameTime.TotalGameTime;
         var bullet = new PlayerBullet();
         bullet.Initialize(playerBullet, new Vector2(
                               player.Position.X + player.Width / 2
                               , player.Position.Y - player.Height / 4));
         bullets.Add(bullet);
     }
 }
Пример #2
0
        public Player()
        {
            Vector2 startPosition = new Vector2(GfxTools.Win.width / 2 - sprite.Width / 2, GfxTools.Win.height - Game.Edge * 1.5f - sprite.Height);

            sprite           = new SpriteObj("Assets/player.png", startPosition);
            centeredPosition = new Vector2(sprite.Position.X + sprite.Width / 2, sprite.Position.Y + sprite.Height / 2);
            for (int i = 0; i < bullets.Length; i++)
            {
                SpriteObj bulletSprite = new SpriteObj("Assets/playerBullet.png");
                bullets[i] = new PlayerBullet(bulletSprite);
            }
        }
Пример #3
0
 public GameManager(int panelWidth, int panelHeight)
 {
     playerSprites.Add(new Bitmap(Resources.player));
     playerDSprites.Add(new Bitmap(Resources.PlayerExplosion1));
     playerDSprites.Add(new Bitmap(Resources.PlayerExplosion2));
     bulletSprites.Add(new Bitmap(Resources.PlayerShot));
     bulletDSprites.Add(new Bitmap(Resources.PlayerShotExplosion));
     mainShip     = new MainShip(300, 716, playerSprites, playerDSprites, panelWidth, panelHeight);
     bullet       = new PlayerBullet(-100, -100, bulletSprites, bulletDSprites, panelWidth, panelHeight);
     enemyManager = new EnemyManager(panelWidth, panelHeight);
     enemyManager.GenerateEnemies();
     player.Open(new Uri(Util.bingPathToAppDir("Resources\\invaderkilled.wav")));
 }
Пример #4
0
 public static bool IsCollideWithBullet(PlayerBullet bullet)
 {
     for (int i = 0; i < enemies.Length; i++)
     {
         if (enemies[i].IsCollideWithBullet(bullet))
         {
             enemiesAlive--;
             MovementSpeedmodifier();
             lowestRow = GetLowestRowAlive();
             return(true);
         }
     }
     return(false);
 }
Пример #5
0
 public static bool BulletCollideWithBullet(PlayerBullet bullet)
 {
     for (int i = 0; i < bullets.Length; i++)
     {
         if (!bullets[i].IsFired)
         {
             continue;
         }
         if (bullets[i].Point.Sub(bullet.Point).GetLength() < bullets[i].Sprite.Width / 1.5f + bullet.Width / 1.5f ||
             bullets[i].Point.Sub(new Vector2(bullet.Point.X, bullet.Sprite.Height)).GetLength() < bullets[i].Sprite.Width / 1.5f + bullet.Width / 1.5f)
         {
             bullets[i].IsFired = false;
             bullet.IsFired     = false;
             return(true);
         }
     }
     return(false);
 }
        public override void Update()
        {
            if (Input.KeyPressed(ConsoleKey.RightArrow))
            {
                xPos = xPos + 8;
            }

            if (Input.KeyPressed(ConsoleKey.LeftArrow))
            {
                xPos = xPos - 8;
            }

            if (Input.KeyPressed(ConsoleKey.Spacebar))
            {
                GameObject tmpBullet = new PlayerBullet();
                tmpBullet.Parent = Parent;
                tmpBullet.xPos   = xPos + 8;
                tmpBullet.yPos   = yPos - 1;
                tmpBullet.Start();
                Parent.GameObjects.Add(tmpBullet);
            }
        }