예제 #1
0
        public List <Action> jumpInDirection(Vector3 dir)
        {
            var ret = new List <Action>();
            var ja  = new JumpAction();

            var d = PosNegAngle(Vector3.up, dir, Vector3.forward);

            //var d = Vector3.Angle(Vector3.up, dir);
            //Debug.Log(d);

            // TODO: control strafe during jump

            if (d > 0)
            {
                var la = new LeftAction();
                ret.Add(la);
            }
            else
            {
                var ra = new RightAction();
                ret.Add(ra);
            }

            ret.Add(ja);
            return(ret);
        }
예제 #2
0
        public Jump(BaseEvent eventFrame, Character character, Skill parentSkill,
                    Environment environment, bool jumpOverDistance = true)
        {
            this.character        = character;
            this.parentSkill      = parentSkill;
            this.environment      = environment;
            this.jumpOverDistance = jumpOverDistance;

            characterCollider = character.GameObject().GetComponent <BoxCollider>();

            BaseEvent be = eventFrame;

            jumpAction = (JumpAction)be.action;
            if (be.trigger.ShowTriggerType() == TriggerType.Frame)
            {
                TimelineTrigger tt = (TimelineTrigger)be.trigger;
                if (tt.ShowScaledFrameInSeconds() == 0)
                {
                    DoJump();
                }
            }
            else
            {
                DoJump();
            }
        }
예제 #3
0
 private void JumpTo(TextSpan location)
 {
     if (null != location)
     {
         JumpAction?.Invoke(location.Start);
     }
 }
예제 #4
0
    void FixedUpdate()
    {
        currentX = Input.GetAxisRaw("Horizontal");
        if (Mathf.Abs(previousX - currentX) > 0.0f)
        {
            createHorizontal = true;
        }
        previousX = currentX;

        if (createKys)
        {
            var action = new KysAction(cc);
            loopTracker.RegisterAction(action);
            action.PlayAction();
            createKys = false;
        }
        if (createHorizontal)
        {
            var action = new HorizontalAction(previousX, player);
            loopTracker.RegisterAction(action);
            action.PlayAction();
            createHorizontal = false;
        }

        if (createJump)
        {
            var action = new JumpAction(player, isJumpKeyDown);
            loopTracker.RegisterAction(action);
            action.PlayAction();
            createJump = false;
        }
    }
예제 #5
0
 private void Start()
 {
     groundDistance = collider.bounds.extents.y + GROUND_DISTANCE_OFFSET;
     state          = GetComponent <VerticalState>();
     jumpAction     = GetComponent <JumpAction>();
     jumpBuffer     = GetComponent <JumpBuffer>();
 }
예제 #6
0
 public ToJump(StateMachine sm_)
 {
     sm          = sm_;
     targetState = sm.jumpState;
     condition   = new JumpCondition(sm);
     actions     = new IAction[1];
     actions[0]  = new JumpAction(sm);
 }
예제 #7
0
    private IEnumerator WaitJump()
    {
        yield return(new WaitForSeconds(0.2f));

        if (JumpAction != null)
        {
            var force = Time.time - jumpTimer <= 0.2f ? 1.25f : 1f;     //TODO убрать в константы
            JumpAction.Invoke(force);
        }
        waitJumpCoroutine = null;
    }
예제 #8
0
    public void StopMovement()
    {
        var action = new HorizontalAction(0.0f, player);

        loopTracker.RegisterAction(action);
        action.PlayAction();

        var action2 = new JumpAction(player, false);

        loopTracker.RegisterAction(action2);
        action2.PlayAction();
    }
예제 #9
0
 public JumpState(StateMachine sm_)
 {
     sm              = sm_;
     exitActions     = new IAction[1];
     exitActions[0]  = new JumpAction(sm);
     entryActions    = new IAction[1];
     entryActions[0] = new JumpAction(sm);
     actions         = new IAction[1];
     actions[0]      = new JumpAction(sm);
     transitions     = new ITransition[2];
     transitions[0]  = new ToInitial(sm);
     transitions[1]  = new ToAerial(sm);
 }
예제 #10
0
    public IEnumerator WaitJump()
    {
        //ожидаем второго нажатия на прыжок
        yield return(new WaitForSeconds(0.2f));

        if (JumpAction != null)
        {
            //должно быть в константе
            var force = Time.time - jumpTimer < 0.2f ? 1.25f : 1f;
            JumpAction.Invoke(force);
        }

        waitForJumpCoroutine = null;
    }
