Exemplo n.º 1
0
        //----------------------//------------------------//

        public CharacterBase(Texture2D texture)
        {
            CharacterSprite = new CharacterSprite(texture);

            // Physics variables init
            _knockbackAcceleration = 0f;
            _dyingAcceleration     = 0f;
            IgnoreGravity          = false;

            // Battle system init
            _hp                   = 1;
            _requestAttack        = false;
            _isAttacking          = false;
            _attackType           = -1;
            _attackCooldownTick   = 0f;
            AttackCooldown        = 0f;
            _shot                 = false;
            _dying                = false;
            _canReceiveAttacks    = true;
            _contactDamageEnabled = true;

            // Rand init
            _rand = new Random();

            _firstGroudLand = false;

            // SE init
            _hitSe = SoundManager.LoadSe("Hit");
        }
Exemplo n.º 2
0
 public void PerformHatDrop()
 {
     _onHatCutScene         = true;
     _hatDropping           = true;
     CharacterSprite.Effect = SpriteEffects.None;
     _hatSprite.Position    = new Vector2(Position.X + CharacterSprite.GetFrameWidth() / 2, 0);
     _hatDroppingSpeed      = BoundingRectangle.Top / HatDroppingMaxTime;
 }
Exemplo n.º 3
0
 public override void UpdateFrameList()
 {
     if (_walkingWithHat)
     {
         CharacterSprite.SetFrameList("walking_with_hat");
     }
     else if (_thumbsUp)
     {
         CharacterSprite.SetFrameList("thumbs_up");
     }
     else if (_hatReceived)
     {
         CharacterSprite.SetFrameList("hat_received");
     }
     else if (_withHat)
     {
         CharacterSprite.SetFrameList("looking_up_with_hat");
     }
     else if (_onHatCutScene)
     {
         CharacterSprite.SetFrameList("looking_up");
     }
     else if (_dying)
     {
         CharacterSprite.SetIfFrameListExists("dying");
     }
     else if (_isAttacking)
     {
         if (_attackType == ShotAttack)
         {
             if (!_isOnGround)
             {
                 CharacterSprite.SetFrameList("attack_shot_jumping");
             }
             else
             {
                 CharacterSprite.SetFrameList("attack_shot");
             }
         }
         else
         {
             CharacterSprite.SetFrameList(_attackFrameList[_attackType]);
         }
     }
     else if (!_isOnGround)
     {
         CharacterSprite.SetFrameList("jumping");
     }
     else if ((RequestingMoveLeft() || RequestingMoveRight()) && !_keysLocked && !_onHatCutScene)
     {
         CharacterSprite.SetFrameList("walking");
     }
     else
     {
         CharacterSprite.SetFrameList("stand");
     }
 }
Exemplo n.º 4
0
        private void CheckKeys(GameTime gameTime)
        {
            if (!_dying)
            {
                // Movement
                if (InputManager.Instace.KeyDown(Keys.Left) && Math.Abs(_knockbackAcceleration) < 1200f)
                {
                    CharacterSprite.SetDirection(SpriteDirection.Left);
                    _movement = -1.0f;
                }
                else if (InputManager.Instace.KeyDown(Keys.Right) && Math.Abs(_knockbackAcceleration) < 1200f)
                {
                    CharacterSprite.SetDirection(SpriteDirection.Right);
                    _movement = 1.0f;
                }

                _isJumping = InputManager.Instace.KeyDown(Keys.C);

                if (InputManager.Instace.KeyPressed(Keys.C) && _isOnGround)
                {
                    CreateJumpParticles();
                }

                // Attack
                if (!_isAttacking)
                {
                    if (!_isAttacking &&
                        ((_isOnGround && InputManager.Instace.KeyPressed(Keys.X)) || (!_isOnGround && InputManager.Instace.KeyDown(Keys.X))))
                    {
                        StartNormalAttack();
                    }

                    if (InputManager.Instace.KeyPressed(Keys.Z) && !_isAttacking && !_dying)
                    {
                        RequestAttack(ShotAttack);
                    }
                }

                // Run
                _running = InputManager.Instace.KeyDown(Keys.A);
            }
        }
