Exemplo n.º 1
0
        public EnemyTest(AbstractScene scene, Vector2 position, Direction direction) : base(scene, position, direction)
        {
            AddCollisionAgainst("Spikes");
            CurrentFaceDirection = Direction.EAST;
            AnimationStateMachine animations = new AnimationStateMachine();

            animations.Offset = offset;
            AddComponent(animations);
            SpriteSheetAnimation runLeft = new SpriteSheetAnimation(this, Assets.GetTexture("EnemyRun"), 32, 32, 40);

            animations.RegisterAnimation("RunLeft", runLeft, () => Velocity.X != 0 && CurrentFaceDirection == Direction.WEST);

            SpriteSheetAnimation runRight = runLeft.CopyFlipped();

            animations.RegisterAnimation("RunRight", runRight, () => Velocity.X != 0 && CurrentFaceDirection == Direction.EAST);

            animations.AddFrameTransition("RunLeft", "RunRight");

            SpriteSheetAnimation idleLeft = new SpriteSheetAnimation(this, Assets.GetTexture("EnemyIdle"), 32, 32, 1);

            animations.RegisterAnimation("IdleLeft", idleLeft, () => Velocity.X == 0 && CurrentFaceDirection == Direction.WEST);

            SpriteSheetAnimation idleRight = idleLeft.CopyFlipped();

            animations.RegisterAnimation("IdleRight", idleRight, () => Velocity.X == 0 && CurrentFaceDirection == Direction.EAST);

            SpriteSheetAnimation jumpLeft = new SpriteSheetAnimation(this, Assets.GetTexture("EnemyRun"), 1);

            jumpLeft.StartFrame = 6;
            jumpLeft.EndFrame   = 7;
            animations.RegisterAnimation("JumpLeft", jumpLeft, () => !IsOnGround && CurrentFaceDirection == Direction.WEST, 1);

            SpriteSheetAnimation jumpRight = jumpLeft.CopyFlipped();

            animations.RegisterAnimation("JumpRight", jumpRight, () => !IsOnGround && CurrentFaceDirection == Direction.EAST, 1);

            CollisionOffsetBottom = 1;

            //AddComponent(new BoxCollisionComponent(this, 18, 30, new Vector2(-8, -30)));

            if (!Tutorial)
            {
                AddComponent(new BoxCollisionComponent(this, 18, 30, new Vector2(-8, -30)));
            }
            else
            {
                AddComponent(new BoxCollisionComponent(this, 22, 30, new Vector2(-8, -30)));
            }

            //DEBUG_SHOW_COLLIDER = true;
        }