예제 #11
0
        public override void Update(GameManager game, float delta)
        {
            if (Input.GetKey(KeyCode.A))
            {
                MoveAction a = MoveAction.Make(-1);
                a.Apply(game, _transform.EntityID);
                a.Recycle();
            }


            if (Input.GetKey(KeyCode.D))
            {
                MoveAction a = MoveAction.Make(1);
                a.Apply(game, _transform.EntityID);
                a.Recycle();
            }


            if (Input.GetKey(KeyCode.W))
            {
                MoveZAction a = MoveZAction.Make(1);
                a.Apply(game, _transform.EntityID);
                a.Recycle();
            }

            if (Input.GetKey(KeyCode.S))
            {
                MoveZAction a = MoveZAction.Make(-1);
                a.Apply(game, _transform.EntityID);
                a.Recycle();
            }


            if (Input.GetKeyDown(KeyCode.Space))
            {
                JumpAction a = JumpAction.Make();
                a.Apply(game, _transform.EntityID);
                a.Recycle();
            }


            if (Input.GetMouseButton(0))
            {
            }
        }
예제 #12
0
        public override void Update(GameManager game, float delta)
        {
            foreach (int entity in _entityList)
            {
                GAstarComponent astarComponent = game.Entities.GetComponentOf <GAstarComponent>(entity);
                GTransform      transform      = game.Entities.GetComponentOf <GTransform>(entity);
                ActionQueue     _actionQueue   = game.Entities.GetComponentOf <ActionQueue>(entity);
                Vector3         current        = astarComponent._current;
                bool            wait           = false;
                //Debug.Log("Astar value "  + astarComponent._path.ElementAt(astarComponent._index).Value);
                if (checkCollision(transform, current))
                {
                    if (!astarComponent._path.ElementAt(astarComponent._index).Value)
                    {
                        astarComponent._index++;
                        astarComponent._current = astarComponent._path.ElementAt(astarComponent._index).Key;
                    }
                }
                if (checkFullCollision(transform, current) && astarComponent._path.ElementAt(astarComponent._index).Value&& game.Entities.GetComponentOf <GMovement>(entity)._grounded)
                {
                    JumpAction a = JumpAction.Make();
                    a.Apply(game, transform.EntityID);
                    a.Recycle();
                    astarComponent._index++;
                    astarComponent._current = astarComponent._path.ElementAt(astarComponent._index).Key;
                }

                if (Mathf.Abs(transform._position.x - current.x) > 0.1f)
                {
                    MoveAction a = MoveAction.Make(current.x - transform._position.x);
                    a.Apply(game, transform.EntityID);
                    a.Recycle();
                }
                if (Mathf.Abs(transform._position.z - current.z) > 0.1f)
                {
                    //Debug.Log("Move Z " + Mathf.Sign(current.x - transform._position.x));
                    MoveZAction a = MoveZAction.Make(current.z - transform._position.z);
                    a.Apply(game, transform.EntityID);
                    a.Recycle();
                }
            }
        }
예제 #13
0
        public void ApplyOp(IPlayerOp op)
        {
            if (this.isDie)
            {
                return;
            }

            switch (op.Type)
            {
            case PlayerOpEnum.Move:
                WalkAction wa = new WalkAction();
                wa.dir = (op as MoveOp).Direction;
                this.ApplyChangePos(wa);

                break;

            case PlayerOpEnum.Jump:

                JumpAction ja = new JumpAction();
                this.ApplyChangePos(ja);
                break;
            }
        }