Exemplo n.º 5
0
        private void CheckKeys(GameTime gameTime)
        {
            if (!_dying)
            {
                // Movement
                if (RequestingMoveLeft() && Math.Abs(_knockbackAcceleration) < 1200f)
                {
                    CharacterSprite.SetDirection(SpriteDirection.Left);
                    _movement = -1.0f;
                }
                else if (RequestingMoveRight() && Math.Abs(_knockbackAcceleration) < 1200f)
                {
                    CharacterSprite.SetDirection(SpriteDirection.Right);
                    _movement = 1.0f;
                }

                _isJumping = InputManager.Instace.Down(InputCommand.Jump);

                if (InputManager.Instace.Pressed(InputCommand.Jump) && _isOnGround)
                {
                    CreateJumpParticles();
                }

                // Attack
                if (!_isAttacking)
                {
                    if (!_isAttacking &&
                        ((_isOnGround && InputManager.Instace.Pressed(InputCommand.Attack)) ||
                         (!_isOnGround && InputManager.Instace.Down(InputCommand.Attack))))
                    {
                        StartNormalAttack();
                    }

                    if (InputManager.Instace.Pressed(InputCommand.Shot) && !_isAttacking && !_dying)
                    {
                        RequestAttack(ShotAttack);
                    }
                }
            }
        }
Exemplo n.º 6
0
        public override void UpdateAttack(GameTime gameTime)
        {
            base.UpdateAttack(gameTime);
            if (_isOnGround)
            {
                if (_attackType == AerialAttack)
                {
                    _isAttacking        = false;
                    _attackType         = -1;
                    _attackCooldownTick = 0;
                }

                if (_attackType == ShotAttack && CharacterSprite.CurrentFrameList == _attackFrameList[ShotAttackJump])
                {
                    CharacterSprite.SetFrameListOnly(_attackFrameList[ShotAttack]);
                }
            }
            else if (_attackType == ShotAttack && CharacterSprite.CurrentFrameList == _attackFrameList[ShotAttack])
            {
                CharacterSprite.SetFrameListOnly(_attackFrameList[ShotAttackJump]);
            }
        }
Exemplo n.º 7
0
 public override void UpdateFrameList()
 {
     if (_dying)
     {
         CharacterSprite.SetIfFrameListExists("dying");
     }
     else if (_isAttacking)
     {
         if (_attackType == ShotAttack)
         {
             if (!_isOnGround)
             {
                 CharacterSprite.SetFrameList("attack_shot_jumping");
             }
             else
             {
                 CharacterSprite.SetFrameList("attack_shot");
             }
         }
         else
         {
             CharacterSprite.SetFrameList(_attackFrameList[_attackType]);
         }
     }
     else if (!_isOnGround)
     {
         CharacterSprite.SetFrameList("jumping");
     }
     else if ((InputManager.Instace.KeyDown(Keys.Left) || InputManager.Instace.KeyDown(Keys.Right)) && !_keysLocked)
     {
         CharacterSprite.SetFrameList("walking");
     }
     else
     {
         CharacterSprite.SetFrameList("stand");
     }
 }
Exemplo n.º 8
0
        public override void DoAttack()
        {
            var damage = _attackType == ShotAttack ? 2 : 1;

            if (_attackType == ShotAttack)
            {
                Shot(damage);
                return;
            }

            var sceneMap = (SceneMap)SceneManager.Instance.GetCurrentScene();
            var enemies  = sceneMap.Enemies;

            foreach (var attackCollider in CharacterSprite.GetCurrentFramesList().Frames[CharacterSprite.CurrentFrame].AttackColliders)
            {
                for (var i = 0; i < enemies.Count; i++)
                {
                    if (enemies[i].CanReceiveAttacks && attackCollider.BoundingBox.Intersects(enemies[i].BoundingRectangle))
                    {
                        enemies[i].ReceiveAttackWithCollider(damage, this.BoundingRectangle, attackCollider);
                    }
                }
            }
        }
