示例#1
0
    IEnumerator finishAttack(SpriteDir d)
    {
        yield return new WaitForSeconds(0.23f);

        // restore link's animation state
        switch(d){
            case SpriteDir.UP:
            case SpriteDir.UP_STEP:
                    sprRend.sprite = spr[10];
                    break;
            case SpriteDir.DOWN:
            case SpriteDir.DOWN_STEP:
                    sprRend.sprite = spr[8];
                    break;
            case SpriteDir.RIGHT:
            case SpriteDir.RIGHT_STEP:
                    sprRend.sprite = spr[11];
                    break;
            case SpriteDir.LEFT:
            case SpriteDir.LEFT_STEP:
                    sprRend.sprite = spr[1];
                    break;
        }

        isAttacking = false;
        Destroy(woodenSword);
    }
示例#2
0
 public static EventTPPlayer c(Vector2 teleportTo, SpriteDir facingDir = SpriteDir.None, NPC npc = NPC.Pom)
 {
     return(new EventTPPlayer()
     {
         TeleportPosition = teleportTo, facingDirection = facingDir, npc = npc
     });
 }
示例#3
0
 public static EventSetFacing c(NPC npc, SpriteDir direction)
 {
     return(new EventSetFacing()
     {
         npc = npc, dir = direction
     });
 }
示例#4
0
    public bool CanMove(SpriteDir direction)
    {
        if (!AllowMovement)
        {
            return(false);
        }

        return(CanMoveRayhit(direction).collider == null);
    }
示例#5
0
    public void SetFacingDirection(SpriteDir direction)
    {
        if (facingDir == direction)
        {
            return;
        }

        facingDir = direction;
        anim.SetSprite(direction, 0);
    }
示例#6
0
    public void TeleToPomWithOffset(Vector3 vec)
    {
        controller.ResetMovement();

        controller.transform.position = Player.playerInstance.transform.position + vec;
        controller.SetFacingDirection(Player.playerInstance.facingDir);

        lastTargetPos     = Player.playerInstance.transform.position;
        lastTargetFacing  = Player.playerInstance.facingDir;
        lastStandingStill = Player.playerInstance.standingStill;
    }
示例#7
0
    public RaycastHit2D CanMoveRayhit(SpriteDir direction)
    {
        var moveDir = VectorFromSpriteDir(direction);

        var pos  = transform.position + new Vector3(0f, -.5f, 0f);
        var dist = 1f;

        var rayHit = Physics2D.Raycast(pos, moveDir, dist);

        Debug.DrawRay(pos, moveDir * dist, Color.red, .1f);

        return(rayHit);
    }
示例#8
0
    public Vector2 VectorFromSpriteDir(SpriteDir dir)
    {
        switch (dir)
        {
        case SpriteDir.Left: return(new Vector2(-1f, 0f));

        case SpriteDir.Right: return(new Vector2(1f, 0f));

        case SpriteDir.Up: return(new Vector2(0f, 1f));

        case SpriteDir.Down: return(new Vector2(0f, -1f));

        default: return(Vector2.zero);
        }
    }
示例#9
0
    public Sprite SpriteFromDir(SpriteDir dir, int step = 0)
    {
        if (step > 2 || step < 0)
        {
            step = 0;
        }

        var sprite = SpriteFromIndex(3 * (int)dir + step);

        //default to the still sprite if no steps are set
        if (sprite == null)
        {
            sprite = SpriteFromIndex(3 * (int)dir);
        }

        return(sprite);
    }
示例#10
0
    public bool TryMove(SpriteDir direction, bool alertHitOfBump)
    {
        if (!AllowMovement || moveTimeout > 0f)
        {
            return(false);
        }

        var rayHit = CanMoveRayhit(direction);

        SetFacingDirection(direction);
        if (rayHit.collider != null)
        {
            if (alertHitOfBump)
            {
                if (gameObject != Player.playerInstance.gameObject)
                {
                    if (rayHit.collider.transform.parent.gameObject == Player.playerInstance.gameObject)
                    {
                        //send message to self if we're not the player and we just bumped into the player
                        gameObject.SendMessage("Bumped", Player.playerInstance.gameObject, SendMessageOptions.DontRequireReceiver);
                    }
                }
                else
                {
                    rayHit.collider.gameObject.SendMessage("Bumped", gameObject, SendMessageOptions.DontRequireReceiver);
                }
            }

            //I forget why I added this, but it was breaking bump events so..
            //StallMovement ();
            return(false);
        }
        else
        {
            ForceMove(VectorFromSpriteDir(direction));
            return(true);
        }
    }