예제 #14
0
        private void InAirUpdate()
        {
            // NOTE: Character momentum is allowed to exceed run speed, but not by character's own force.

            // Character Movement & Handling
            FInt speedMult = (this.shoes is Shoes || this.input.isDown(IKey.XButton)) ? FInt.Create(1) : this.stats.SlowSpeedMult;
            FInt maxSpeed  = this.stats.RunMaxSpeed * speedMult;

            // Maximum Fall Speed
            if (this.physics.velocity.Y > 14)
            {
                this.physics.velocity.Y = FInt.Create(14);
            }

            // Movement Right
            if (this.input.isDown(IKey.Right))
            {
                this.FaceRight = true;

                // Move Right up to maximum speed. (Must use FInt Math, not Math.Min)
                if (maxSpeed > this.physics.velocity.X)
                {
                    this.physics.velocity.X += this.stats.AirAcceleration * speedMult;
                    if (this.physics.velocity.X > maxSpeed)
                    {
                        this.physics.velocity.X = maxSpeed;
                    }
                }

                // If there's too much momentum, decelerate to normal speed:
                else
                {
                    this.DecelerateChar(this.stats.AirDeceleration, 2 - speedMult, FInt.Create(0.065));                         // Roughly 1/16
                }
            }

            // Movement Left
            else if (this.input.isDown(IKey.Left))
            {
                this.FaceRight = false;

                // Move Left up to maximum speed.(Must use FInt Math, not Math.Min)
                if (maxSpeed.Inverse < this.physics.velocity.X)
                {
                    this.physics.velocity.X -= this.stats.AirAcceleration * speedMult;
                    if (this.physics.velocity.X < maxSpeed.Inverse)
                    {
                        this.physics.velocity.X = maxSpeed.Inverse;
                    }
                }

                // If there's too much momentum, decelerate to normal speed:
                else
                {
                    this.DecelerateChar(this.stats.AirDeceleration, 2 - speedMult, FInt.Create(0.065));                     // Roughly 1/16
                }
            }

            // Resting Friction (No Intentional Movement)
            else
            {
                this.DecelerateChar(this.stats.AirDeceleration, 2 - speedMult, (FInt)1);
            }

            // Attempted Air Jump
            if (this.input.isPressed(IKey.AButton))
            {
                this.status.rapidRejump = Systems.timer.Frame + 5;

                // Delayed Wall Jump
                // Creates a smoother wall jump experience by giving a little leeway after leaving the wall.
                if (this.status.leaveWall >= Systems.timer.Frame)
                {
                    ActionMap.WallJump.StartAction(this, this.status.grabDir);
                }

                // Double Jump
                else if (JumpAction.CanJump(this))
                {
                    ActionMap.Jump.StartAction(this);
                }
            }
        }
예제 #15
0
        private void OnFloorUpdate()
        {
            this.status.coyoteJump = Systems.timer.Frame + 4;

            // Character Movement & Handling
            FInt speedMult = (this.shoes is Shoes || this.input.isDown(IKey.XButton)) ? FInt.Create(1) : this.stats.SlowSpeedMult;
            FInt maxSpeed  = this.stats.RunMaxSpeed * speedMult;

            // Movement Right
            if (this.input.isDown(IKey.Right))
            {
                this.FaceRight = true;

                // Move Right up to maximum speed. (Must use FInt Math, not Math.Min)
                if (maxSpeed > this.physics.velocity.X)
                {
                    this.physics.velocity.X += this.stats.RunAcceleration * speedMult;
                    if (this.physics.velocity.X > maxSpeed)
                    {
                        this.physics.velocity.X = maxSpeed;
                    }
                }

                // If there's too much momentum, decelerate to normal speed:
                else
                {
                    this.DecelerateChar(this.stats.RunDeceleration, 2 - speedMult, FInt.Create(0.25));
                }
            }

            // Movement Left
            else if (this.input.isDown(IKey.Left))
            {
                this.FaceRight = false;

                // Move Left up to maximum speed. (Must use FInt Math, not Math.Min)
                if (this.physics.velocity.X > maxSpeed.Inverse)
                {
                    this.physics.velocity.X -= this.stats.RunAcceleration * speedMult;
                    if (this.physics.velocity.X < maxSpeed.Inverse)
                    {
                        this.physics.velocity.X = maxSpeed.Inverse;
                    }
                }

                // If there's too much momentum, decelerate to normal speed:
                else
                {
                    this.DecelerateChar(this.stats.RunDeceleration, 2 - speedMult, FInt.Create(0.25));
                }
            }

            // Resting Friction (No Intentional Movement)
            else
            {
                this.DecelerateChar(this.stats.RunDeceleration, 2 - speedMult, FInt.Create(2));
            }

            // As long as we're not currently sliding:
            if (status.action is SlideAction == false)
            {
                // Reset Actions on Land
                if (this.physics.touch.toBottom)
                {
                    // Only apply landing if the minimum jump time has not passed.
                    // Prevents issues like springs causing infinite jumps.
                    if (status.action is JumpAction == false || JumpAction.MinimumTimePassed(status))
                    {
                        if (status.action is Action)
                        {
                            status.action.LandsOnGround(this);
                        }
                        status.jumpsUsed = 0;
                    }

                    // Update Shoes
                    if (this.shoes is Shoes)
                    {
                        this.shoes.TouchWall();
                    }
                }

                // Attempt Jump
                bool doJump = status.action is JumpAction == false && (input.isPressed(IKey.AButton) || (input.isDown(IKey.AButton) && status.rapidRejump >= Systems.timer.Frame));

                // JUMP Button Pressed
                if (doJump)
                {
                    // JUMP+DOWN (Slide or Platform Drop) is Activated
                    if (input.isDown(IKey.Down))
                    {
                        // If on a Platform, perform Down-Jump
                        if (this.physics.touch.onMover)
                        {
                            ActionMap.Dropdown.StartAction(this, 6);
                        }

                        // Slide, if able:
                        else if (SlideAction.IsAbleToSlide(this, this.FaceRight))
                        {
                            ActionMap.Slide.StartAction(this, this.FaceRight);
                        }

                        // Otherwise, JUMP.
                        else
                        {
                            ActionMap.Jump.StartAction(this);
                        }
                    }

                    // JUMP
                    else
                    {
                        ActionMap.Jump.StartAction(this);
                    }
                }
            }
        }