Exemplo n.º 2
0
        public Hero(AbstractScene scene, Vector2 position) : base(scene.LayerManager.EntityLayer, null, position)
        {
            //DEBUG_SHOW_PIVOT = true;

            AddTag("Hero");
            AddCollisionAgainst("Enemy");
            AddCollisionAgainst("Spikes");
            AddCollisionAgainst("Trap");

            CanFireTriggers = true;

            DrawPriority = 10;

            AddCollisionAgainst("Pickup");
            AddCollisionAgainst("Door", false);
            AddCollisionAgainst("Key");
            AddCollisionAgainst("MountedGunBullet");

            SetupController();

            CollisionOffsetBottom = 1;
            CollisionOffsetLeft   = 0.5f;
            CollisionOffsetRight  = 0.5f;
            CollisionOffsetTop    = 1;

            CurrentFaceDirection = Direction.EAST;

            collisionComponent = new BoxCollisionComponent(this, 18, 30, new Vector2(-8, -30));
            AddComponent(collisionComponent);
            //DEBUG_SHOW_COLLIDER = true;

            AnimationStateMachine animations = new AnimationStateMachine();

            animations.Offset = offset;
            AddComponent(animations);

            SpriteSheetAnimation idleLeft = new SpriteSheetAnimation(this, Assets.GetTexture("HeroIdle"), 24);

            /*idleLeft.AnimationSwitchCallback = () => { if (CurrentWeapon != null) CurrentWeapon.SetAnimationBreathingOffset(Vector2.Zero); };
             * idleLeft.EveryFrameAction = (frame) =>
             *  {
             *      if (CurrentWeapon == null) return;
             *      float unit = 0.5f;
             *      float offsetY = 0;
             *      if (frame == 2 || frame == 3 || frame == 4)
             *      {
             *          offsetY += unit;
             *      }
             *      else if (frame == 6 || frame == 7)
             *      {
             *          offsetY -= unit;
             *      }
             *      CurrentWeapon.SetAnimationBreathingOffset(new Vector2(0, offsetY));
             *  };*/
            idleLeft.StartedCallback = () =>
            {
                if (CurrentWeapon == null)
                {
                    return;
                }
                if (CurrentWeapon is Shotgun)
                {
                    (CurrentWeapon as Handgun).SetLeftFacingOffset(new Vector2(-3, -17));
                    (CurrentWeapon as Handgun).SetRightFacingOffset(new Vector2(3, -17));
                }
                else if (CurrentWeapon is Machinegun)
                {
                    (CurrentWeapon as Handgun).SetLeftFacingOffset(new Vector2(-3, -17));
                    (CurrentWeapon as Handgun).SetRightFacingOffset(new Vector2(3, -17));
                }
                else if (CurrentWeapon is Handgun)
                {
                    (CurrentWeapon as Handgun).SetLeftFacingOffset(new Vector2(-3, -17));
                    (CurrentWeapon as Handgun).SetRightFacingOffset(new Vector2(3, -17));
                }
            };
            animations.RegisterAnimation("IdleLeft", idleLeft, () => previousPosition == Transform.Position && CurrentFaceDirection == Direction.WEST);

            SpriteSheetAnimation idleRight = idleLeft.CopyFlipped();

            animations.RegisterAnimation("IdleRight", idleRight, () => previousPosition == Transform.Position && CurrentFaceDirection == Direction.EAST);

            SpriteSheetAnimation runLeft = new SpriteSheetAnimation(this, Assets.GetTexture("HeroRun"), 40);

            runLeft.StartedCallback = () =>
            {
                if (CurrentWeapon == null)
                {
                    return;
                }
                if (CurrentWeapon is Shotgun)
                {
                    (CurrentWeapon as Handgun).SetLeftFacingOffset(new Vector2(-3, -17));
                    (CurrentWeapon as Handgun).SetRightFacingOffset(new Vector2(3, -17));
                }
                else if (CurrentWeapon is Machinegun)
                {
                    (CurrentWeapon as Handgun).SetLeftFacingOffset(new Vector2(-3, -17));
                    (CurrentWeapon as Handgun).SetRightFacingOffset(new Vector2(3, -17));
                }
                else if (CurrentWeapon is Handgun)
                {
                    (CurrentWeapon as Handgun).SetLeftFacingOffset(new Vector2(1, -17));
                    (CurrentWeapon as Handgun).SetRightFacingOffset(new Vector2(-1, -17));
                }
            };
            animations.RegisterAnimation("RunLeft", runLeft, () => Velocity.X < 0 && CurrentFaceDirection == Direction.WEST);

            SpriteSheetAnimation runRight = runLeft.CopyFlipped();

            animations.RegisterAnimation("RunRight", runRight, () => Velocity.X > 0 && CurrentFaceDirection == Direction.EAST);

            SpriteSheetAnimation runBackwardsLeft = new SpriteSheetAnimation(this, Assets.GetTexture("HeroRunBackwards"), 40);

            runBackwardsLeft.StartedCallback = () =>
            {
                if (CurrentWeapon == null)
                {
                    return;
                }
                if (CurrentWeapon is Shotgun)
                {
                    (CurrentWeapon as Handgun).SetLeftFacingOffset(new Vector2(-3, -17));
                    (CurrentWeapon as Handgun).SetRightFacingOffset(new Vector2(3, -17));
                }
                else if (CurrentWeapon is Machinegun)
                {
                    (CurrentWeapon as Handgun).SetLeftFacingOffset(new Vector2(-3, -17));
                    (CurrentWeapon as Handgun).SetRightFacingOffset(new Vector2(3, -17));
                }
                else if (CurrentWeapon is Handgun)
                {
                    (CurrentWeapon as Handgun).SetLeftFacingOffset(new Vector2(1, -17));
                    (CurrentWeapon as Handgun).SetRightFacingOffset(new Vector2(-1, -17));
                }
            };
            animations.RegisterAnimation("RunBackwardsLeft", runBackwardsLeft, () => Velocity.X > 0 && CurrentFaceDirection == Direction.WEST);

            SpriteSheetAnimation runRighrunBackwardsRight = runBackwardsLeft.CopyFlipped();

            animations.RegisterAnimation("RunBackwardsRight", runRighrunBackwardsRight, () => Velocity.X < 0 && CurrentFaceDirection == Direction.EAST);

            SpriteSheetAnimation jumpLeft = new SpriteSheetAnimation(this, Assets.GetTexture("HeroRun"), 1);

            jumpLeft.StartFrame = 6;
            jumpLeft.EndFrame   = 7;
            animations.RegisterAnimation("JumpLeft", jumpLeft, () => !IsOnGround && CurrentFaceDirection == Direction.WEST, 1);

            SpriteSheetAnimation jumpRight = jumpLeft.CopyFlipped();

            animations.RegisterAnimation("JumpRight", jumpRight, () => !IsOnGround && CurrentFaceDirection == Direction.EAST, 1);

            SpriteSheetAnimation jetpackLeft = new SpriteSheetAnimation(this, Assets.GetTexture("Jetpacking"), 40);

            animations.RegisterAnimation("JetpackLeft", jetpackLeft, () => flying && CurrentFaceDirection == Direction.WEST, 2);

            SpriteSheetAnimation jetpackRight = jetpackLeft.CopyFlipped();

            animations.RegisterAnimation("JetpackRight", jetpackRight, () => flying && CurrentFaceDirection == Direction.EAST, 2);

            SpriteSheetAnimation kickLeft = new SpriteSheetAnimation(this, Assets.GetTexture("Kick"), 40);

            kickLeft.Looping = false;
            kickLeft.AddFrameAction(5, (frame) =>
            {
                AudioEngine.Play("Kick");
                IsKicking = true;
                if (THIS_IS_SPARTAAAAA && collidingWith.Count > 0)
                {
                    THIS_IS_SPARTAAAAA    = false;
                    Vector2 canSpawnPos   = collidingWith[0].Transform.Position;
                    FuelCan can           = new FuelCan(scene, canSpawnPos + new Vector2(0, -20), TankCapacity);
                    can.Velocity         += new Vector2(-3, -1);
                    can.CollisionsEnabled = false;

                    Ammo ammo              = new Ammo(scene, canSpawnPos + new Vector2(0, -20), 20, typeof(Handgun));
                    ammo.Velocity         += new Vector2(-4f, -1.5f);
                    ammo.CollisionsEnabled = false;
                    Timer.TriggerAfter(2000, () =>
                    {
                        can.CollisionsEnabled  = true;
                        ammo.CollisionsEnabled = true;

                        new TextPopup(Scene, Assets.GetTexture("FuelAmmoText"), Transform.Position + new Vector2(-20, -80), 0.3f, 3000);
                    });
                }
            });
            kickLeft.AddFrameAction(6, (frame) =>
            {
                IsKicking = false;
            });
            kickLeft.StartedCallback = () =>
            {
                if (THIS_IS_SPARTAAAAA && collidingWith.Count > 0)
                {
                    THIS_IS_SPARTA();
                    Globals.FixedUpdateMultiplier = 0.1f;
                    Timer.TriggerAfter(3000, () =>
                    {
                        Globals.FixedUpdateMultiplier = 0.5f;

                        Timer.Repeat(1000, (elapsedTime) =>
                        {
                            Scene.Camera.Zoom -= 0.002f * elapsedTime;
                        });
                    });
                }
                //IsKicking = true;
                if (IsOnGround)
                {
                    MovementSpeed = 0;
                }

                if (CurrentWeapon == null)
                {
                    return;
                }
                if (CurrentWeapon is Shotgun)
                {
                    (CurrentWeapon as Handgun).SetLeftFacingOffset(new Vector2(-3, -17));
                    (CurrentWeapon as Handgun).SetRightFacingOffset(new Vector2(3, -17));
                }
                else if (CurrentWeapon is Machinegun)
                {
                    (CurrentWeapon as Handgun).SetLeftFacingOffset(new Vector2(-3, -17));
                    (CurrentWeapon as Handgun).SetRightFacingOffset(new Vector2(3, -17));
                }
                else if (CurrentWeapon is Handgun)
                {
                    (CurrentWeapon as Handgun).SetLeftFacingOffset(new Vector2(1, -17));
                    (CurrentWeapon as Handgun).SetRightFacingOffset(new Vector2(-1, -17));
                }
            };

            kickLeft.AnimationSwitchCallback = () =>
            {
                IsKicking     = false;
                MovementSpeed = Config.CHARACTER_SPEED;
                foreach (AbstractEnemy enemy in collidingWith)
                {
                    enemy.IsKicked = false;
                }
            };
            animations.RegisterAnimation("KickLeft", kickLeft, () => false);

            SpriteSheetAnimation kickRight = kickLeft.CopyFlipped();

            animations.RegisterAnimation("KickRight", kickRight, () => false);

            SpriteSheetAnimation kickJetpackLeft = new SpriteSheetAnimation(this, Assets.GetTexture("KickJetpacking"), 40);

            kickJetpackLeft.Looping = false;
            kickJetpackLeft.AddFrameAction(5, (frame) =>
            {
                AudioEngine.Play("Kick");
                IsKicking = true;
            });
            kickJetpackLeft.AddFrameAction(6, (frame) =>
            {
                IsKicking = false;
            });
            kickJetpackLeft.StartedCallback = () =>
            {
                //IsKicking = true;
                if (CurrentWeapon == null)
                {
                    return;
                }
                if (CurrentWeapon is Shotgun)
                {
                    (CurrentWeapon as Handgun).SetLeftFacingOffset(new Vector2(-3, -17));
                    (CurrentWeapon as Handgun).SetRightFacingOffset(new Vector2(3, -17));
                }
                else if (CurrentWeapon is Machinegun)
                {
                    (CurrentWeapon as Handgun).SetLeftFacingOffset(new Vector2(-3, -17));
                    (CurrentWeapon as Handgun).SetRightFacingOffset(new Vector2(3, -17));
                }
                else if (CurrentWeapon is Handgun)
                {
                    (CurrentWeapon as Handgun).SetLeftFacingOffset(new Vector2(1, -17));
                    (CurrentWeapon as Handgun).SetRightFacingOffset(new Vector2(-1, -17));
                }
            };
            kickJetpackLeft.AnimationSwitchCallback = () =>
            {
                IsKicking = false;
            };
            animations.RegisterAnimation("KickJetpackLeft", kickJetpackLeft, () => false);

            SpriteSheetAnimation kickJetpackRight = kickJetpackLeft.CopyFlipped();

            animations.RegisterAnimation("KickJetpackRight", kickJetpackRight, () => false);

            animations.AddFrameTransition("RunLeft", "RunBackwardsLeft");
            animations.AddFrameTransition("RunRight", "RunBackwardsRight");
            animations.AddFrameTransition("RunLeft", "RunRight");
            animations.AddFrameTransition("RunBackwardsLeft", "RunBackwardsRight");
            animations.AddFrameTransition("JetpackLeft", "JetpackRight");

            Visible = true;
            Active  = true;

            /*DebugFunction = () =>
             * {
             *  return "Fuel: " + (int)(((float)(Fuel / TankCapacity)) * 100) + " %";
             * };*/

            CurrentWeapon = new Handgun(scene, this);
            weapons.Add(CurrentWeapon);
            Machinegun mg = new Machinegun(scene, this);

            mg.Visible = false;
            Shotgun sg = new Shotgun(scene, this);

            sg.Visible = false;
            weapons.Add(mg);
            weapons.Add(sg);
        }