Exemple #1
0
    public override void _IntegrateForces(Physics2DDirectBodyState bodyState)
    {
        Vector2 linearVelocity = bodyState.LinearVelocity;
        float   step           = bodyState.Step;

        PlayerInputInteraction playerInputInteraction = ListenToPlayerInput();

        linearVelocity.x -= this.floorHVelocity;
        floorHVelocity    = 0.0f;

        FloorContact floorContact = FindFloorContact(bodyState);

        ProcessSpawn(playerInputInteraction);
        ProcessShooting(playerInputInteraction, step);
        ProcessFloorContact(floorContact, step);
        linearVelocity = ProcessJump(playerInputInteraction, linearVelocity, step);
        linearVelocity = ProcessPlayerMovement(playerInputInteraction, linearVelocity, step);

        this.shooting = playerInputInteraction.Shoot;
        if (floorContact.FoundFloor)
        {
            floorHVelocity    = bodyState.GetContactColliderVelocityAtPosition(floorContact.FloorIndex).x;
            linearVelocity.x += floorHVelocity;
        }

        linearVelocity          += bodyState.TotalGravity * step;
        bodyState.LinearVelocity = linearVelocity;
    }
Exemple #2
0
    private void ProcessAnimation(PlayerInputInteraction playerInputInteraction, Vector2 linearVelocity)
    {
        String newAnimation = this.animation;

        if (this.jumping)
        {
            newAnimation = "jumping";
        }
        else if (Mathf.Abs(linearVelocity.x) < 0.1)
        {
            if (this.shootTime < MAX_SHOOT_POSE_TIME)
            {
                newAnimation = "idle_weapon";
            }
            else
            {
                newAnimation = "idle";
            }
        }
        else
        {
            if (this.shootTime < MAX_SHOOT_POSE_TIME)
            {
                newAnimation = "run_weapon";
            }
            else
            {
                newAnimation = "run";
            }
        }

        UpdateAnimation(newAnimation);
    }
Exemple #3
0
    private void ProcessInAirAnimation(PlayerInputInteraction playerInputInteraction, Vector2 linearVelocity)
    {
        String newAnimation = this.animation;

        if (linearVelocity.y < 0)
        {
            if (this.shootTime < MAX_SHOOT_POSE_TIME)
            {
                newAnimation = "jumping_weapon";
            }
            else
            {
                newAnimation = "jumping";
            }
        }
        else
        {
            if (this.shootTime < MAX_SHOOT_POSE_TIME)
            {
                newAnimation = "falling_weapon";
            }
            else
            {
                newAnimation = "falling_weapon";
            }
        }

        UpdateAnimation(newAnimation);
    }
Exemple #4
0
    private Vector2 ProcessPlayerInAirDirectionalMovement(PlayerInputInteraction playerInputInteraction, Vector2 linearVelocity, float step)
    {
        if (playerInputInteraction.MoveLeft && !playerInputInteraction.MoveRight)
        {
            if (linearVelocity.x > -WALK_MAX_VELOCITY)
            {
                linearVelocity.x -= AIR_ACCELERATION * step;
            }
        }
        else if (playerInputInteraction.MoveRight && !playerInputInteraction.MoveLeft)
        {
            if (linearVelocity.x < WALK_MAX_VELOCITY)
            {
                linearVelocity.x += AIR_ACCELERATION * step;
            }
        }
        else
        {
            float linearVelocityX = Mathf.Abs(linearVelocity.x);
            linearVelocityX -= AIR_DEACCELERATION * step;
            linearVelocityX  = linearVelocityX < 0 ? 0 : linearVelocityX;
            linearVelocity.x = Mathf.Sign(linearVelocity.x) * linearVelocityX;
        }

        return(linearVelocity);
    }
Exemple #5
0
 private void ProcessShooting(PlayerInputInteraction playerInputInteraction, float step)
 {
     if (playerInputInteraction.Shoot && !this.shooting)
     {
         CallDeferred("ShotBullet");
     }
     else
     {
         this.shootTime += step;
     }
 }
Exemple #6
0
    private Vector2 ProcessJumpMovement(PlayerInputInteraction playerInputInteraction, Vector2 linearVelocity, float step)
    {
        if (!this.jumping && playerInputInteraction.Jump)
        {
            linearVelocity.y  = -JUMP_VELOCITY;
            this.jumping      = true;
            this.stoppingJump = false;
            AudioStreamPlayer2D soundJump = GetNode("SoundJump") as AudioStreamPlayer2D;
            soundJump.Play();
        }

        return(linearVelocity);
    }
Exemple #7
0
    private void ProcessSpawn(PlayerInputInteraction playerInputInteraction)
    {
        if (playerInputInteraction.Spawn)
        {
            RigidBody2D enemy    = this.enemyScene.Instance() as RigidBody2D;
            Vector2     position = Position;

            position.y     = position.y - 100;
            enemy.Position = position;

            GetParent().AddChild(enemy);
        }
    }
Exemple #8
0
    private void ProcessPlayerSiding(PlayerInputInteraction playerInputInteraction, Vector2 linearVelocity)
    {
        bool newSidingLeft = this.sidingLeft;

        if (linearVelocity.x < 0 && playerInputInteraction.MoveLeft)
        {
            newSidingLeft = true;
        }
        else if (linearVelocity.x > 0 && playerInputInteraction.MoveRight)
        {
            newSidingLeft = false;
        }

        UpdateSidingLeft(newSidingLeft);
    }
Exemple #9
0
    private Vector2 ProcessPlayerMovement(PlayerInputInteraction playerInputInteraction, Vector2 linearVelocity, float step)
    {
        bool onFloor = airborneTime < MAX_FLOOR_AIRBORNE_TIME;

        if (onFloor)
        {
            linearVelocity = ProcessPlayerDirectionalMovement(playerInputInteraction, linearVelocity, step);
            linearVelocity = ProcessJumpMovement(playerInputInteraction, linearVelocity, step);
            ProcessPlayerSiding(playerInputInteraction, linearVelocity);
            ProcessAnimation(playerInputInteraction, linearVelocity);
        }
        else
        {
            linearVelocity = ProcessPlayerInAirDirectionalMovement(playerInputInteraction, linearVelocity, step);
            ProcessInAirAnimation(playerInputInteraction, linearVelocity);
        }

        return(linearVelocity);
    }
Exemple #10
0
    private Vector2 ProcessJump(PlayerInputInteraction playerInputInteraction, Vector2 linearVelocity, float step)
    {
        if (!this.jumping)
        {
            return(linearVelocity);
        }

        if (linearVelocity.y > 0)
        {
            this.jumping = false;
        }
        else if (!playerInputInteraction.Jump)
        {
            this.stoppingJump = true;
        }

        if (this.stoppingJump)
        {
            linearVelocity.y += STOP_JUMP_FORCE * step;
        }

        return(linearVelocity);
    }