示例#11
0
 public void SetSprite(SpriteDir dir, int step = 0)
 {
     spriteRenderer.sprite = SpriteFromDir(dir, step);
 }
示例#12
0
    SpriteDir handleStep(SpriteDir theDir)
    {
        Vector3 dtPos = previousPos - transform.position;
        distSinceLastStep += new Vector2(Mathf.Abs(dtPos.x), Mathf.Abs(dtPos.y));

        if(distSinceLastStep.x >= DIST_BTW_STEPS || distSinceLastStep.y >= DIST_BTW_STEPS){
            isRightFootForward = !isRightFootForward;
            distSinceLastStep = Vector2.zero;
        }

        if(isRightFootForward){
            return theDir+1;
        }
        else {
            return theDir;
        }
    }
示例#13
0
    float getNearestVerticalGridLine(float xpos, SpriteDir currentDir)
    {
        float closestRight = topLeftX + 0.5f + 50;
        float closestLeft = topLeftX - 2;

        while(closestRight >= xpos){
            closestRight --;
        }
        closestRight ++;

        while(closestLeft <= xpos) {
            closestLeft ++;
        }
        closestLeft --;

        float closestLeftDiff = Mathf.Abs(closestLeft - xpos);
        float closestRightDiff = Mathf.Abs(closestRight - xpos);

        if(closestLeftDiff < closestRightDiff) return closestLeftDiff;
        else if(closestRightDiff <= closestLeftDiff) return -closestRightDiff;

        return 0;
    }
示例#14
0
    float getNearestHorizontalGridLine(float ypos, SpriteDir currentDir)
    {
        float closestUp = topLeftY + 20 + 0.5f;
        float closestDown = topLeftY - 50;

        while(closestUp >= ypos){
            closestUp --;
        }
        closestUp ++;

        while(closestDown <= ypos){
            closestDown ++;
        }
        closestDown --;

        float closestUpDiff = Mathf.Abs(closestUp - ypos);
        float closestDownDiff = Mathf.Abs(closestDown - ypos);

        if(closestUpDiff < closestDownDiff) return closestUpDiff;
        else if(closestDownDiff <= closestUpDiff) return -closestDownDiff;

        return 0;
    }
