Exemplo n.º 1
0
 public override void Blocked_Bottom(GameInput input)
 {
     base.Blocked_Top(input);
     if (input.Left == input.Right)
     {
         animation = 0;
     }
     landState = LandState.OnGround;
     if (arm == ArmDirection.Lower)
     {
         arm = ArmDirection.Forward;
     }
 }
Exemplo n.º 2
0
 public Player(GameScene game, int row, int col, Direction direction)
     : base(game, RECTANGLE, new Vector(col * Settings.BLOCK_WDITH, row * Settings.BLOCK_WDITH), Vector.Zero, INIT_HEALTH)
 {
     this.direction    = direction;
     arm               = ArmDirection.Forward;
     landState         = LandState.InAir;
     weapon            = Weapon.Pistol;
     ammo              = 0;
     jumpCount         = -1;
     fireCount         = -1;
     animation         = 0;
     enemyDamageCount  = 0;
     freeze            = false;
     armAnimation      = 0;
     visible           = true;
     drawHealth        = health;
     focus             = Vector.Zero;
     ammoHudColorCount = 0;
     ammoNumColorCount = 0;
 }
Exemplo n.º 3
0
 public Player(GameScene game, int row, int col, Direction direction)
     : base(game, RECTANGLE, new Vector(col * Settings.BLOCK_WDITH, row * Settings.BLOCK_WDITH), Vector.Zero, INIT_HEALTH)
 {
     this.direction = direction;
     arm = ArmDirection.Forward;
     landState = LandState.InAir;
     weapon = Weapon.Pistol;
     ammo = 0;
     jumpCount = -1;
     fireCount = -1;
     animation = 0;
     enemyDamageCount = 0;
     freeze = false;
     armAnimation = 0;
     visible = true;
     drawHealth = health;
     focus = Vector.Zero;
     ammoHudColorCount = 0;
     ammoNumColorCount = 0;
 }
