Example #1
0
 public Bullet Shot()
 {
     if (this.PlayerWeapon.WeaponBullet.Texture != null && isFireKeyPress)
     {
         var bulletPosition = new Vector2(this.PositionX + this.Width / 2 - InitialData.UnitData.BulletWidth / 2,
                                         this.PositionY - InitialData.UnitData.BulletHeight / 2);
         var bullet = new Bullet(this.PlayerWeapon.WeaponBullet.Texture, bulletPosition);
         return bullet;
     }
     // To do: a better return value when the isTimeForFite is equal to false
     return null;
 }
Example #2
0
        private void handleBulletCollision(Bullet i_Bullet)
        {
            int amountToBiteOff = (int)(i_Bullet.Height * 0.55);
            int row, col, direction;

            direction = i_Bullet.Velocity.Y > 0 ? 1 : -1;

            foreach (Point point in CollidingPoints)
            {
                col = point.Y;
                for (int i = 0; i < amountToBiteOff; ++i)
                {
                    row = point.X + (direction * i);
                    if (row >= 0 && row < this.Height)
                    {
                        this.SpritePixelMatrix.ChangePixelAlpha(row, col, 0);
                    }
                }
            }

            m_SoundService.PlaySoundEffect(GameSounds.BarrierHit);
        }
Example #3
0
        void Fire()
        {
            if (_creationList != null)
            {
                Bullet bullet = new Bullet();
                bullet.ownerID = ID;
                bullet.color = this.color;
                bullet.Place(this.Position + new Vector2(0.0f, -14.0f));
                bullet.Velocity = new Vector2(0.0f, -20.0f);
                _creationList.Add(bullet);

            }
        }
Example #4
0
        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            // TODO: Add your update code here
            //position += velocity;

            world =Matrix.CreateScale(radius)*Matrix.CreateTranslation(position) ;

            //            if (DateTime.Now.Subtract(timeOfBirth).TotalMilliseconds > 2000)
            //            {
            //                alive = false;
            //            }
            int i=random.Next()%40;
            if (i == 0 && bullets.Count<40)
            {
                Bullet b = new Bullet(theGame);
                b.Initialize(bulletModel, Vector3.Backward, position);
                bullets.Add(b);
            }

            base.Update(gameTime);
        }
Example #5
0
        public void Update(GameTime gt)
        {
            KeyboardState ks = Keyboard.GetState();

            if(ks.IsKeyDown(Keys.Up)){
                yaw+=maxYawSpeed;
            }
            if(ks.IsKeyDown(Keys.Down)){
                yaw-=maxYawSpeed;
            }

            if (ks.IsKeyDown(Keys.Right))
            {
                position.X += maxHorzSpeed;
            }
            if (ks.IsKeyDown(Keys.Left))
            {
                position.X -= maxHorzSpeed;

            }

            Matrix rot=Matrix.CreateRotationY(yaw);
            direction = Vector3.Transform(Vector3.Forward, rot);

            //only spawn bullet if its been 100ms since last bullet was made
            if (ks.IsKeyDown(Keys.Space)
                &&
                DateTime.Now.Subtract(timeOfLastBullet).TotalMilliseconds
                > 100)
            {
                Bullet b = new Bullet(game);
                b.Initialize(bulletModel,direction,position);
                bullets.Add(b);
                timeOfLastBullet = DateTime.Now;
            }
            world = Matrix.CreateRotationY(yaw) * Matrix.CreateTranslation(position) ;

            foreach (Bullet b in bullets)
            {
                  b.Update(gt);
            }
            bullets.RemoveAll(Bullet.IsDead);

            long millsSinceLastDeath = (long)DateTime.Now.Subtract(timeOfLastDeath).TotalMilliseconds;
            if (millsSinceLastDeath < 3000)
            {//flicker for 3 seconds after death
                spawning = true;
                long tenthsSinceLastDeath = millsSinceLastDeath / 100;
                visible=true;
                if (tenthsSinceLastDeath % 2 == 0)
                {
                    visible = false;
                }
            }
            else
            {
                spawning = false;
                visible = true;

            }
        }
Example #6
0
        public void Spawn(GameMessage message)
        {
            int index = message.index;
            int p = BitConverter.ToInt32(message.Message, 16);
            if (entities.Keys.Contains<int>(index))
            {
                if (entities[index].typeID == -1)
                {
                    entities.Remove(index);
                }
                else
                {
                    return;
                }
            }

            if (idCounter <= index)
                idCounter = index + 1;

            switch (p)
            {
                case 0:
                    var ship = new PlayerShip();
                    ship.HandleSpawnMessage(message);
                    AddEntity(index, ship);
                    break;
                case 1:
                    var enemyShip = new EnemyShip();
                    enemyShip.HandleSpawnMessage(message);
                    AddEntity(index, enemyShip);
                    break;
                case 2:
                    var bullet = new Bullet();
                    bullet.HandleSpawnMessage(message);
                    AddEntity(index, bullet);
                    break;
                case 3:
                    var chunk = new BuildingChunk();
                    chunk.HandleSpawnMessage(message);
                    AddEntity(index, chunk);
                    break;
            }
        }
Example #7
0
 public static bool IsDead(Bullet b)
 {
     return !b.alive;
 }
Example #8
0
 void Fire()
 {
     if (_createList != null)
     {
         var bullet = new Bullet();
         bullet.ownerID = ID;
         bullet.isDown = true;
         bullet.color = this.color;
         bullet.Place(_position + new Vector2(0.0f, 18.0f));
         bullet.Velocity = new Vector2(0.0f, 20.0f);
         _createList.Add(bullet);
     }
 }