public static DJ_Dir GetPreferredDirection(DJ_Point from, DJ_Point to) { DJ_Dir direction = DJ_Dir.NONE; float dx = to.X - from.X; float dy = to.Y - from.Y; if (Mathf.Abs(dx) > Mathf.Abs(dy)) { if (dx < 0) { direction = DJ_Dir.LEFT; } if (dx > 0) { direction = DJ_Dir.RIGHT; } } else { if (dy < 0) { direction = DJ_Dir.UP; } if (dy > 0) { direction = DJ_Dir.DOWN; } } return(direction); }
void Awake() { inputDir = DJ_Dir.NONE; currentMouse = new Vector2(0, 0); currLevel = DJ_LevelManager.currentLevel; onInput = false; tapTimer = 0.0f; prevMouseDown = false; mouseDown = false; prevKeyDown = false; keyDown = false; }
public void Reset() { elapsedDeathTime = 0.0f; isLerping = false; justLanded = false; playerHeight = 0.0f; isFalling = false; currAnimationTime = 0.0f; direction = DJ_Dir.NONE; prevCanMove = false; canMove = true; maxMoveDistance = 1; direction = DJ_Dir.NONE; //deathTimeCounter++; }
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; } }
void Update() { tapTimer += Time.deltaTime; onInput = false; inputDir = DJ_Dir.NONE; UpdateKeyboardAndMouseDown(); bool test = OnLevelSelect(); if (ValidInputToMove()) { // VITAL for pausing to work properly if (test) { } // VITAL for pausing to work properly else if (inPauseMenu()) { } // VITAL for score screen to work properly else if (inScoreScreen()) { } else { checkScreen(); checkKeys(); } } checkResetRoom(); //set the input of the movement GetComponent <DJ_Movement>().direction = inputDir; prevMouseDown = mouseDown; prevKeyDown = keyDown; }
//Checks the WASD keys for which direction to move public void checkKeys() { if (Input.GetKeyDown("a")) //right { inputDir = DJ_Dir.RIGHT; onInput = true; } if (Input.GetKeyDown("d")) //left { inputDir = DJ_Dir.LEFT; onInput = true; } if (Input.GetKeyDown("w")) //up { inputDir = DJ_Dir.UP; onInput = true; } if (Input.GetKeyDown("s")) //down { inputDir = DJ_Dir.DOWN; onInput = true; } }
public static DJ_Dir GetOppositeDirection(DJ_Dir dir) { if (dir == DJ_Dir.LEFT) { return(DJ_Dir.RIGHT); } if (dir == DJ_Dir.RIGHT) { return(DJ_Dir.LEFT); } if (dir == DJ_Dir.UP) { return(DJ_Dir.DOWN); } if (dir == DJ_Dir.DOWN) { return(DJ_Dir.UP); } return(DJ_Dir.NONE); }
/// <summary> /// Checks what quarter of the screen has been touched or clicked /// </summary> public void checkScreen() { //if(prevMouseDown || Input.GetMouseButton(0)) //if (mousedown { //currentMouse.x = Input.mousePosition.x; currentMouse = new Vector2(Input.mousePosition.x, Input.mousePosition.y); //get the quadrant the mouse/touch was int area = GetAreaFromPosition(currentMouse); //now based off of the area the mouse pos/touch was on the screen, //set the direction of the player if (area == 0) { inputDir = DJ_Dir.UP; } else if (area == 1) { inputDir = DJ_Dir.RIGHT; } else if (area == 2) { inputDir = DJ_Dir.DOWN; } else if (area == 3) { inputDir = DJ_Dir.LEFT; } if (area != -1) { onInput = true; } } }
private bool GetNextMove(DJ_Point from, DJ_Point to, float currDist, float maxDist, DJ_Distance distanceType, float currentCost) { if (from.Equals(to)) { return(true); } if (!tileMap.ContainsKey(to) && DJ_Util.GetDistance(from, to, DJ_Distance.EUCLIDEAN) <= 1) { return(false); } if (currDist > maxDist) { return(true); } if (tileMap.ContainsKey(from)) { DJ_Dir prefDir = DJ_Util.GetPreferredDirection(from, to); int index; //immediately return none if the preferred direction //happens to be none. This either means the positions, from //and to, are the same or that there is no path from "from" to "to" if (prefDir == DJ_Dir.NONE) { return(true); } if (tileMap[from].neighbors[(int)prefDir] != null && DJ_LevelManager.isTileAvailable(tileMap[from].neighbors[(int)prefDir].pos)) { if (!tilesVisited.Contains(tileMap[from].neighbors[(int)prefDir].pos)) { tilesVisited.Add(tileMap[from].neighbors[(int)prefDir].pos); currentCosts.Add(currentCost); } else { index = tilesVisited.IndexOf(tileMap[from].neighbors[(int)prefDir].pos); float currCost = currentCosts[index]; if (currentCost < currCost) { tilesVisited.RemoveAt(index); currentCosts.RemoveAt(index); tilesVisited.Add(tileMap[from].neighbors[(int)prefDir].pos); currentCosts.Add(currentCost); } else { return(false); } } if (GetNextMove(tileMap[from].neighbors[(int)prefDir].pos, to, currDist + 1.0f, maxDist, distanceType, currentCost + 1.0f)) { return(true); } index = tilesVisited.IndexOf(tileMap[from].neighbors[(int)prefDir].pos); currentCosts.RemoveAt(index); tilesVisited.Remove(tileMap[from].neighbors[(int)prefDir].pos); } for (int i = 0; i < tileMap[from].neighbors.Length; ++i) { if (tileMap[from].neighbors[i] != null && i != (int)prefDir && DJ_LevelManager.isTileAvailable(tileMap[from].neighbors[i].pos)) { tilesVisited.Add(tileMap[from].neighbors[i].pos); currentCosts.Add(currentCost); if (GetNextMove(tileMap[from].neighbors[i].pos, to, currDist + 1.0f, maxDist, distanceType, currentCost + 1.0f)) { return(true); } index = tilesVisited.IndexOf(tileMap[from].neighbors[i].pos); currentCosts.RemoveAt(index); tilesVisited.Remove(tileMap[from].neighbors[i].pos); } } } return(false); }
public DJ_Dir GetNextMove(DJ_Point from, DJ_Point to, float maxDist, DJ_Distance distanceType) { tilesVisited.Clear(); currentCosts.Clear(); tilesVisited.Add(from); currentCosts.Add(0.0f); if (tileMap.ContainsKey(from)) { DJ_Dir prefDir = DJ_Util.GetPreferredDirection(from, to); float currentCost = 0.0f; //immediately return none if the preferred direction //happens to be none. This either means the positions, from //and to, are the same or that there is no path from "from" to "to" if (prefDir == DJ_Dir.NONE) { return(prefDir); } //Debug.Log("the preferred direction is " + prefDir.ToString()); int index; if (tileMap[from].neighbors[(int)prefDir] != null && DJ_LevelManager.isTileAvailable(tileMap[from].neighbors[(int)prefDir].pos)) { //push info onto queue tilesVisited.Add(tileMap[from].neighbors[(int)prefDir].pos); currentCosts.Add(currentCost); if (GetNextMove(tileMap[from].neighbors[(int)prefDir].pos, to, 0.0f, maxDist, distanceType, currentCost + 1.0f)) { return(prefDir); } //remove info from queue index = tilesVisited.IndexOf(tileMap[from].neighbors[(int)prefDir].pos); currentCosts.RemoveAt(index); tilesVisited.Remove(tileMap[from].neighbors[(int)prefDir].pos); } for (int i = 0; i < tileMap[from].neighbors.Length; ++i) { if (tileMap[from].neighbors[i] != null && i != (int)prefDir && DJ_LevelManager.isTileAvailable(tileMap[from].neighbors[i].pos)) { tilesVisited.Add(tileMap[from].neighbors[i].pos); currentCosts.Add(currentCost); if (GetNextMove(tileMap[from].neighbors[i].pos, to, 0.0f, maxDist, distanceType, currentCost + 1.0f)) { return(DJ_Util.GetPreferredDirection(from, tileMap[from].neighbors[i].pos)); } index = tilesVisited.IndexOf(tileMap[from].neighbors[i].pos); currentCosts.RemoveAt(index); tilesVisited.Remove(tileMap[from].neighbors[i].pos); } } } return(DJ_Dir.NONE); }
public static void GetNeighboringTilePos(DJ_Point currTilePos, DJ_Dir direction, DJ_Point targetTilePos) { GetNeighboringTilePos(currTilePos, direction, 1, targetTilePos); }
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; } }