Exemplo n.º 9
0
        //----------------------//------------------------//

        public Player(Texture2D texture) : base(texture)
        {
            // Stand
            CharacterSprite.CreateFrameList("stand", 140);
            CharacterSprite.AddCollider("stand", new Rectangle(9, 2, 17, 30));
            CharacterSprite.AddFrames("stand", new List <Rectangle>()
            {
                new Rectangle(0, 0, 32, 32),
                new Rectangle(32, 0, 32, 32),
                new Rectangle(64, 0, 32, 32),
                new Rectangle(96, 0, 32, 32),
            }, new int[] { 0, 0, 0, 0 }, new int[] { 0, 0, 0, 0 });

            // Walking
            CharacterSprite.CreateFrameList("walking", 120);
            CharacterSprite.AddCollider("walking", new Rectangle(9, 2, 17, 30));
            CharacterSprite.AddFrames("walking", new List <Rectangle>()
            {
                new Rectangle(128, 0, 32, 32),
                new Rectangle(160, 0, 32, 32),
                new Rectangle(192, 0, 32, 32),
                new Rectangle(224, 0, 32, 32),
            }, new int[] { 0, 0, 0, 0 }, new int[] { 0, 0, 0, 0 });

            // Jumping
            CharacterSprite.CreateFrameList("jumping", 0);
            CharacterSprite.AddCollider("jumping", new Rectangle(9, 2, 17, 30));
            CharacterSprite.AddFrames("jumping", new List <Rectangle>()
            {
                new Rectangle(0, 32, 32, 32)
            }, new int[] { 0, 0, 0, 0 }, new int[] { 0, 0, 0, 0 });

            // Sword Attack
            CharacterSprite.CreateFrameList("attack_sword", 70);
            CharacterSprite.AddCollider("attack_sword", new Rectangle(9, 2, 17, 30));
            CharacterSprite.AddFramesToAttack("attack_sword", 1, 2);
            CharacterSprite.AddFrames("attack_sword", new List <Rectangle>()
            {
                new Rectangle(32, 32, 32, 32),
                new Rectangle(64, 32, 64, 32),
                new Rectangle(128, 32, 64, 32),
                new Rectangle(192, 32, 64, 32)
            }, new int[] { 0, 0, 0, 0 }, new int[] { 0, 0, 0, 0 });

            CharacterSprite.AddAttackCollider("attack_sword", new List <List <Rectangle> >()
            {
                new List <Rectangle>()
                {
                },
                new List <Rectangle>()
                {
                    new Rectangle(31, 14, 32, 6)
                },
                new List <Rectangle>()
                {
                    new Rectangle(31, 14, 32, 6)
                }
            }, 64);

            // Aerial Attack
            CharacterSprite.CreateFrameList("attack_aerial", 60);
            CharacterSprite.AddCollider("attack_aerial", new Rectangle(9, 2, 17, 30));
            CharacterSprite.AddFrames("attack_aerial", new List <Rectangle>()
            {
                new Rectangle(0, 64, 64, 64),
                new Rectangle(64, 64, 64, 64),
                new Rectangle(128, 64, 64, 64),
                new Rectangle(192, 64, 64, 64)
            }, new int[] { 0, 0, -32, -32 }, new int[] { -32, 0, 0, -32 });
            CharacterSprite.AddAttackCollider("attack_aerial", new List <List <Rectangle> >()
            {
                new List <Rectangle>()
                {
                    new Rectangle(25, -21, 27, 21),
                    new Rectangle(31, 0, 25, 27)
                },

                new List <Rectangle>()
                {
                    new Rectangle(32, 25, 21, 27),
                    new Rectangle(5, 31, 27, 25)
                },

                new List <Rectangle>()
                {
                    new Rectangle(-20, 32, 27, 21),
                    new Rectangle(-24, 5, 25, 27)
                },

                new List <Rectangle>()
                {
                    new Rectangle(-21, -20, 21, 27),
                    new Rectangle(0, -24, 27, 25)
                }
            }, 64);
            CharacterSprite.AddFramesToAttack("attack_aerial", 0, 1, 2, 3);

            // Shot Attack
            CharacterSprite.CreateFrameList("attack_shot", 80);
            CharacterSprite.AddCollider("attack_shot", new Rectangle(9, 2, 17, 30));
            CharacterSprite.AddFramesToAttack("attack_shot", 2);
            CharacterSprite.AddFrames("attack_shot", new List <Rectangle>()
            {
                new Rectangle(0, 128, 32, 32),
                new Rectangle(32, 128, 64, 32),
                new Rectangle(96, 128, 64, 32),
                new Rectangle(160, 128, 64, 32)
            }, new int[] { 0, 0, 0, 0 }, new int[] { 0, 0, 0, 0 });

            CharacterSprite.CreateFrameList("attack_shot_jumping", 50);
            CharacterSprite.AddCollider("attack_shot_jumping", new Rectangle(9, 2, 17, 30));
            CharacterSprite.AddFramesToAttack("attack_shot_jumping", 3);
            CharacterSprite.AddFrames("attack_shot_jumping", new List <Rectangle>()
            {
                new Rectangle(0, 160, 32, 32),
                new Rectangle(32, 160, 64, 32),
                new Rectangle(96, 160, 64, 32),
                new Rectangle(160, 160, 64, 32)
            }, new int[] { 0, 0, 0, 0 }, new int[] { 0, 0, 0, 0 });

            Position = new Vector2(32, 160);

            // Attacks setup
            _attackFrameList = new string[]
            {
                "attack_sword",
                "attack_aerial",
                "attack_shot",
                "attack_shot_jumping"
            };

            AttackCooldown  = 300f;
            _deathTick      = 0.0f;
            _requestRespawn = false;
            _active         = true;
            _keysLocked     = false;

            // SEs init
            _aerialAttackSe    = SoundManager.LoadSe("Aerial");
            _normalAttackSe    = SoundManager.LoadSe("Sword");
            _shotEmptyAttackSe = SoundManager.LoadSe("ShotPeteEmpty");
            _footstepSe        = SoundManager.LoadSe("Footstep");
        }