示例#15
0
    // Update is called once per frame
    void Update()
    {
        if (ignoreForFrame)
        {
            ignoreForFrame = false;
        }
        if (Global.FocusJustChanged)
        {
            ignoreForFrame = true; Global.FocusJustChanged = false;
        }

        var curTouches      = Input.touches;
        var curMouse        = ScreenToPercentage(Input.mousePosition);
        var curMousePressed = Input.GetMouseButton(0) || //left click
                              Input.GetMouseButton(1);   //right click

        if (curMousePressed && !lastMousePressed)
        {
            startClick = curMouse;
        }

        Vector2 averageRightTouchPos = Vector2.zero;
        float   rightTouches         = 0f;

        //sort touches
        foreach (var touch in curTouches)
        {
            var percentage = ScreenToPercentage(touch.position);
            if (percentage.x > 0)
            {
                if (touch.phase != TouchPhase.Ended)
                {
                    rightTouches++;
                    averageRightTouchPos += percentage;
                }
            }
            else
            {
                if (lastMoveTouch == null && touch.phase == TouchPhase.Began)
                {
                    startClick    = percentage;
                    lastMoveTouch = touch;
                }
                else if (touch.fingerId == lastMoveTouch.Value.fingerId)
                {
                    lastMoveTouch = touch;

                    if (touch.phase == TouchPhase.Canceled || touch.phase == TouchPhase.Ended)
                    {
                        lastMoveTouch = null;
                    }
                }
            }
        }

        //TODO: Re-look at all the touch stuff, it seems to be fairly glitchy.
        //look up how people normally do it

        if (Input.touchCount == 0)
        {
            lastMoveTouch = null;
        }

        if (rightTouches > 0)
        {
            curMouse        = averageRightTouchPos / rightTouches;
            curMousePressed = true;
        }

        SpriteDir dirPressed      = SpriteDir.None;
        Vector2?  diff            = null;
        var       minMoveDistance = .1f;

        if (curMousePressed && lastMousePressed && startClick.x < 0)
        {
            diff = curMouse - startClick;
        }
        else if (lastMoveTouch != null)
        {
            diff = ScreenToPercentage(lastMoveTouch.Value.position) - startClick;
        }

        if (diff != null && diff.Value.magnitude > minMoveDistance)
        {
            var absPercentages = new Vector2(Mathf.Abs(diff.Value.x), Mathf.Abs(diff.Value.y));

            if (absPercentages.x > absPercentages.y)
            {
                if (diff.Value.x > 0f)
                {
                    dirPressed = SpriteDir.Right;
                }
                else
                {
                    dirPressed = SpriteDir.Left;
                }
            }
            else
            {
                if (diff.Value.y > 0f)
                {
                    dirPressed = SpriteDir.Up;
                }
                else
                {
                    dirPressed = SpriteDir.Down;
                }
            }
        }

        var maxCount = (int)Action.COUNT;

        for (int i = 0; i < maxCount; i++)
        {
            var lastDown = curIsDown[i];
            var curDown  = false;

            switch ((Action)i)
            {
            case Action.Cancel:
                curDown = Input.GetKey(KeyCode.Escape) ||
                          Input.GetKey(KeyCode.X) ||
                          Input.GetKey(KeyCode.Backspace) ||
                          (curMousePressed && !lastMousePressed && curMouse.x > 0 && curMouse.y > 0);
                break;

            case Action.Confirm:
                curDown = Input.GetKey(KeyCode.Return) ||
                          Input.GetKey(KeyCode.Z) ||
                          Input.GetKey(KeyCode.Space) ||
                          (curMousePressed && !lastMousePressed && curMouse.x > 0 && curMouse.y < 0);
                break;

            case Action.Up:
                curDown = Input.GetKey(KeyCode.UpArrow) ||
                          Input.GetKey(KeyCode.W) ||
                          dirPressed == SpriteDir.Up;
                break;

            case Action.Down:
                curDown = Input.GetKey(KeyCode.DownArrow) ||
                          Input.GetKey(KeyCode.S) ||
                          dirPressed == SpriteDir.Down;
                break;

            case Action.Left:
                curDown = Input.GetKey(KeyCode.LeftArrow) ||
                          Input.GetKey(KeyCode.A) ||
                          dirPressed == SpriteDir.Left;
                break;

            case Action.Right:
                curDown = Input.GetKey(KeyCode.RightArrow) ||
                          Input.GetKey(KeyCode.D) ||
                          dirPressed == SpriteDir.Right;
                break;

            case Action.Any:
                curDown = Input.anyKey || Input.touchCount > 0;
                break;

            case Action.DEBUG_SaveState:
                curDown = Input.GetKey(KeyCode.PageUp);
                break;
            }

            curIsDown[i]      = curDown;
            curJustPressed[i] = !lastDown && curDown;
        }

        lastTouches      = curTouches;
        lastMousePos     = curMouse;
        lastMousePressed = curMousePressed;
    }
示例#16
0
    void Update()
    {
        NPCController follower = null;

        if (Global.s.ExtraParkPartyMember == 1)
        {
            follower = NPCList.GetNPC(NPC.Hus);
        }
        else if (Global.s.ExtraParkPartyMember == 2)
        {
            follower = NPCList.GetNPC(NPC.Chi);
        }

        var distance = Vector2.Distance(transform.position, Player.playerInstance.transform.position);

        if (Global.s.ShibeInParty > 0 && Global.s.ShibeAbleToFollow > 0 && controller.standingStill)
        {
            if (distance < 5)
            {
                var beforeFacing = controller.facingDir;
                var dir          = controller.DirFromVector(lastTargetPos - transform.position);
                controller.TryMove(dir, false);

                if (controller.standingStill || Player.playerInstance.standingStill)
                {
                    controller.SetFacingDirection(beforeFacing);
                }
                else if (follower != null && !controller.standingStill)
                {
                    var followerDir = transform.position - follower.transform.position;

                    if (followerDir.magnitude < 5)
                    {
                        follower.SetFacingDirection(follower.DirFromVector(followerDir));
                        follower.ForceMove(followerDir);
                    }
                    else
                    {
                        follower.transform.position = transform.position;
                    }
                }
            }
            else
            {
                //distance is >= 5 tiles, teleport
                if (!Player.playerInstance.standingStill)
                {
                    controller.SetFacingDirection(lastTargetFacing);
                    transform.position = lastTargetPos;
                    if (follower != null)
                    {
                        follower.transform.position = transform.position;
                    }
                }
            }
        }

        if (Global.s.ShibeInParty > 0 && Global.s.ShibeAbleToFollow > 0 && (!Player.playerInstance.standingStill || !lastStandingStill) && distance <= 2.1f)
        {
            var movePercentage = Player.playerInstance.movePercentage;

            if (movePercentage < 1f)
            {
                var pos = Vector3.Lerp(transform.position, controller.boxCollider.transform.position, movePercentage);

                //snap to the 16 pixel grid
                controller.anim.transform.position = new Vector3(((int)(pos.x * 16) / 16f), ((int)(pos.y * 16) / 16f), controller.anim.transform.position.z);

                if (follower != null)
                {
                    var followerPos = Vector3.Lerp(follower.transform.position, follower.boxCollider.transform.position, movePercentage);
                    follower.anim.transform.position = new Vector3(((int)(followerPos.x * 16) / 16f), ((int)(followerPos.y * 16) / 16f), follower.anim.transform.position.z);
                }
            }
            else
            {
                movePercentage     = 1f;
                transform.position = controller.boxCollider.transform.position;
                controller.boxCollider.transform.localPosition = Vector3.zero;
                controller.anim.transform.localPosition        = Vector3.zero;
                controller.standingStill = true;
                controller.stoppedOnTile = true;

                if (follower != null)
                {
                    movePercentage = 1f;
                    follower.transform.position = follower.boxCollider.transform.position;
                    follower.boxCollider.transform.localPosition = Vector3.zero;
                    follower.anim.transform.localPosition        = Vector3.zero;
                    follower.standingStill = true;
                    follower.stoppedOnTile = true;
                }
            }
        }

        Debug.DrawLine(lastTargetPos, lastTargetPos + Vector3.up + Vector3.right);
        lastTargetPos     = Player.playerInstance.transform.position;
        lastTargetFacing  = Player.playerInstance.facingDir;
        lastStandingStill = Player.playerInstance.standingStill;
    }
