Exemple #1
0
        public void Update(GameTime gameTime, ProjectileManager projectileManager)
        {
            if (Keyboard.GetState().IsKeyDown(Keys.W))
            {
                myShip.Move(0f, -myShip.Speed);
            }

            if (Keyboard.GetState().IsKeyDown(Keys.S))
            {
                myShip.Move(0f, myShip.Speed);
            }

            if (Keyboard.GetState().IsKeyDown(Keys.A))
            {
                myShip.Move(-myShip.Speed, 0f);
            }

            if (Keyboard.GetState().IsKeyDown(Keys.D))
            {
                myShip.Move(myShip.Speed, 0f);
            }

            myShip.Update(gameTime);
            myShip.FireWeapon(gameTime, projectileManager, myShip.Position, true);

            // Make sure that the player does not go out of bounds
            myShip.Position.X = MathHelper.Clamp(myShip.Position.X, 0, screenSize.X - texture.Width);
            myShip.Position.Y = MathHelper.Clamp(myShip.Position.Y, 0, screenSize.Y - texture.Height);
            CollisionBox = new Rectangle((int)myShip.Position.X, (int)myShip.Position.Y, texture.Width, texture.Height);
        }
        public void Update(GameTime gameTime, ProjectileManager projectilemanager)
        {
            if (gameTime.TotalGameTime - previousSpawnTime > enemySpawnTime)
            {
                Spawn();
                previousSpawnTime = gameTime.TotalGameTime;

            }

            enemyManager.Update(gameTime, projectilemanager);
        }
Exemple #3
0
 public void Update(GameTime gametime, ProjectileManager projectilemanager)
 {
     Position.X -= myShip.Speed;
     CollisionBox = new Rectangle((int)Position.X, (int)Position.Y, myShip.ShipTexture.Width, myShip.ShipTexture.Height);
     if (Position.X < -myShip.ShipTexture.Width)
     {
         Active = false;
     }
     if (myShip.Health <= 0)
     {
         Active = false;
         Player.Score += myShip.Points;
     }
     myShip.FireWeapon(gametime, projectilemanager, Position, false);
 }
Exemple #4
0
 public void fire(GameTime gameTime, ProjectileManager projectileManager, Vector2 postition, bool isplayer, Ship ship)
 {
     if (gameTime.TotalGameTime - this.PreviousFireTime > FireTime)
     {
         float projectileSpeed;
         if (isplayer)
             projectileSpeed = ProjectileSpeed;
         else
             projectileSpeed = -ProjectileSpeed;
         Projectile myProjectile = new Projectile(ProjectileTexture, ProjectileType, projectileSpeed, ProjectileDamage, postition, ship, !isplayer);
         myProjectile.Position.X += OffsetX;
         myProjectile.Position.Y += OffsetY;
         this.PreviousFireTime = gameTime.TotalGameTime;
         projectileManager.AddProjectile(myProjectile);
         fired++;
     }
 }
Exemple #5
0
 public void FireWeapon(GameTime gameTime, ProjectileManager projectileManager, Vector2 position, bool isplayer)
 {
     for (int mPoint = 0; mPoint < Hardpoints; mPoint++)
         if (this.myHardpoints[mPoint] != null)
             this.myHardpoints[mPoint].fire(gameTime, projectileManager, position + new Vector2(ShipTexture.Width / 2, ShipTexture.Height / 2), isplayer, this);
 }
 public void Update(GameTime gameTime, ProjectileManager projectilemanager)
 {
     UpdateEnemies(gameTime, projectilemanager);
 }
        private void UpdateEnemies(GameTime gameTime, ProjectileManager projectilemanager)
        {
            for (int i = Asteroids.Count - 1; i >= 0; i--)
            {
                if (Asteroids[i].Splitting == true)
                {
                    Random random = new Random();
                    SplitAsteroid(Asteroids[i].Size, Asteroids[i].Position + new Vector2(0, -25 * Asteroids[i].Size));
                    Asteroids[i].Position += new Vector2(0, 25 * Asteroids[i].Size);
                    Asteroids[i].Splitting = false;
                }

                Asteroids[i].Update(gameTime);

                if (Asteroids[i].Active == false)
                {
                    Asteroids.RemoveAt(i);
                }

            }

            for (int i = Enemies.Count - 1; i >= 0; i--)
            {
                Enemies[i].Update(gameTime, projectilemanager);

                if (Enemies[i].Active == false)
                {
                    Enemies.RemoveAt(i);
                }
            }
        }