Exemple #1
0
        public void Update(GameCommand command)
        {
            if (isDead || freeze)
            {
                return;
            }

            if (command.Left != command.Right)
            {
                if (command.Left)
                {
                    vx -= SPEED_UP;
                    if (vx < -MAX_SPEED)
                    {
                        vx = -MAX_SPEED;
                    }
                }
                if (command.Right)
                {
                    vx += SPEED_UP;
                    if (vx > MAX_SPEED)
                    {
                        vx = MAX_SPEED;
                    }
                }
            }
            else
            {
                if (Math.Abs(vx) < SPEED_DOWN)
                {
                    vx = 0;
                }
                else
                {
                    vx -= Math.Sign(vx) * SPEED_DOWN;
                }
            }
            if (command.Up != command.Down)
            {
                if (command.Up)
                {
                    vy -= SPEED_UP;
                    if (vy < -MAX_SPEED)
                    {
                        vy = -MAX_SPEED;
                    }
                }
                if (command.Down)
                {
                    vy += SPEED_UP;
                    if (vy > MAX_SPEED)
                    {
                        vy = MAX_SPEED;
                    }
                }
            }
            else
            {
                if (Math.Abs(vy) < SPEED_DOWN)
                {
                    vy = 0;
                }
                else
                {
                    vy -= Math.Sign(vy) * SPEED_DOWN;
                }
            }

            X += vx;
            Y += vy;

            if (X < 16)
            {
                X = 16;
            }
            else if (X > Game.FieldWidth - 16)
            {
                X = Game.FieldWidth - 16;
            }
            if (Y < Game.FieldHeight / 4)
            {
                Y = Game.FieldHeight / 4;
            }
            else if (Y > Game.FieldHeight - 16)
            {
                Y = Game.FieldHeight - 16;
            }

            if (fireCount > 0)
            {
                fireCount--;
            }
            if (command.Button1)
            {
                if (fireCount == 0)
                {
                    if (Game.PlayerBulletList.Count < 8)
                    {
                        Bullet bullet = new PlayerBullet(Game, X, Y - 32, 16, 90);
                        Game.AddPlayerBullet(bullet);
                        Game.PlaySound(Sound.PlayerFire);
                        fireCount = 2;
                    }
                }
            }
        }