示例#17
0
    public void changeRoom(SpriteDir dir)
    {
        float newRoomX = 0;
        float newRoomY = 0;

        switch(dir){
            case SpriteDir.UP:
                if(roomPos == 2 || roomPos == 3){
                    roomPos -= 2;
                }
                else {
                    roomPos -= 3;
                }

                newRoomY = 9f;

                break;
            case SpriteDir.DOWN:
                if(roomPos == 0 || roomPos == 1){
                    roomPos += 2;
                }
                else {
                    roomPos += 3;
                }

                newRoomY = -13;

                break;
            case SpriteDir.RIGHT:
                ++roomPos;

                newRoomY = -2;
                newRoomX = 16;

                break;
            case SpriteDir.LEFT:
                --roomPos;

                newRoomY = -2;
                newRoomX = -16;

                break;
            case SpriteDir.DOWN_STEP:		// from stairs room8
                roomPos = 1;
                newRoomY = -2;
                break;
            case SpriteDir.UP_STEP:			// from stairs room1
                roomPos = 8;
                newRoomY = -2;
                break;
            case SpriteDir.RIGHT_STEP:		// from stairs room3 (boss --> triforce)
                roomPos = 9;
                newRoomY = -2;
                break;
        }

        if(roomPos != 9){
            string tmp = "hudRoom" + roomPos;
            GameObject.Find("hudlocation").transform.position = GameObject.Find(tmp).transform.position;
        }
        else {
            // TODO: hide HUD??
        }

        if(isAnimating){
            return;
        }
        isAnimating = true;

        // delete items
        Utils.that.deleteItems();

        // delete enemies
        deleteEnemies();

        // disable link
        linkGM.gameObject.SetActive(false);

        // swap rooms
        nextRoom = DungeonRooms.that.getRoom(roomPos, new Vector2(newRoomX, newRoomY));

        theDir = dir;

        if(dir == SpriteDir.DOWN_STEP || dir == SpriteDir.UP_STEP || dir == SpriteDir.RIGHT_STEP){
            numDone = 2;
            done();
        }
        else {
            if(dir == SpriteDir.DOWN){
                StartCoroutine(Utils.that.MoveToPosition(curRoom.transform, new Vector3(0, 9), 1.8f, done));
            }
            else if(dir == SpriteDir.UP){
                StartCoroutine(Utils.that.MoveToPosition(curRoom.transform, new Vector3(0, -13f), 1.8f, done));
            }
            else {
                StartCoroutine(Utils.that.MoveToPosition(curRoom.transform, new Vector3(-newRoomX, -2), 1.8f, done));
            }

            StartCoroutine(Utils.that.MoveToPosition(nextRoom.transform, new Vector3(0, -2), 1.8f, done));
        }
    }