예제 #16
0
        /// <summary>
        ///     Check keyboard input and fire events according to what was pressed.
        /// </summary>
        private void CheckInput()
        {
            if (TMBAW_Game.CurrentGameMode == GameMode.None)
            {
                return;
            }

            if (TMBAW_Game.Dialog.IsActive)
            {
                return;
            }

            if (StoryTracker.InCutscene || GameWorld.IsInCutsceneMode)
            {
                return;
            }

            if (DialogueSystem.IsShowingDialogue)
            {
                return;
            }

            if (TMBAW_Game.CurrentGameMode == GameMode.Edit)
            {
                return;
            }

            if (IsPunchPressed() && !_attackIsPressed)
            {
                PlayerScript.TimeSinceLastPunch.Reset();
            }

            if (!PlayerScript.IsDoingAction)
            {
                if (TMBAW_Game.CurrentGameMode == GameMode.Play)
                {
                    if (IsRewindPressed())
                    {
                        RewindAction?.Invoke();
                    }
                }
                if (IsMoveLeftPressed())
                {
                    LeftMove?.Invoke();
                }
                if (IsMoveRightPressed())
                {
                    RightMove?.Invoke();
                }
                if (IsMoveDownPressed())
                {
                    if (GameWorld.WorldData.IsTopDown)
                    {
                        DownMove?.Invoke();
                    }
                    else
                    {
                        DuckAction?.Invoke();
                    }
                }
                else
                {
                    DuckActionStop?.Invoke();
                }
                if (IsInteractPressed())
                {
                    if (GameWorld.WorldData.IsTopDown)
                    {
                        UpMove?.Invoke();
                    }
                    else
                    {
                        InteractAction?.Invoke();
                    }
                }

                if (!IsMoveDownPressed() && !IsInteractPressed())
                {
                    ReleaseUpAndDownAction?.Invoke();
                }

                if (IsPunchPressed())
                {
                    if (!_attackIsPressed)
                    {
                        //FireWeaponAction?.Invoke();
                        _attackIsPressed = true;
                    }
                }
                else
                {
                    _attackIsPressed = false;
                }

                if (IsWeaponFirePressed())
                {
                    FireWeaponAction?.Invoke();
                }

                if (InputSystem.WasKeyReleased(Keys.Space) && IsJumpButtonPressed())
                {
                    JumpAction?.Invoke();
                    //_jumpButtonIsPressed = true;
                }
                //else
                //{
                //    _jumpButtonIsPressed = false;
                //}
                if (IsSprintButtonPressed())
                {
                    FastRunActive?.Invoke();
                }
                else
                {
                    FastRunInactive?.Invoke();
                }
            }


            StillUpdate?.Invoke();

            if (InputSystem.IsAnyInputPressed())
            {
                NotIdle?.Invoke();
            }
        }
