Beispiel #1
0
        public Player(Vector2 spritePosition, string spriteSheetName = "crash", DrawManager.Layer drawLayer = DrawManager.Layer.Playground) : base(spritePosition, spriteSheetName, drawLayer)
        {
            CreateColliders();
            SetAudioClips();

            RigidBody      = new RigidBody(sprite.position, this, null, colliders[State.Idle], true);
            RigidBody.Type = (uint)PhysicsManager.ColliderType.Player;
            RigidBody.SetCollisionMask((uint)(PhysicsManager.ColliderType.Ground | PhysicsManager.ColliderType.Crate | PhysicsManager.ColliderType.Trap));

            sprite.scale   = new Vector2(1.5f, 1.5f);
            Speed          = new Vector2(150f, -220f);
            VelocityLanded = Vector2.Zero;

            audioSource         = new AudioSource();
            audioSourceFootStep = new AudioSource();

            animations[(int)State.Waiting].LoopAtFrame(12);
            animations[(int)State.JumpStopped].LoopAtFrame(3);
            animations[(int)State.JumpInMovement].LoopAtFrame(7);
            animations[(int)State.Slide].LoopAtFrame(4);
            animations[(int)State.Crouch].LoopAtFrame(2);
            animations[(int)State.DeathBurnt].WaitForNextFrame(0, 1.5f);
            animations[(int)State.DeathBurnt].LoopAtFrame(14);
            animations[(int)State.DeathFalling].LoopAtFrame(7);
            animations[(int)State.DeathDrowned].LoopAtFrame(5);
            animations[(int)State.DeathRotation].LoopAtFrame(9);

            StateMachine       = new StateMachine(this);
            PlayerState.Player = this;

            StateMachine.RegisterState((int)State.Idle, new IdleState());
            StateMachine.RegisterState((int)State.Run, new RunState());
            StateMachine.RegisterState((int)State.JumpStopped, new JumpState());
            StateMachine.RegisterState((int)State.JumpInMovement, new LongJumpState());
            StateMachine.RegisterState((int)State.Landed, new LandedState());
            StateMachine.RegisterState((int)State.Attack, new AttackState());
            StateMachine.RegisterState((int)State.Slide, new SlideState());
            StateMachine.RegisterState((int)State.Crouch, new CrouchState());
            StateMachine.RegisterState((int)State.CrouchMoving, new CrouchMovingState());
            StateMachine.RegisterState((int)State.DeathBurnt, new DeathBurntState());
            StateMachine.RegisterState((int)State.DeathAngel, new DeathAngelState());
            StateMachine.RegisterState((int)State.DeathFalling, new DeathFalling());
            StateMachine.RegisterState((int)State.DeathDrowned, new DeathDrownedState());
            StateMachine.RegisterState((int)State.DeathMashed, new DeathMashedState());
            StateMachine.RegisterState((int)State.DeathRotation, new DeathRotationState());
            //registrare altre due deaths

            StateMachine.Switch((int)State.Idle);

            isHitted = false;
            currTimeInvulnerability = TIME_INVULNERABILITY_AFTER_HITTED;
            Apples    = 0;
            Life      = 4;
            timeBlink = 0; //when the player is hitted
            akuAku    = new AkuAku(Vector2.Zero, this);

            offsetParent = Vector2.Zero;

            ExtraLife.GuiObject = (NumerableGUIObject)GuiManager.GetGuiObject(GuiManager.GuiObjectType.LIFE);
            Apple.GuiObject     = (NumerableGUIObject)GuiManager.GetGuiObject(GuiManager.GuiObjectType.APPLE);

            initialPosition = Position;

            clipFootStep = AudioManager.GetAudioClip("grassFootStep");
            //OnAkuAkuPicked();
            //OnAkuAkuPicked();
            //OnAkuAkuPicked();
        }