Ejemplo n.º 1
0
 public override void Update(Game gameInstance, double deltaT)
 {
     if (gameInstance.keyPressed.Contains(Keys.Right))
     {
         var oldPosition = Position;
         Position += new Vecteur2d(Speed);
         if (Position.X > gameInstance.gameSize.Width - Image.Width)
         {
             Position = oldPosition;
         }
     }
     else if (gameInstance.keyPressed.Contains(Keys.Left))
     {
         var oldPosition = Position;
         Position -= new Vecteur2d(Speed);
         if (Position.X < 0)
         {
             Position = oldPosition;
         }
     }
     if (gameInstance.keyPressed.Contains(Keys.Space))
     {
         Shoot(gameInstance);
     }
 }
Ejemplo n.º 2
0
 protected override void OnCollision(Missile m, Vecteur2d collisionPoint)
 {
     if (m.IsAlive())
     {
         Lives--;
         m.Lives = 0;
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Add a line of ennemy in the enemy block
        /// Create a beautifull offset for a cool display
        /// </summary>
        /// <param name="nbShips">Number of ships to add</param>
        /// <param name="nbLives">Ship's lives</param>
        /// <param name="shipImage">Ship's image</param>
        public void AddLine(int nbShips, int nbLives, Bitmap shipImage)
        {
            float offsetY = shipImage.Height + (size.Height * 40);
            float offsetX = (baseWidth - nbShips * shipImage.Width) / (nbShips + 1);

            for (int i = 0; i < nbShips; i++)
            {
                var vector = new Vecteur2d((i * shipImage.Width) + offsetX * (i + 1), offsetY);
                EnemyShips.Add(new SpaceShip(vector, nbLives, shipImage, Side.Enemy));
            }
            size.Height++;
        }
Ejemplo n.º 4
0
 public override void Update(Game gameInstance, double deltaT)
 {
     Position = (Side == Side.Ally)? Position -= new Vecteur2d(0, speed) : Position += new Vecteur2d(0, speed);
     Lives    = (Position.Y <0 || Position.Y> gameInstance.gameSize.Height) ? 0 : Lives;
     foreach (var stupidObject in gameInstance.gameObjects)
     {
         if (stupidObject.Equals(this))
         {
             continue;
         }
         stupidObject.Collision(this);
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Update the size of the enemy block for a correct mouvement
        /// when they are a column of ship destroyed
        /// </summary>
        public void UpdateSize()
        {
            double minLenX   = Double.MaxValue;
            double maxLenX   = Double.MinValue;
            double image_len = 0;

            foreach (var ship in EnemyShips)
            {
                if (ship.Position.X > maxLenX)
                {
                    maxLenX   = ship.Position.X;
                    image_len = ship.Image.Width;
                }
                if (ship.Position.X < minLenX)
                {
                    minLenX = ship.Position.X;
                }
            }
            Position   = new Vecteur2d(minLenX, Position.Y);
            size.Width = (int)maxLenX + (int)image_len - (int)Position.X;
        }
Ejemplo n.º 6
0
        public override void Update(Game gameInstance, double deltaT)
        {
            // If the enemy block need to go down & reverse vectorX
            if (Position.X + size.Width + vectorX.X > gameInstance.gameSize.Width || Position.X + vectorX.X < 0)
            {
                Position += vectorY;
                vectorX  -= vectorX * 2.03;
                randomShootProbability += .015;
                EnemyShips.ToList().ForEach(enemy => enemy.Position += vectorY);
            }
            Position += vectorX;
            EnemyShips.ToList().ForEach(enemy => enemy.Position += vectorX);

            // Fire in the hole
            foreach (var ship in EnemyShips)
            {
                if (rng.NextDouble() <= randomShootProbability * deltaT)
                {
                    ship.Shoot(gameInstance);
                }
                ship.Lives = (ship.Position.Y + ship.Image.Height > gameInstance.gameSize.Height) ? 0 : ship.Lives;
            }
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="position">Base position</param>
 /// <param name="lives">Number of lives</param>
 /// <param name="image">Image to draw</param>
 /// <param name="side">Side</param>
 public SpaceShip(Vecteur2d position, int lives, Bitmap image, Side side) : base(position, lives, image, side)
 {
     Speed   = 1;
     Missile = null;
 }
Ejemplo n.º 8
0
 protected override void OnCollision(Missile m, Vecteur2d collisionPoint)
 {
     Lives   = 0;
     m.Lives = 0;
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Another constructor calling just the abstract constructor
 /// </summary>
 /// <param name="position">Missile base position</param>
 /// <param name="lives">Number of lives</param>
 /// <param name="image">Missile's image</param>
 /// <param name="side">Side of the missile</param>
 public Missile(Vecteur2d position, int lives, Bitmap image, Side side) : base(position, lives, image, side)
 {
 }
Ejemplo n.º 10
0
 protected override void OnCollision(Missile m, Vecteur2d collisionPoint)
 {
     Image.SetPixel((int)collisionPoint.X, (int)collisionPoint.Y, Color.FromArgb(0, 255, 255, 255));
     m.Lives--;
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Public constructor calling base constructor
 /// </summary>
 /// <param name="position">The bunker's position</param>
 public Bunker(Vecteur2d position) : base(position, 1, Properties.Resources.bunker, Side.Neutral)
 {
 }
Ejemplo n.º 12
0
 /// <summary>
 /// The main constructor
 /// </summary>
 /// <param name="position">Starting position of the block</param>
 /// <param name="baseWidth">The original width</param>
 /// <param name="side">The side of the block</param>
 public EnemyBlock(Vecteur2d position, int baseWidth, Side side) : base(position, side)
 {
     EnemyShips     = new HashSet <SpaceShip>();
     this.baseWidth = baseWidth;
     this.randomShootProbability = .05;
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Wow another empty constructor
 /// </summary>
 /// <param name="position">Initial position</param>
 /// <param name="lives">Number of lives</param>
 /// <param name="image">The image</param>
 /// <param name="side">Side</param>
 public PlayerSpaceShip(Vecteur2d position, int lives, Bitmap image, Side side) : base(position, lives, image, side)
 {
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Constructor of the object
 /// </summary>
 /// <param name="position">The position</param>
 /// <param name="side">The side</param>
 public GameObject(Vecteur2d position, Side side)
 {
     Side     = side;
     Position = position;
 }