예제 #1
0
 public TileNode(DJ_Point tilePos, ref GameObject tile)
 {
     neighbors = new TileNode[4];
     pos       = new DJ_Point(0, 0);
     pos.Set(tilePos);
     this.tile = tile;
 }
예제 #2
0
 public static void GetNeighboringTilePos(DJ_Point currTilePos, DJ_Dir direction, int dist, DJ_Point targetTilePos)
 {
     targetTilePos.Set(currTilePos);
     if (direction == DJ_Dir.DOWN)
     {
         targetTilePos.Y += dist;
     }
     else if (direction == DJ_Dir.UP)
     {
         targetTilePos.Y += -dist;
     }
     else if (direction == DJ_Dir.LEFT)
     {
         targetTilePos.X += -dist;
     }
     else if (direction == DJ_Dir.RIGHT)
     {
         targetTilePos.X += dist;
     }
 }
예제 #3
0
    public void Update()
    {
        //TODO: Peter's Temp fix
        //animationLength = 0.5f * .75f;
//		animationLength = DJ_BeatManager.metronome.GetInterval() * .75f;

        //update the current animation time
        currAnimationTime += Time.deltaTime;

        //save the current position of the GO so that we  can
        //modify it and  set the transform.position equal to
        //the  modified position
        currentPosition = transform.position;
        // sets the previous move
        prevCanMove = canMove;

        DJ_Util.GetTilePos(currentPosition, currentTilePos);
        //playerHeight = currentPosition.y;

        // Checks to see if the player should be falling
        checkFalling();

        // If true, activate falling to death
        if (isFalling)
        {
            fallingScript();
        }
        if (DJ_PlayerManager.player.GetComponent <DJ_Damageable>().isAlive)
        {
            // If the entity can move then apply a lerp based on the direction.
            if (canMove)
            {
                justLanded = false;
                if (direction != DJ_Dir.NONE)
                {
                    if (direction == DJ_Dir.TP)
                    {
                        isLerping = true;
                        canMove   = false;
                        prevPrevTilePos.Set(prevTilePos);
                        direction = DJ_Dir.NONE;
                    }
                    else
                    {
                        isLerping     = true;
                        prevDirection = direction;
                        canMove       = false;
                        prevPrevTilePos.Set(prevTilePos);
                        prevTilePos.Set(currentTilePos);
                        DJ_Util.GetNeighboringTilePos(prevTilePos, direction, maxMoveDistance, targetTilePos);
                    }
                }
                currAnimationTime = 0.0f;
            }
            if (currAnimationTime > animationLength)
            {
                maxMoveDistance = 1;
                heightOfHop     = 1;
                canMove         = true;
                isLerping       = false;
                //direction = DJ_Dir.NONE;
                justLanded = true;
                //snap the position
                prevTilePos.Set(targetTilePos);

                // Only update the player's position in the playerPref if in the level select
                // Used to respawn in the correction position whenever they die or come back.

                if (Application.loadedLevelName.Equals("levelSelectStage") && DJ_TileManagerScript.tileMap.ContainsKey(targetTilePos))
                {
                    PlayerPrefs.SetInt("PlayerX", targetTilePos.X);
                    PlayerPrefs.SetInt("PlayerY", targetTilePos.Y);
                    //Debug.Log("Flush this to hash table");
                    //Debug.Log("Flush Player hash table = " + targetTilePos);
                    PlayerPrefs.Flush();
                }
            }

            //else
            {
                DJ_Util.LerpTrajectory(ref currentPosition, prevTilePos, targetTilePos,
                                       heightOfHop, currAnimationTime, animationLength, playerHeight);
            }
            switch (DJ_PlayerManager.player.GetComponent <DJ_Damageable>().deathBy)
            {
            case DJ_Death.NONE: transform.position = currentPosition;
                break;

            case DJ_Death.FALLING: transform.position = currentPosition;
                break;

            case DJ_Death.FLATTEN: transform.position = new Vector3(currentPosition.x, 0, currentPosition.z);
                break;

            case DJ_Death.ELECTROCUTED: transform.position = currentPosition;
                break;
            }

            //transform.position = currentPosition;
        }
        switch (DJ_PlayerManager.player.GetComponent <DJ_Damageable>().deathBy)
        {
        case DJ_Death.NONE: transform.position = currentPosition;
            break;

        case DJ_Death.FALLING: transform.position = currentPosition;
            break;

        case DJ_Death.FLATTEN: transform.position = new Vector3(currentPosition.x, 0, currentPosition.z);
            break;

        case DJ_Death.ELECTROCUTED: transform.position = currentPosition;
            break;
        }
    }