예제 #17
0
 private void Start()
 {
     groundDistance = collider.bounds.extents.y + VerticalMovement.Constants.SQUARE_DISTANCE_OFFSET;
     jumpAction     = GetComponent <JumpAction>();
 }
    void Update()
    {
        if (!isFreeze)
        {
            return;
        }
        if (!m_TimelineManager.m_MoveTimeline.Locked)
        {
            if (Input.GetButtonDown("Horizontal"))
            {
                // Start recording horizontal movement
                m_StartActionTime = Time.time;
                float  direction   = GetMoveDirection();
                float  currentTime = Time.time;
                float  duration    = currentTime - m_StartActionTime;
                Action action      = new MoveAction(m_StartActionTime - m_PlayTime, duration, direction, 1);
                m_TimelineManager.RecordAction(action);
                Move(direction);
            }


            if (Input.GetButton("Horizontal"))
            {
                float direction   = GetMoveDirection();
                float currentTime = Time.time;
                float duration    = currentTime - m_StartActionTime;
                m_TimelineManager.m_MoveTimeline.UpdateDurationLastAction(duration);
                m_TimelineManager.m_MoveTimeline.UpdateDirectionLastAction(direction);
                Move(direction);
            }

            if (Input.GetButtonUp("Horizontal"))
            {
                float direction   = GetMoveDirection();
                float currentTime = Time.time;
                float duration    = currentTime - m_StartActionTime;
                m_TimelineManager.m_MoveTimeline.UpdateDurationLastAction(duration);
                Debug.Log("Add new action at " + m_StartActionTime + ". Move timeline: " + m_TimelineManager.m_MoveTimeline.Length());
            }
        }



        // Jump
        if (Input.GetButtonDown("Jump") && !m_TimelineManager.m_JumpTimeline.Locked)
        {
            float  time   = Time.time - m_PlayTime;
            Action action = new JumpAction(time);
            if (Jump())
            {
                m_TimelineManager.RecordAction(action);
            }
            Debug.Log("Jump timeline: " + m_TimelineManager.m_JumpTimeline.Length());
        }


        // Shoot
        if (Input.GetButtonDown("Fire1") && m_BulletRemaining > 0 && !m_TimelineManager.m_ShootTimeline.Locked)
        {
            float  time   = Time.time - m_PlayTime;
            Action action = new ShootAction(time);
            Fire();
            m_TimelineManager.RecordAction(action);
            Debug.Log("Shoot timeline: " + m_TimelineManager.m_ShootTimeline.Length());
        }
    }
예제 #19
0
    void Start()
    {
        fsm = new FSM("Boss Ai");

        standState      = fsm.AddState("StandState");
        moveTargetState = fsm.AddState("MoveTargetState");
        retreatState    = fsm.AddState("RetreatState");
        runTargetState  = fsm.AddState("RunTargetState");
        jumpState       = fsm.AddState("JumpState");


        standAction      = new StandAction(standState);
        moveTargetAction = new MoveTargetAction(moveTargetState);
        retreatAction    = new RetreatAction(retreatState);
        runTargetAction  = new MoveTargetAction(runTargetState);
        jumpAction       = new JumpAction(jumpState);


        finishEventRun = new List <string>
        {
            "to move target",
            "to retreat",
            "to stand",
            "to jump"
        };

        finishEventStand = new List <string>
        {
            "to move target",
            "to retreat",
            "to run",
            "to jump"
        };

        finishEventMoveTarget = new List <string>
        {
            "to move target",
            "to stand",
            "to retreat",
            "to jump"
        };
        finishEventRetreat = new List <string>
        {
            "to stand",
            "to run"
        };
        finishEventJump = new List <string>
        {
            "to stand"
        };


        standState.AddAction(standAction);

        runTargetState.AddAction(runTargetAction);

        moveTargetState.AddAction(moveTargetAction);

        retreatState.AddAction(retreatAction);

        jumpState.AddAction(jumpAction);

        standState.AddTransition("to move target", moveTargetState);
        standState.AddTransition("to retreat", retreatState);
        standState.AddTransition("to run", runTargetState);
        standState.AddTransition("to jump", jumpState);

        moveTargetState.AddTransition("to move target", moveTargetState);
        moveTargetState.AddTransition("to stand", standState);
        moveTargetState.AddTransition("to retreat", retreatState);
        moveTargetState.AddTransition("to jump", jumpState);

        retreatState.AddTransition("to stand", standState);
        retreatState.AddTransition("to run", runTargetState);

        runTargetState.AddTransition("to move target", moveTargetState);
        runTargetState.AddTransition("to stand", standState);
        runTargetState.AddTransition("to retreat", retreatState);
        runTargetState.AddTransition("to jump", jumpState);

        jumpState.AddTransition("to stand", standState);



        vecPos     = GameObject.Find("Boss").transform.position;
        vecEnnemis = new Vector3(0.1f, 0, 0);
        vecJump    = new Vector3(0f, 0.15f, 0);


        moveTargetAction.init(this.transform, vecEnnemis, 2.0f, finishEventMoveTarget);
        retreatAction.init(this.transform, vecEnnemis, 0.5f, finishEventRetreat);
        runTargetAction.init(this.transform, new Vector3(0.3f, 0, 0), 1.0f, finishEventRun);
        jumpAction.init(this.transform, vecJump, 2f, finishEventJump);

        standAction.init(1.0f, finishEventStand);

        fsm.Start("StandState");
    }