コード例 #1
0
 public override void OnFixedUpdate()
 {
     if (C.isTransitioning)
         return;
     if (initDelay > 0)
     {
         if (stateCount > initDelay)
         {
             initDelay = 0;
             stateCount = 0;
         }
         return;
     }
     if (loaded)
     {
         if (stateCount > .5f)
         {
             Arrow a = new Arrow(this, world);
             a.SetDirection(CurrentDirection);
             a.PlayAnim();
             switch(CurrentDirection)
             {
                 case Direction.UP: a.yVel = arrowSpeed; break;
                 case Direction.RIGHT: a.xVel = arrowSpeed; break;
                 case Direction.DOWN: a.yVel = -arrowSpeed; break;
                 case Direction.LEFT: a.xVel = -arrowSpeed; break;
             }
             a.SetPosition(this.GetPosition());
             world.addObject(a);
             loaded = false;
             stateCount = 0;
         }
     }
     else
     {
         if (stateCount > interval)
         {
             loaded = true;
             stateCount = 0;
         }
     }
     base.OnFixedUpdate();
     PlayAnim();
 }
コード例 #2
0
ファイル: Player.cs プロジェクト: maggardJosh/SpiritGuard
    public override void OnFixedUpdate()
    {
        swordCollision.SetPosition(this.GetPosition());
        switch (_direction)
        {
            case Direction.RIGHT:
                swordCollision.hitBox.x = 6;
                swordCollision.hitBox.y = -8;
                swordCollision.hitBox.width = 15;
                swordCollision.hitBox.height = 12;
                break;
            case Direction.LEFT:

                swordCollision.hitBox.x = -6;
                swordCollision.hitBox.y = -8;
                swordCollision.hitBox.width = 15;
                swordCollision.hitBox.height = 12;

                break;
            case Direction.DOWN:
                swordCollision.hitBox.x = 0;
                swordCollision.hitBox.y = -12;
                swordCollision.hitBox.width = 12;
                swordCollision.hitBox.height = 15;

                break;
            case Direction.UP:
                swordCollision.hitBox.x = 0;
                swordCollision.hitBox.y = 8;
                swordCollision.hitBox.width = 12;
                swordCollision.hitBox.height = 15;
                break;
        }
        swordCollision.UpdateHitBoxSprite();

        if (C.isTransitioning)
            return;
        switch (State)
        {
            case PlayerState.IDLE:
            case PlayerState.MOVE:
                maxXVel = 1f;
                maxYVel = 1;
                minYVel = -1f;
                if (State == PlayerState.MOVE)
                    if (RXRandom.Float() < .04f)
                        SpawnParticles((Direction)((int)(_direction + 2) % Enum.GetValues(typeof(Direction)).Length), 1);
                shouldDamage = false;
                if (C.getKey(C.JUMP_KEY) && CanJump && !world.checkForInteractObject(this))
                {

                    FSoundManager.PlaySound("jump");
                    State = PlayerState.JUMP;
                    if (C.getKey(C.RIGHT_KEY))
                        _direction = Direction.RIGHT;
                    else if (C.getKey(C.DOWN_KEY))
                        _direction = Direction.DOWN;
                    else if (C.getKey(C.LEFT_KEY))
                        _direction = Direction.LEFT;
                    else if (C.getKey(C.UP_KEY))
                        _direction = Direction.UP;
                    Go.killAllTweensWithTarget(this);
                    PlayAnim(true);

                    SpawnParticles((Direction)((int)(_direction + 2) % Enum.GetValues(typeof(Direction)).Length));

                    float newX = this.x;
                    float newY = this.y;
                    float targetY;
                    float targetX;
                    switch (_direction)
                    {
                        case Direction.UP:
                            targetY = this.y + maxJumpDist;
                            while (newY < targetY && !(world.CheckForJumpObjectCollisionHitbox(this, this.x, newY) != null))
                                newY += 1;
                            while (newY > this.y &&
                                (!world.isAllPassable(this, this.x , newY, false) ||
                                world.CheckObjectCollisionHitbox(this, this.x, newY) != null))
                            { newY -= 1f; }
                            break;
                        case Direction.RIGHT:
                            targetX = this.x + maxJumpDist;
                            while (newX < targetX && !(world.CheckForJumpObjectCollisionHitbox(this, newX, this.y) != null))
                                newX += 1;
                            while (newX > this.x && (!world.isAllPassable(this,newX , this.y, true) || world.CheckObjectCollisionHitbox(this, newX, this.y) != null)) { newX -= 1f; } break;
                        case Direction.DOWN:
                            targetY = this.y - maxJumpDist;
                            while (newY > targetY && !(world.CheckForJumpObjectCollisionHitbox(this, this.x, newY) != null))
                                newY -= 1;
                            while (newY < this.y && (!world.isAllPassable(this, this.x , newY, false) || world.CheckObjectCollisionHitbox(this, this.x, newY) != null)) { newY += 1f; } break;
                        case Direction.LEFT:
                            targetX = this.x - maxJumpDist;
                            while (newX > targetX && !(world.CheckForJumpObjectCollisionHitbox(this, newX, this.y) != null))
                                newX -= 1;
                            while (newX < this.x && (!world.isAllPassable(this, newX, this.y, true) || world.CheckObjectCollisionHitbox(this, newX, this.y) != null)) { newX += 1f; } break;
                    }
                    xVel = 0;
                    yVel = 0;
                    float jumpTime = .5f;
                    float jumpDisp = 10f;
                    if (_direction == Direction.UP || _direction == Direction.DOWN)
                    {
                        Go.to(this, jumpTime / 2f, new TweenConfig().floatProp("x", -jumpDisp, true).setEaseType(EaseType.QuadOut).setIterations(2, LoopType.PingPong));
                        Go.to(this, jumpTime, new TweenConfig().floatProp("y", newY).setEaseType(EaseType.QuadOut).onComplete(() => { yVel = .01f; State = PlayerState.IDLE; }));

                    }
                    else
                    {
                        Go.to(this, jumpTime / 2f, new TweenConfig().floatProp("y", jumpDisp, true).setEaseType(EaseType.QuadOut).setIterations(2, LoopType.PingPong));
                        Go.to(this, jumpTime, new TweenConfig().floatProp("x", newX).setEaseType(EaseType.QuadOut).onComplete(() => { yVel = .01f; State = PlayerState.IDLE; }));

                    }
                    if (_direction == Direction.RIGHT)
                        scaleX = -1;
                    else if (_direction == Direction.LEFT)
                        scaleX = 1;
                    return;
                }
                float attackTime = .4f;
                float attackDist = 16;
                float attackDisp = 3f;
                if (C.getKey(C.SELECT_KEY) && !lastSelectPress)
                {
                    if (selectedItem == SecondaryItem.SWORD && C.Save.canBow)
                    {
                        FSoundManager.PlaySound("swap");
                        selectedItem = SecondaryItem.BOW;
                        world.ui.UpdateSelectedItem(selectedItem);
                    }
                    else if (selectedItem == SecondaryItem.BOW && C.Save.canSword)
                    {
                        FSoundManager.PlaySound("swap");
                        selectedItem = SecondaryItem.SWORD;
                        world.ui.UpdateSelectedItem(selectedItem);
                    }
                }
                if (C.getKey(C.ACTION_KEY))
                {
                    hasSpawnedSpiritParticles = false;
                    switch (selectedItem)
                    {
                        case SecondaryItem.SWORD:
                            if (lastActionPress)
                                break;
                            FSoundManager.PlaySound("swordOne");
                            State = PlayerState.SWORD;
                            if (C.getKey(C.RIGHT_KEY))
                                _direction = Direction.RIGHT;
                            else if (C.getKey(C.DOWN_KEY))
                                _direction = Direction.DOWN;
                            else if (C.getKey(C.LEFT_KEY))
                                _direction = Direction.LEFT;
                            else if (C.getKey(C.UP_KEY))
                                _direction = Direction.UP;

                            SpawnParticles((Direction)((int)(_direction + 2) % Enum.GetValues(typeof(Direction)).Length));

                            Go.killAllTweensWithTarget(this);
                            float newX = this.x;
                            float newY = this.y;
                            switch (_direction)
                            {
                                case Direction.UP: newY += attackDist; while (newY > this.y && (!world.isAllPassable(this.x + hitBox.x, newY + hitBox.y + hitBox.height / 2f) || !world.isAllPassable(this.x + hitBox.x, newY + hitBox.y - hitBox.height / 2f) || world.CheckObjectCollision(this, this.x + hitBox.x, newY + hitBox.y + hitBox.height / 2f) != null || world.CheckObjectCollision(this, this.x + hitBox.x, newY + hitBox.y - hitBox.height / 2f) != null)) { newY -= 1f; } break;
                                case Direction.RIGHT: newX += attackDist; while (newX > this.x && (!world.isAllPassable(newX + hitBox.x + hitBox.width / 2f, this.y + hitBox.y) || !world.isAllPassable(newX + hitBox.x - hitBox.width / 2f, this.y + hitBox.y) || world.CheckObjectCollision(this, newX + hitBox.x + hitBox.width / 2f, this.y + hitBox.y) != null || world.CheckObjectCollision(this, newX + hitBox.x - hitBox.width / 2f, this.y + hitBox.y) != null)) { newX -= 1f; } break;
                                case Direction.DOWN: newY -= attackDist; while (newY < this.y && (!world.isAllPassable(this.x + hitBox.x, newY + hitBox.y + hitBox.height / 2f) || !world.isAllPassable(this.x + hitBox.x, newY + hitBox.y - hitBox.height / 2f) || world.CheckObjectCollision(this, this.x + hitBox.x, newY + hitBox.y - hitBox.height / 2f) != null || world.CheckObjectCollision(this, this.x + hitBox.x, newY + hitBox.y + hitBox.height / 2f) != null)) { newY += 1f; } break;
                                case Direction.LEFT: newX -= attackDist; while (newX < this.x && (!world.isAllPassable(newX + hitBox.x + hitBox.width / 2f, this.y + hitBox.y) || !world.isAllPassable(newX + hitBox.x - hitBox.width / 2f, this.y + hitBox.y) || world.CheckObjectCollision(this, newX + hitBox.x - hitBox.width / 2f, this.y + hitBox.y) != null || world.CheckObjectCollision(this, newX + hitBox.x + hitBox.width / 2f, this.y + hitBox.y) != null)) { newX += 1f; } break;
                            }
                            xVel = 0;
                            yVel = 0;
                            if (newX == this.x)
                            {
                                Go.to(this, attackTime / 2f, new TweenConfig().floatProp("x", -attackDisp, true).setEaseType(EaseType.QuadOut).setIterations(2, LoopType.PingPong));
                                Go.to(this, attackTime, new TweenConfig().floatProp("y", newY).setEaseType(EaseType.BackInOut).onComplete(() => { }));

                            }
                            else
                            {
                                Go.to(this, attackTime / 2f, new TweenConfig().floatProp("y", attackDisp, true).setEaseType(EaseType.QuadOut).setIterations(2, LoopType.PingPong));
                                Go.to(this, attackTime, new TweenConfig().floatProp("x", newX).setEaseType(EaseType.BackInOut).onComplete(() => { }));

                            }
                            if (_direction == Direction.RIGHT)
                                scaleX = -1;
                            else if (_direction == Direction.LEFT)
                                scaleX = 1;
                            return;
                        case SecondaryItem.BOW:
                            SpawnDeathParticles(Direction.UP, 20);
                            State = PlayerState.BOW_DRAWN;
                            return;
                    }
                }
                if (C.getKey(C.LEFT_KEY))
                {

                    xAcc = -moveSpeed;
                    if (xVel > 0)
                    {

                        SpawnParticles((Direction)((int)(_direction + 2) % Enum.GetValues(typeof(Direction)).Length), 1);
                        xVel *= .8f;
                    }

                }
                else
                    if (C.getKey(C.RIGHT_KEY))
                    {

                        xAcc = moveSpeed;
                        if (xVel < 0)
                        {
                            SpawnParticles((Direction)((int)(_direction + 2) % Enum.GetValues(typeof(Direction)).Length), 1);
                            xVel *= .8f;
                        }

                    }
                    else
                        xVel *= .7f;
                if (C.getKey(C.UP_KEY))
                {
                    yAcc = moveSpeed;
                    if (yVel < 0)
                    {

                        SpawnParticles((Direction)((int)(_direction + 2) % Enum.GetValues(typeof(Direction)).Length), 1);
                        yVel *= .8f;
                    }

                }
                else if (C.getKey(C.DOWN_KEY))
                {
                    yAcc = -moveSpeed;
                    if (yVel > 0)
                    {

                        SpawnParticles((Direction)((int)(_direction + 2) % Enum.GetValues(typeof(Direction)).Length), 1);
                        yVel *= .8f;
                    }
                }
                else
                    yVel *= .7f;

                break;
            case PlayerState.BOW_DRAWN:
                if (!C.getKey(C.ACTION_KEY))
                {
                    State = PlayerState.BOW_SHOOTING;
                    Arrow arrow = new Arrow(this, world);
                    arrow.SetDirection(CurrentDirection);
                    arrow.PlayAnim();
                    arrow.SetPosition(this.GetPosition());
                    switch (CurrentDirection)
                    {
                        case Direction.UP: arrow.yVel = 2; break;
                        case Direction.RIGHT: arrow.xVel = 2; break;
                        case Direction.DOWN: arrow.yVel = -2; break;
                        case Direction.LEFT: arrow.xVel = -2; break;
                    }
                    world.addObject(arrow);
                    return;
                }
                float strafeSpeed = 5f;
                if (C.getKey(C.LEFT_KEY))
                    xVel = -strafeSpeed;
                else if (C.getKey(C.RIGHT_KEY))
                    xVel = strafeSpeed;
                else xVel *= .8f;

                if (C.getKey(C.UP_KEY))
                    yVel = strafeSpeed;
                else if (C.getKey(C.DOWN_KEY))
                    yVel = -strafeSpeed;
                else yVel *= .8f;

                break;
            case PlayerState.BOW_SHOOTING:
                xVel *= .8f;
                yVel *= .8f;
                if (stateCount > .5f)
                {
                    State = PlayerState.IDLE;
                    SpawnDeathParticles(Direction.UP, 20);
                }
                break;
            case PlayerState.SWORD:
                shouldDamage = stateCount > .2f && stateCount < .4f;
                if (stateCount > .6f)
                    State = PlayerState.IDLE;
                else if (stateCount > .3f)
                {

                    if (C.getKey(C.ACTION_KEY) && !lastActionPress)
                    {
                        float attack2Time = .25f;
                        float attack2Dist = 20;
                        float attack2Disp = 5f;
                        State = PlayerState.SWORD_TWO;
                        FSoundManager.PlaySound("swordTwo");
                        hasSpawnedSpiritParticles = false;
                        if (C.getKey(C.RIGHT_KEY))
                            _direction = Direction.RIGHT;
                        else if (C.getKey(C.DOWN_KEY))
                            _direction = Direction.DOWN;
                        else if (C.getKey(C.LEFT_KEY))
                            _direction = Direction.LEFT;
                        else if (C.getKey(C.UP_KEY))
                            _direction = Direction.UP;
                        SpawnParticles((Direction)((int)(_direction + 2) % Enum.GetValues(typeof(Direction)).Length));

                        Go.killAllTweensWithTarget(this);
                        float newX = this.x;
                        float newY = this.y;
                        PlayAnim(true);
                        switch (_direction)
                        {
                            case Direction.UP: newY += attack2Dist; while (newY > this.y && (!world.isAllPassable(this.x + hitBox.x, newY + hitBox.y + hitBox.height / 2f) || !world.isAllPassable(this.x + hitBox.x, newY + hitBox.y - hitBox.height / 2f) || world.CheckObjectCollision(this, this.x + hitBox.x, newY + hitBox.y + hitBox.height / 2f) != null || world.CheckObjectCollision(this, this.x + hitBox.x, newY + hitBox.y - hitBox.height / 2f) != null)) { newY -= 1f; } break;
                            case Direction.RIGHT: newX += attack2Dist; while (newX > this.x && (!world.isAllPassable(newX + hitBox.x + hitBox.width / 2f, this.y + hitBox.y) || !world.isAllPassable(newX + hitBox.x - hitBox.width / 2f, this.y + hitBox.y) || world.CheckObjectCollision(this, newX + hitBox.x + hitBox.width / 2f, this.y + hitBox.y) != null || world.CheckObjectCollision(this, newX + hitBox.x - hitBox.width / 2f, this.y + hitBox.y) != null)) { newX -= 1f; } break;
                            case Direction.DOWN: newY -= attack2Dist; while (newY < this.y && (!world.isAllPassable(this.x + hitBox.x, newY + hitBox.y + hitBox.height / 2f) || !world.isAllPassable(this.x + hitBox.x, newY + hitBox.y - hitBox.height / 2f) || world.CheckObjectCollision(this, this.x + hitBox.x, newY + hitBox.y - hitBox.height / 2f) != null || world.CheckObjectCollision(this, this.x + hitBox.x, newY + hitBox.y + hitBox.height / 2f) != null)) { newY += 1f; } break;
                            case Direction.LEFT: newX -= attack2Dist; while (newX < this.x && (!world.isAllPassable(newX + hitBox.x + hitBox.width / 2f, this.y + hitBox.y) || !world.isAllPassable(newX + hitBox.x - hitBox.width / 2f, this.y + hitBox.y) || world.CheckObjectCollision(this, newX + hitBox.x - hitBox.width / 2f, this.y + hitBox.y) != null || world.CheckObjectCollision(this, newX + hitBox.x + hitBox.width / 2f, this.y + hitBox.y) != null)) { newX += 1f; } break;
                        }
                        xVel = 0;
                        yVel = 0;
                        Go.killAllTweensWithTarget(this);
                        if (newX == this.x)
                        {
                            Go.to(this, attack2Time / 2f, new TweenConfig().floatProp("x", -attack2Disp, true).setEaseType(EaseType.QuadOut).setIterations(2, LoopType.PingPong));
                            Go.to(this, attack2Time, new TweenConfig().floatProp("y", newY).setEaseType(EaseType.BackInOut).onComplete(() => { }));

                        }
                        else
                        {
                            Go.to(this, attack2Time / 2f, new TweenConfig().floatProp("y", attack2Disp, true).setEaseType(EaseType.QuadOut).setIterations(2, LoopType.PingPong));
                            Go.to(this, attack2Time, new TweenConfig().floatProp("x", newX).setEaseType(EaseType.BackInOut).onComplete(() => { }));

                        }
                        if (_direction == Direction.RIGHT)
                            scaleX = -1;
                        else if (_direction == Direction.LEFT)
                            scaleX = 1;
                        return;
                    }
                }
                else if (stateCount > .25f)
                {
                    if (!hasSpawnedSpiritParticles)
                    {
                        SpawnParticles(_direction);
                        hasSpawnedSpiritParticles = true;
                    }
                }

                break;
            case PlayerState.SWORD_TWO:
                shouldDamage = stateCount > .2f;
                if (stateCount > .6f)
                    State = PlayerState.IDLE;
                else if (stateCount > .19f)
                    if (!hasSpawnedSpiritParticles)
                    {
                        SpawnParticles(_direction, 30);
                        hasSpawnedSpiritParticles = true;
                    }
                break;
            case PlayerState.INVULNERABLE:
                if (RXRandom.Float() < .2f)
                    SpawnParticles(Direction.UP, 1);
                this.isVisible = stateCount * 100 % 10 < 5;
                if (stateCount > invulnerableStunTime)
                {
                    State = PlayerState.IDLE;

                    maxXVel = 1;
                    maxYVel = 1;
                    minYVel = -1;
                    this.isVisible = true;
                }
                this.xVel *= .9f;
                this.yVel *= .9f;

                break;
            case PlayerState.DYING:
                if (!hasSpawnedSpiritParticles)
                {

                    if (RXRandom.Float() < .4f + .4f * stateCount)
                        SpawnDeathParticles(Direction.UP, 1 + (int)stateCount);
                    if (stateCount > invulnerableStunTime * 3)
                    {
                        FSoundManager.PlaySound("death");
                        C.getCameraInstance().shake(1.0f, .5f);
                        SpawnDeathParticles(Direction.UP, 20);
                        this.isVisible = false;
                        hasSpawnedSpiritParticles = true;
                    }
                    else
                        this.isVisible = stateCount * 100 % 10 < 5;
                }
                if (stateCount > invulnerableStunTime * 5)
                {
                    world.Respawn();

                    maxXVel = 1;
                    maxYVel = 1;
                    minYVel = -1;
                }
                this.xVel *= .9f;
                this.yVel *= .9f;
                break;

        }

        if (xAcc != 0 || yAcc != 0)
        {
            switch (State)
            {
                case PlayerState.IDLE:
                    {
                        State = PlayerState.MOVE;
                    }
                    break;
            }
        }
        else
        {
            switch (State)
            {
                case PlayerState.MOVE:
                    State = PlayerState.IDLE;
                    break;
            }
        }

        base.OnFixedUpdate();
        if (stateCount == 0 && State == PlayerState.MOVE)

            SpawnParticles((Direction)((int)(_direction + 2) % Enum.GetValues(typeof(Direction)).Length), 1);
        lastActionPress = C.getKey(C.ACTION_KEY);
        lastSelectPress = C.getKey(C.SELECT_KEY);
        lastJumpPress = C.getKey(C.JUMP_KEY);
        PlayAnim();
    }