Exemplo n.º 4
0
        public override void Tick(GameInput input)
        {
            if (ammoHudColorCount > 0)
            {
                ammoHudColorCount--;
            }
            if (ammoNumColorCount > 0)
            {
                ammoNumColorCount--;
            }

            if (!freeze && visible)
            {
                #region 左右の動き

                if (input.Left == input.Right)
                {
                    if (landState == LandState.InAir)
                    {
                        if (Math.Abs(velocity.X) > ACCELERATION_IN_AIR / 8)
                        {
                            velocity.X -= Math.Sign(velocity.X) * ACCELERATION_IN_AIR / 8;
                        }
                        else
                        {
                            velocity.X = 0;
                        }
                    }
                    else if (landState == LandState.OnGround)
                    {
                        if (Math.Abs(velocity.X) > ACCELERATION_ON_GROUND)
                        {
                            velocity.X -= Math.Sign(velocity.X) * ACCELERATION_ON_GROUND;
                        }
                        else
                        {
                            velocity.X = 0;
                        }
                    }
                }
                else if (input.Left && !input.Right)
                {
                    direction = Direction.Left;
                    if (landState == LandState.InAir)
                    {
                        if (velocity.X > -MAX_MOVING_SPEED)
                        {
                            velocity.X -= ACCELERATION_IN_AIR;
                        }
                    }
                    else if (landState == LandState.OnGround)
                    {
                        if (velocity.X > -MAX_MOVING_SPEED)
                        {
                            velocity.X -= ACCELERATION_ON_GROUND;
                        }
                        animation = (animation + 1) % NUM_ANIMATIONS;
                    }
                }
                else if (input.Right && !input.Left)
                {
                    direction = Direction.Right;
                    if (landState == LandState.InAir)
                    {
                        if (velocity.X < MAX_MOVING_SPEED)
                        {
                            velocity.X += ACCELERATION_IN_AIR;
                        }
                    }
                    else if (landState == LandState.OnGround)
                    {
                        if (velocity.X < MAX_MOVING_SPEED)
                        {
                            velocity.X += ACCELERATION_ON_GROUND;
                        }
                        animation = (animation + 1) % NUM_ANIMATIONS;
                    }
                }

                if (Math.Abs(velocity.X) > MAX_MOVING_SPEED)
                {
                    if (Math.Abs(velocity.X) - 1 < MAX_MOVING_SPEED)
                    {
                        velocity.X = Math.Sign(velocity.X) * MAX_MOVING_SPEED;
                    }
                    else
                    {
                        velocity.X -= Math.Sign(velocity.X);
                    }
                }

                MoveBy_Horizontal(input, velocity.X);

                #endregion

                #region   の動き

                velocity.Y += ACCELERATION_FALLING;
                if (velocity.Y > MAX_FALLING_SPEED)
                {
                    velocity.Y = MAX_FALLING_SPEED;
                }
                if (landState == LandState.OnGround)
                {
                    if (input.Jump)
                    {
                        if (jumpCount != -1)
                        {
                            landState = LandState.InAir;
                            jumpCount = INIT_JUMP_COUNT;
                            animation = (animation + (NUM_ANIMATIONS / 4)) % NUM_ANIMATIONS;
                        }
                    }
                    else
                    {
                        jumpCount = 0;
                    }
                }
                if (landState == LandState.InAir)
                {
                    if (jumpCount > 0)
                    {
                        if (input.Jump)
                        {
                            velocity.Y = -JUMP_SPEED;
                            jumpCount--;
                        }
                        else
                        {
                            jumpCount = -1;
                        }
                    }
                    else
                    {
                        if (velocity.Y < 0)
                        {
                            jumpCount = -1;
                        }
                        else if (!input.Jump)
                        {
                            jumpCount = 0;
                        }
                    }
                }
                landState = LandState.InAir;
                MoveBy_Vertical(input, velocity.Y);

                #endregion

                #region 腕

                if (input.Up == input.Down)
                {
                    arm = ArmDirection.Forward;
                }
                else if (input.Up)
                {
                    arm = ArmDirection.Upper;
                }
                else if (input.Down && landState == LandState.InAir)
                {
                    arm = ArmDirection.Lower;
                }

                #endregion

                #region 弾丸発射

                if (input.Attack && fireCount <= 0)
                {
                    if (weapon == Weapon.Pistol)
                    {
                        fireCount = INIT_FIRE_COUNT;
                    }
                    else if (weapon == Weapon.Machinegun)
                    {
                        fireCount = INIT_FIRE_COUNT / 2;
                    }
                    else if (weapon == Weapon.Rocket)
                    {
                        fireCount = INIT_FIRE_COUNT * 2;
                    }
                    else if (weapon == Weapon.Shotgun)
                    {
                        fireCount = INIT_FIRE_COUNT * 4;
                    }
                    else if (weapon == Weapon.Flamethrower)
                    {
                        if (fireCount == -1)
                        {
                            game.PlaySound(GameSound.Flame);
                        }
                        fireCount = 1;
                    }

                    armAnimation = 16;
                    FireWeapon(weapon);

                    /*
                     * if (direction == Direction.Left)
                     * {
                     *  game.AddPlayerBullet(new PlayerBullet(game, position + new Vector(0, 32), 180));
                     *  // game.AddParticle(new PlayerBulletExplosion(game, position + new Vector(0, 32), velocity * 0.5));
                     * }
                     * else
                     * {
                     *  game.AddPlayerBullet(new PlayerBullet(game, position + new Vector(32, 32), 0));
                     *  // game.AddParticle(new PlayerBulletExplosion(game, position + new Vector(32, 32), velocity * 0.5));
                     * }
                     */
                }
                if (fireCount > -1)
                {
                    fireCount--;
                }
                if (armAnimation > 0)
                {
                    armAnimation--;
                }

                #endregion

                #region アイテム取得

                foreach (Thing item in game.Items)
                {
                    if (Overlappes(this, item))
                    {
                        GetItem((Item)item);
                    }
                }

                #endregion
            }

            #region カメラ位置の補正

            if (direction == Direction.Left)
            {
                focus.X -= 2;
            }
            else
            {
                focus.X += 2;
            }
            if (Math.Abs(focus.X) > Settings.SCREEN_WIDTH / 8)
            {
                focus.X = Math.Sign(focus.X) * Settings.SCREEN_WIDTH / 8;
            }
            if (Center.X + focus.X < Settings.SCREEN_WIDTH / 2)
            {
                focus.X = Settings.SCREEN_WIDTH / 2 - Center.X;
            }
            else if (Center.X + focus.X > game.Map.Width - Settings.SCREEN_WIDTH / 2)
            {
                focus.X = game.Map.Width - Settings.SCREEN_WIDTH / 2 - Center.X;
            }

            #endregion

            if (enemyDamageCount > 0)
            {
                enemyDamageCount--;
            }

            /*
             * if (drawHealth < health)
             * {
             *  drawHealth++;
             * }
             * else if (drawHealth > health)
             * {
             *  drawHealth--;
             * }
             */
            drawHealth = health + (drawHealth - health) * 3 / 4;

            if (game.DebugMode)
            {
                if (health < 100)
                {
                    health++;
                }
            }

            base.Tick(input);
        }