Exemplo n.º 10
0
        //----------------------//------------------------//

        public Player(Texture2D texture) : base(texture)
        {
            // Stand
            CharacterSprite.CreateFrameList("stand", 140);
            CharacterSprite.AddCollider("stand", new Rectangle(9, 2, 17, 30));
            CharacterSprite.AddFrames("stand", new List <Rectangle>()
            {
                new Rectangle(0, 0, 32, 32),
                new Rectangle(32, 0, 32, 32),
                new Rectangle(64, 0, 32, 32),
                new Rectangle(96, 0, 32, 32),
            }, new int[] { 0, 0, 0, 0 }, new int[] { 0, 0, 0, 0 });

            // Stand with hat
            CharacterSprite.CreateFrameList("stand_with_hat", 140);
            CharacterSprite.AddCollider("stand_with_hat", new Rectangle(9, 2, 17, 30));
            CharacterSprite.AddFrames("stand_with_hat", new List <Rectangle>()
            {
                new Rectangle(128, 192, 32, 64),
                new Rectangle(160, 192, 32, 64),
                new Rectangle(192, 192, 32, 64),
                new Rectangle(224, 192, 32, 64),
            }, new int[] { 0, 0, 0, 0 }, new int[] { -32, -32, -32, -32 });

            // Walking
            CharacterSprite.CreateFrameList("walking", 120);
            CharacterSprite.AddCollider("walking", new Rectangle(9, 2, 17, 30));
            CharacterSprite.AddFrames("walking", new List <Rectangle>()
            {
                new Rectangle(128, 0, 32, 32),
                new Rectangle(160, 0, 32, 32),
                new Rectangle(192, 0, 32, 32),
                new Rectangle(224, 0, 32, 32),
            }, new int[] { 0, 0, 0, 0 }, new int[] { 0, 0, 0, 0 });

            // Walking with hat
            CharacterSprite.CreateFrameList("walking_with_hat", 220);
            CharacterSprite.AddCollider("walking_with_hat", new Rectangle(9, 2, 17, 30));
            CharacterSprite.AddFrames("walking_with_hat", new List <Rectangle>()
            {
                new Rectangle(32, 256, 32, 64),
                new Rectangle(64, 256, 32, 64),
                new Rectangle(96, 256, 32, 64),
                new Rectangle(128, 256, 32, 64),
            }, new int[] { 0, 0, 0, 0 }, new int[] { -32, -32, -32, -32 });

            // Jumping
            CharacterSprite.CreateFrameList("jumping", 0);
            CharacterSprite.AddCollider("jumping", new Rectangle(9, 2, 17, 30));
            CharacterSprite.AddFrames("jumping", new List <Rectangle>()
            {
                new Rectangle(0, 32, 32, 32)
            }, new int[] { 0, 0, 0, 0 }, new int[] { 0, 0, 0, 0 });

            // Sword Attack
            CharacterSprite.CreateFrameList("attack_sword", 70);
            CharacterSprite.AddCollider("attack_sword", new Rectangle(9, 2, 17, 30));
            CharacterSprite.AddFramesToAttack("attack_sword", 1, 2);
            CharacterSprite.AddFrames("attack_sword", new List <Rectangle>()
            {
                new Rectangle(32, 32, 32, 32),
                new Rectangle(64, 32, 64, 32),
                new Rectangle(128, 32, 64, 32),
                new Rectangle(192, 32, 64, 32)
            }, new int[] { 0, 0, 0, 0 }, new int[] { 0, 0, 0, 0 });

            CharacterSprite.AddAttackCollider("attack_sword", new List <List <Rectangle> >()
            {
                new List <Rectangle>()
                {
                },
                new List <Rectangle>()
                {
                    new Rectangle(31, 14, 32, 6)
                },
                new List <Rectangle>()
                {
                    new Rectangle(31, 14, 32, 6)
                }
            }, 64);

            // Aerial Attack
            CharacterSprite.CreateFrameList("attack_aerial", 50);
            CharacterSprite.AddCollider("attack_aerial", new Rectangle(9, 2, 17, 30));
            CharacterSprite.AddFrames("attack_aerial", new List <Rectangle>()
            {
                new Rectangle(0, 64, 64, 64),
                new Rectangle(64, 64, 64, 64),
                new Rectangle(128, 64, 64, 64),
                new Rectangle(192, 64, 64, 64)
            }, new int[] { 0, 0, -32, -32 }, new int[] { -32, 0, 0, -32 });
            CharacterSprite.AddAttackCollider("attack_aerial", new List <List <Rectangle> >()
            {
                new List <Rectangle>()
                {
                    new Rectangle(25, -21, 27, 21),
                    new Rectangle(31, 0, 25, 27)
                },

                new List <Rectangle>()
                {
                    new Rectangle(32, 25, 21, 27),
                    new Rectangle(5, 31, 27, 25)
                },

                new List <Rectangle>()
                {
                    new Rectangle(-20, 32, 27, 21),
                    new Rectangle(-24, 5, 25, 27)
                },

                new List <Rectangle>()
                {
                    new Rectangle(-21, -20, 21, 27),
                    new Rectangle(0, -24, 27, 25)
                }
            }, 64);
            CharacterSprite.AddFramesToAttack("attack_aerial", 0, 1, 2, 3);

            // Shot Attack
            CharacterSprite.CreateFrameList("attack_shot", 80);
            CharacterSprite.AddCollider("attack_shot", new Rectangle(9, 2, 17, 30));
            CharacterSprite.AddFramesToAttack("attack_shot", 2);
            CharacterSprite.AddFrames("attack_shot", new List <Rectangle>()
            {
                new Rectangle(0, 128, 32, 32),
                new Rectangle(32, 128, 64, 32),
                new Rectangle(96, 128, 64, 32),
                new Rectangle(160, 128, 64, 32)
            }, new int[] { 0, 0, 0, 0 }, new int[] { 0, 0, 0, 0 });

            // Shot Attack Jumping
            CharacterSprite.CreateFrameList("attack_shot_jumping", 50);
            CharacterSprite.AddCollider("attack_shot_jumping", new Rectangle(9, 2, 17, 30));
            CharacterSprite.AddFramesToAttack("attack_shot_jumping", 3);
            CharacterSprite.AddFrames("attack_shot_jumping", new List <Rectangle>()
            {
                new Rectangle(0, 160, 32, 32),
                new Rectangle(32, 160, 64, 32),
                new Rectangle(96, 160, 64, 32),
                new Rectangle(160, 160, 64, 32)
            }, new int[] { 0, 0, 0, 0 }, new int[] { 0, 0, 0, 0 });

            // Hat Received
            CharacterSprite.CreateFrameList("hat_received", 1000, false);
            CharacterSprite.AddCollider("hat_received", new Rectangle(9, 2, 17, 30));
            CharacterSprite.AddFrames("hat_received", new List <Rectangle>()
            {
                new Rectangle(0, 192, 32, 64),
                new Rectangle(32, 192, 32, 64),
            }, new int[] { 0, 0, 0, 0 }, new int[] { -32, -32, -32, -32 });

            // Thumbs up
            CharacterSprite.CreateFrameList("thumbs_up", 140, false);
            CharacterSprite.AddCollider("thumbs_up", new Rectangle(9, 2, 17, 30));
            CharacterSprite.AddFrames("thumbs_up", new List <Rectangle>()
            {
                new Rectangle(64, 192, 32, 64),
                new Rectangle(96, 192, 32, 64),
            }, new int[] { 0, 0, 0, 0 }, new int[] { -32, -32, -32, -32 });

            // Looking up
            CharacterSprite.CreateFrameList("looking_up", 140);
            CharacterSprite.AddCollider("looking_up", new Rectangle(9, 2, 17, 30));
            CharacterSprite.AddFrames("looking_up", new List <Rectangle>()
            {
                new Rectangle(0, 256, 32, 64),
            }, new int[] { 0, 0, 0, 0 }, new int[] { -32, -32, -32, -32 });

            // Looking up with hat
            CharacterSprite.CreateFrameList("looking_up_with_hat", 140);
            CharacterSprite.AddCollider("looking_up_with_hat", new Rectangle(9, 2, 17, 30));
            CharacterSprite.AddFrames("looking_up_with_hat", new List <Rectangle>()
            {
                new Rectangle(0, 192, 32, 64),
            }, new int[] { 0, 0, 0, 0 }, new int[] { -32, -32, -32, -32 });

            Position = new Vector2(32, 160);

            // Attacks setup
            _attackFrameList = new string[]
            {
                "attack_sword",
                "attack_aerial",
                "attack_shot",
                "attack_shot_jumping"
            };

            AttackCooldown  = 200f;
            _deathTick      = 0.0f;
            _requestRespawn = false;
            _active         = true;
            _keysLocked     = false;

            // Hat drop
            var hatTexture = ImageManager.loadMisc("PeteHat");

            _hatSprite = new AnimatedSprite(hatTexture, new Rectangle[] {
                new Rectangle(0, 0, 96, 64),
                new Rectangle(96, 0, 96, 64),
                new Rectangle(192, 0, 96, 64),
                new Rectangle(288, 0, 96, 64),
                new Rectangle(384, 0, 96, 64),
                new Rectangle(0, 64, 96, 64),
                new Rectangle(96, 64, 96, 64),
                new Rectangle(192, 64, 96, 64),
                new Rectangle(288, 64, 96, 64),
                new Rectangle(384, 64, 96, 64),
            }, 100, Vector2.Zero);
            _hatSprite.Origin = new Vector2(50, 37);

            // Flash texture
            _flashTexture = new Texture2D(SceneManager.Instance.GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
            _flashTexture.SetData(new Color[] { Color.White });

            // SEs init
            _aerialAttackSe    = SoundManager.LoadSe("Aerial");
            _normalAttackSe    = SoundManager.LoadSe("Sword");
            _shotEmptyAttackSe = SoundManager.LoadSe("ShotPeteEmpty");
            _footstepSe        = SoundManager.LoadSe("Footstep");
            _hatSe             = SoundManager.LoadSe("Hat");
        }