Exemplo n.º 5
0
        public override void Tick(GameInput input)
        {
            if (ammoHudColorCount > 0)
            {
                ammoHudColorCount--;
            }
            if (ammoNumColorCount > 0)
            {
                ammoNumColorCount--;
            }

            if (!freeze && visible)
            {

                #region ���E�̓���

                if (input.Left == input.Right)
                {
                    if (landState == LandState.InAir)
                    {
                        if (Math.Abs(velocity.X) > ACCELERATION_IN_AIR / 8)
                        {
                            velocity.X -= Math.Sign(velocity.X) * ACCELERATION_IN_AIR / 8;
                        }
                        else
                        {
                            velocity.X = 0;
                        }
                    }
                    else if (landState == LandState.OnGround)
                    {
                        if (Math.Abs(velocity.X) > ACCELERATION_ON_GROUND)
                        {
                            velocity.X -= Math.Sign(velocity.X) * ACCELERATION_ON_GROUND;
                        }
                        else
                        {
                            velocity.X = 0;
                        }
                    }
                }
                else if (input.Left && !input.Right)
                {
                    direction = Direction.Left;
                    if (landState == LandState.InAir)
                    {
                        if (velocity.X > -MAX_MOVING_SPEED)
                        {
                            velocity.X -= ACCELERATION_IN_AIR;
                        }
                    }
                    else if (landState == LandState.OnGround)
                    {
                        if (velocity.X > -MAX_MOVING_SPEED)
                        {
                            velocity.X -= ACCELERATION_ON_GROUND;
                        }
                        animation = (animation + 1) % NUM_ANIMATIONS;
                    }
                }
                else if (input.Right && !input.Left)
                {
                    direction = Direction.Right;
                    if (landState == LandState.InAir)
                    {
                        if (velocity.X < MAX_MOVING_SPEED)
                        {
                            velocity.X += ACCELERATION_IN_AIR;
                        }
                    }
                    else if (landState == LandState.OnGround)
                    {
                        if (velocity.X < MAX_MOVING_SPEED)
                        {
                            velocity.X += ACCELERATION_ON_GROUND;
                        }
                        animation = (animation + 1) % NUM_ANIMATIONS;
                    }
                }

                if (Math.Abs(velocity.X) > MAX_MOVING_SPEED)
                {
                    if (Math.Abs(velocity.X) - 1 < MAX_MOVING_SPEED)
                    {
                        velocity.X = Math.Sign(velocity.X) * MAX_MOVING_SPEED;
                    }
                    else
                    {
                        velocity.X -= Math.Sign(velocity.X);
                    }
                }

                MoveBy_Horizontal(input, velocity.X);

                #endregion

                #region �㉺�̓���

                velocity.Y += ACCELERATION_FALLING;
                if (velocity.Y > MAX_FALLING_SPEED)
                {
                    velocity.Y = MAX_FALLING_SPEED;
                }
                if (landState == LandState.OnGround)
                {
                    if (input.Jump)
                    {
                        if (jumpCount != -1)
                        {
                            landState = LandState.InAir;
                            jumpCount = INIT_JUMP_COUNT;
                            animation = (animation + (NUM_ANIMATIONS / 4)) % NUM_ANIMATIONS;
                        }
                    }
                    else
                    {
                        jumpCount = 0;
                    }
                }
                if (landState == LandState.InAir)
                {
                    if (jumpCount > 0)
                    {
                        if (input.Jump)
                        {
                            velocity.Y = -JUMP_SPEED;
                            jumpCount--;
                        }
                        else
                        {
                            jumpCount = -1;
                        }
                    }
                    else
                    {
                        if (velocity.Y < 0)
                        {
                            jumpCount = -1;
                        }
                        else if (!input.Jump)
                        {
                            jumpCount = 0;
                        }
                    }
                }
                landState = LandState.InAir;
                MoveBy_Vertical(input, velocity.Y);

                #endregion

                #region �r

                if (input.Up == input.Down)
                {
                    arm = ArmDirection.Forward;
                }
                else if (input.Up)
                {
                    arm = ArmDirection.Upper;
                }
                else if (input.Down && landState == LandState.InAir)
                {
                    arm = ArmDirection.Lower;
                }

                #endregion

                #region �e�۔���

                if (input.Attack && fireCount <= 0)
                {
                    if (weapon == Weapon.Pistol)
                    {
                        fireCount = INIT_FIRE_COUNT;
                    }
                    else if (weapon == Weapon.Machinegun)
                    {
                        fireCount = INIT_FIRE_COUNT / 2;
                    }
                    else if (weapon == Weapon.Rocket)
                    {
                        fireCount = INIT_FIRE_COUNT * 2;
                    }
                    else if (weapon == Weapon.Shotgun)
                    {
                        fireCount = INIT_FIRE_COUNT * 4;
                    }
                    else if (weapon == Weapon.Flamethrower)
                    {
                        if (fireCount == -1)
                        {
                            game.PlaySound(GameSound.Flame);
                        }
                        fireCount = 1;
                    }

                    armAnimation = 16;
                    FireWeapon(weapon);

                    /*
                    if (direction == Direction.Left)
                    {
                        game.AddPlayerBullet(new PlayerBullet(game, position + new Vector(0, 32), 180));
                        // game.AddParticle(new PlayerBulletExplosion(game, position + new Vector(0, 32), velocity * 0.5));
                    }
                    else
                    {
                        game.AddPlayerBullet(new PlayerBullet(game, position + new Vector(32, 32), 0));
                        // game.AddParticle(new PlayerBulletExplosion(game, position + new Vector(32, 32), velocity * 0.5));
                    }
                    */
                }
                if (fireCount > -1)
                {
                    fireCount--;
                }
                if (armAnimation > 0)
                {
                    armAnimation--;
                }

                #endregion

                #region �A�C�e���擾

                foreach (Thing item in game.Items)
                {
                    if (Overlappes(this, item))
                    {
                        GetItem((Item)item);
                    }
                }

                #endregion

            }

            #region �J�����ʒu�̕␳

            if (direction == Direction.Left)
            {
                focus.X -= 2;
            }
            else
            {
                focus.X += 2;
            }
            if (Math.Abs(focus.X) > Settings.SCREEN_WIDTH / 8) focus.X = Math.Sign(focus.X) * Settings.SCREEN_WIDTH / 8;
            if (Center.X + focus.X < Settings.SCREEN_WIDTH / 2)
            {
                focus.X = Settings.SCREEN_WIDTH / 2 - Center.X;
            }
            else if (Center.X + focus.X > game.Map.Width - Settings.SCREEN_WIDTH / 2)
            {
                focus.X = game.Map.Width - Settings.SCREEN_WIDTH / 2 - Center.X;
            }

            #endregion

            if (enemyDamageCount > 0)
            {
                enemyDamageCount--;
            }

            /*
            if (drawHealth < health)
            {
                drawHealth++;
            }
            else if (drawHealth > health)
            {
                drawHealth--;
            }
            */
            drawHealth = health + (drawHealth - health) * 3 / 4;

            if (game.DebugMode)
            {
                if (health < 100)
                {
                    health++;
                }
            }

            base.Tick(input);
        }
Exemplo n.º 6
0
 public override void Blocked_Bottom(GameInput input)
 {
     base.Blocked_Top(input);
     if (input.Left == input.Right)
     {
         animation = 0;
     }
     landState = LandState.OnGround;
     if (arm == ArmDirection.Lower)
     {
         arm = ArmDirection.Forward;
     }
 }