/* * SetDirection * the ai player is given access to the gamegrid to calculate it's next direction, they are also * given the users current direction so they can try to match it. */ public override void setDirection(Wall[,] matrix, Player.Direction userDirection) { // Set the users direction as the initially best one Player.Direction bestDirection = userDirection; int bestDistance = getDistance(userDirection, matrix); //Change direction only when the best direction is bad if (bestDistance <= threshold) { // Test all directions and set the best one Player.Direction nextDirection = Player.Direction.Up; int nextDistance = getDistance(nextDirection, matrix); if (nextDistance > bestDistance) bestDirection = nextDirection; nextDirection = Player.Direction.Right; nextDistance = getDistance(nextDirection, matrix); if (nextDistance > bestDistance) bestDirection = nextDirection; nextDirection = Player.Direction.Down; nextDistance = getDistance(nextDirection, matrix); if (nextDistance > bestDistance) bestDirection = nextDirection; nextDirection = Player.Direction.Left; nextDistance = getDistance(nextDirection, matrix); if (nextDistance > bestDistance) bestDirection = nextDirection; } // Change direction to the best one if close to hitting a wall if (getDistance(this.direction, matrix) <= threshold) this.direction = bestDirection; }
public bool isTileMoveable(Vector3 currentPlayerPosition, Player.Direction direction) { int x = (int)currentPlayerPosition.x; Debug.Log("Current X:" + x.ToString()); int z = (int)currentPlayerPosition.z; Debug.Log("Current X:" + z.ToString()); switch (direction) { case Player.Direction.up: Debug.Log(getTile(x, z + 1, currentMap).Walkable); return(getTile(x, z + 1, currentMap).Walkable); case Player.Direction.right: Debug.Log(getTile(x + 1, z, currentMap).Walkable); return(getTile(x + 1, z, currentMap).Walkable); case Player.Direction.down: Debug.Log(getTile(x, z + 1, currentMap).Walkable); return(getTile(x, z - 1, currentMap).Walkable); case Player.Direction.left: Debug.Log(getTile(x, z + 1, currentMap).Walkable); return(getTile(x - 1, z, currentMap).Walkable); default: return(false); } }
/// <summary> /// Checks on the Walls /// </summary> public void CheckWallDetection() { Up = map.HasHitWall(PacMan.HitBox); Down = map.HasHitWall(PacMan.HitBox); Left = map.HasHitWall(PacMan.HitBox); Right = map.HasHitWall(PacMan.HitBox); if (PacMan.WallCollision()) { if (LastInput == Player.Direction.Up) { LastInput = Player.Direction.Still; } else if (LastInput == Player.Direction.Down) { LastInput = Player.Direction.Still; } else if (LastInput == Player.Direction.Left) { LastInput = Player.Direction.Still; } else if (LastInput == Player.Direction.Right) { LastInput = Player.Direction.Still; } } }
public void ChangeDirection(Player.Direction changeTo) { if (changeTo == Player.Direction.SOUTH && facing_ == Player.Direction.NORTH) { return; } facing_ = changeTo; }
void UpdateDisplay() { if (!player.currentDirection.Equals (currentDir)) { currentDir = player.currentDirection; SetRenderer (currentDir); } }
/* * SetDirection * The user will ignore the information from the grid but use this method to change it's direction * Left has priority */ public override void setDirection(Wall[,] matrix, Player.Direction userDirection) { if (turnLeft) { turnCounterClockwise(); } else if (turnRight) { turnClockwise(); } turnLeft = false; turnRight = false; }
public Cell getFacingDirection(Player.Direction direction) { switch (direction) { case Player.Direction.Down: return(getDown()); case Player.Direction.Up: return(getUp()); case Player.Direction.Right: return(getForward()); } return(getReverse()); }
public ActiveSkills() { this.shieldGfx = null; this.shieldOnGround = false; this.player = null; this.rowFrame = 0; this.world = null; this.shieldTexture = null; this.shieldHP = 0; this.removeShield = false; this.shieldCooldown = 0; this.shieldActivate = false; this.direction = Player.Direction.Right; this.shieldDuration = 0; }
public void Win(Player.Direction winnerDir) { //Set the player win card to the correct texture this.nodeCardsPlayerWin.Visible = false; this.nodeCardsPlayerWin.Texture = winnerDir == Player.Direction.RIGHT ? p1Card : p2Card; //Gets node cards sprite set up correctly this.nodeCardsSprite.Modulate = new Color(255, 255, 255, 255); this.nodeCardsSprite.Playing = false; this.nodeCardsSprite.Animation = "default"; //Hide the rest of the HUD this.nodeGroupP1.Visible = false; this.nodeGroupP2.Visible = false; if (Command.IsMobile()) { this.nodeMobileControls.Visible = false; } this.nodeCardsPlayer.Play("win"); }
void Shoot(Player.Direction direction) { // Change animation animator.SetTrigger("is_Shooting"); // Create arrow Vector2 force = Vector2.zero; if (direction == Player.Direction.left) { force.x = -1; force.y = 0; fire_Point.rotation = Quaternion.Euler(0, 0, 90); } else if (direction == Player.Direction.right) { force.x = 1; force.y = 0; fire_Point.rotation = Quaternion.Euler(0, 0, 270); } else if (direction == Player.Direction.up) { force.x = 0; force.y = 1; fire_Point.rotation = Quaternion.Euler(0, 0, 0); } else if (direction == Player.Direction.down) { force.x = 0; force.y = -1; fire_Point.rotation = Quaternion.Euler(0, 0, 180); } GameObject arrow = Instantiate(arrow_Prefab, fire_Point.position, fire_Point.rotation); // Apply force to arrow Rigidbody2D rb = arrow.GetComponent <Rigidbody2D>(); rb.AddForce(force * arrow_Force, ForceMode2D.Impulse); }
// Gets the distance from this players location to the nearest wall in a driection private int getDistance(Player.Direction dir, Wall[,] matrix) { int distance = 0; if (dir == Player.Direction.Left) for (int i = this.x - 1; i >= 0; i--) { if (matrix[i, this.y] == null) distance++; else return distance; } else if (dir == Player.Direction.Right) for (int i = this.x + 1; i < matrix.GetLength(0); i++) { if (matrix[i, this.y] == null) distance++; else return distance; } else if (dir == Player.Direction.Up) for (int i = this.y - 1; i >= 0; i--) { if (matrix[this.x, i] == null) distance++; else return distance; } else if (dir == Player.Direction.Down) for (int i = this.y + 1; i < matrix.GetLength(0); i++) { if (matrix[this.x, i] == null) distance++; else return distance; } return distance; }
public void rotateSwitches(Player.Direction newDir) { for (int i = 0; i < SwitchList.Length; i++) { switch (newDir) { case Player.Direction.Up: SwitchList[i].transform.rotation = Quaternion.Euler(transform.rotation.x, 0, transform.rotation.z); break; case Player.Direction.Down: SwitchList[i].transform.rotation = Quaternion.Euler(transform.rotation.x, 180, transform.rotation.z); break; case Player.Direction.Left: SwitchList[i].transform.rotation = Quaternion.Euler(transform.rotation.x, 270, transform.rotation.z); break; case Player.Direction.Right: SwitchList[i].transform.rotation = Quaternion.Euler(transform.rotation.x, 90, transform.rotation.z); break; } } }
private void HasHitAWall(KeyEventArgs e) { if (!PacMan.IsDead()) { switch (e.KeyCode) { case Keys.Up: if (!Up) { LastInput = Player.Direction.Up; } break; case Keys.Down: if (!Down) { LastInput = (Player.Direction.Down); } break; case Keys.Left: if (!Left) { LastInput = (Player.Direction.Left); } break; case Keys.Right: if (!Right) { LastInput = (Player.Direction.Right); } break; } } }
public ActiveSkills(World world, Game1 game, Player player, Player.Direction direction) { this.shieldTexture = game.Content.Load<Texture2D>("Projectiles/Shield"); this.direction = direction; this.player = player; this.world = world; this.shieldHP = (int)((player.skillTree.playerInfo.playerHP / 10) * player.skillTree.ShieldPoint); this.shieldDuration += 2 * player.skillTree.ShieldPoint; this.shieldCooldown -= 4 * player.skillTree.ShieldCDPoint; shieldGfx = new DrawableGameObject(world, shieldTexture, new Vector2(shieldTexture.Width, shieldTexture.Height), 90, "shield"); if (direction == Player.Direction.Right) { shieldGfx.Position = new Vector2(player.torso.Position.X + shieldGfx.texture.Width * 1.5f, player.torso.Position.Y); } else { shieldGfx.Position = new Vector2(player.torso.Position.X - shieldGfx.texture.Width * 1.5f, player.torso.Position.Y); } shieldGfx.body.FixedRotation = true; shieldGfx.body.BodyType = BodyType.Dynamic; }
public PlayerPosition(Player.Direction direction) { this.direction = direction; }
// Update is called once per frame void Update() { // grounded = groundCheck.IsTouchingLayers (whatIsGround); // move = Input.GetAxis ("Horizontal"); // if (move > 0 && !facingRight) // { // Flip(); // } // else if (move < 0 && facingRight) // { // Flip(); // } // if (move != 0) { // animator.SetBool("isMoving", true); // } // else { // animator.SetBool("isMoving", false); // } if (currentCell != null && currentCell.name.StartsWith("exit")) { string scene = currentCell.name; SpawnPoint.SwitchToLevel(this.gameObject); GameState.SetPlayerDroplet(this.gameObject); currentCell = null; LoadScene(scene); //SceneManager.LoadScene(scene); } if (currentCell != null && !stillMoving) { int horizontal = 0; //Used to store the horizontal move direction. int vertical = 0; //Used to store the vertical move direction. //Check if we are running either in the Unity editor or in a standalone build. //Get input from the input manager, round it to an integer and store in horizontal to set x axis move direction horizontal = (int)(Input.GetAxisRaw("Horizontal")); //Get input from the input manager, round it to an integer and store in vertical to set y axis move direction vertical = (int)(Input.GetAxisRaw("Vertical")); // Debug.Log("H: " + horizontal + ", V: " + vertical); if (horizontal != 0) { vertical = 0; } if (horizontal != 0 || vertical != 0) { if (horizontal > 0) { // move forward lastDirection = Direction.Right; targetCell = currentCell.getForward(); } if (horizontal < 0) { // move backward lastDirection = Direction.Left; targetCell = currentCell.getReverse(); } if (vertical > 0) { // move up lastDirection = Direction.Up; targetCell = currentCell.getUp(); } if (vertical < 0) { // move down lastDirection = Direction.Down; targetCell = currentCell.getDown(); } //If Move returns true, meaning Player was able to move into an empty space. if (targetCell != null && targetCell.transform.GetChild(0).GetComponent <TileContent>().cellContent == null) { stillMoving = true; StartCoroutine(SmoothMovement(targetCell.transform.GetChild(0).transform.position)); // Move (targetCell.transform.GetChild(0).transform.position.x, targetCell.transform.GetChild(0).transform.position.y, out hit); } // search for cage if (currentCell != null && currentCell.getFacingDirection(lastDirection) != null && currentCell.getFacingDirection(lastDirection).transform.GetChild(0).GetComponent <TileContent>().cellContent != null) { Transform cellCage = getCage(targetCell.transform); Transform animal = getACagedAnimal(cellCage); if (animal != null) { cellCage.gameObject.GetComponent <Cage>().activateThought(animal.gameObject.name); } } } switch (horizontal) { case -1: this.GetComponent <SpriteRenderer>().sprite = left; this.GetComponent <SpriteRenderer>().flipX = false; break; case 1: this.GetComponent <SpriteRenderer>().sprite = left; this.GetComponent <SpriteRenderer>().flipX = true; break; } switch (vertical) { case 1: this.GetComponent <SpriteRenderer>().sprite = back; break; case -1: this.GetComponent <SpriteRenderer>().sprite = front; break; } } if (Input.GetKeyDown(KeyCode.Q)) { Debug.Log("Starting destroy all"); destroyAllAnimalsInCage(lastDirection); } if (Input.GetKeyDown(KeyCode.R)) { // manually reduce hearts Transform cage = findCage(currentCell.getFacingDirection(lastDirection).transform); Debug.Log("Cage is " + cage.transform.parent.gameObject.name); decrCageHeart(cage); } if (Input.GetKeyDown(KeyCode.F)) { //Debug.Log("Target cell name: " + targetCell.transform.GetChild(0).GetComponent<TileContent>().cellContent.GetComponent<SpriteRenderer>().sprite.name); // get one animal from cage removeAnimalFromCage(lastDirection); } if (Input.GetKeyDown(KeyCode.E)) { // pick up something if (targetCell != null && thingsBeingHeld < 6 && currentCell.getFacingDirection(lastDirection).transform.GetChild(0).GetComponent <TileContent>().cellContent != null) { // Transform[] items = GetComponentsInChildren<Transform>(); // pick up animal currentCell.getFacingDirection(lastDirection).transform.GetChild(0).GetComponent <TileContent>().cellContent.transform.parent = gameObject.transform; currentCell.getFacingDirection(lastDirection).transform.GetChild(0).GetComponent <TileContent>().cellContent.transform.localPosition = positionStack[thingsBeingHeld]; currentCell.getFacingDirection(lastDirection).transform.GetChild(0).GetComponent <TileContent>().cellContent = null; thingsBeingHeld++; } } if (Input.GetKeyDown(KeyCode.Space)) { // drop something Debug.Log("Dropping"); if (targetCell != null && thingsBeingHeld > 0 && currentCell != null && currentCell.getFacingDirection(lastDirection).transform.GetChild(0).GetComponent <TileContent>().cellContent == null) { Stack <Transform> stack = new Stack <Transform>(); // Transform[] items = GetComponentsInChildren<Transform>(); foreach (Transform tr in transform) { Debug.Log("Name: " + tr.name); stack.Push(tr); } Transform lastChild = stack.Pop(); currentCell.getFacingDirection(lastDirection).transform.GetChild(0).GetComponent <TileContent>().cellContent = lastChild.gameObject; currentCell.getFacingDirection(lastDirection).transform.GetChild(0).GetComponent <TileContent>().cellContent.transform.position = currentCell.getFacingDirection(lastDirection).transform.position; lastChild.parent = currentCell.getFacingDirection(lastDirection).transform; thingsBeingHeld--; } else { // for all other drops string targetItem = GetCellName(currentCell.getFacingDirection(lastDirection)); string currentItem = NameOfTopOfStack(); Debug.Log("Placing down something else: [" + currentItem + "] --> [" + targetItem + "]"); // wood + wood to make cage if (currentItem != null && currentItem == "wood") { if (targetItem != null) { if (targetItem == "wood") { // then make a cage Destroy(removeTopItem().gameObject); var gObj = (GameObject)Instantiate(Resources.Load("prefab/" + "cage"), GetComponent <Transform>().position, GetComponent <Transform>().rotation); placeItemInCell(lastDirection, gObj.transform); } } } // animals in cages if (currentItem != null && (currentItem == "hay" || currentItem == "rabbit" || currentItem == "chicken" || currentItem == "fox" || currentItem == "raptor" || currentItem == "unicorn")) { if (targetItem != null) { if (targetItem == "good_cage") { //placeItemInCell(lastDirection, removeTopItem()); addAnimalToCage(lastDirection); // parent the animal to the cage } } } } } // var dir = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), 0); // transform.position += dir * 5.0f * Time.deltaTime; //Debug.Log ("move = " + move); }
public void gotoNextStage(Player.Direction dir) { switch (dir) { case Player.Direction.EAST: nextSpawnDir = PlayerSpawnDir.SPAWN_WEST; break; case Player.Direction.WEST: nextSpawnDir = PlayerSpawnDir.SPAWN_EAST; break; case Player.Direction.SOUTH: nextSpawnDir = PlayerSpawnDir.SPAWN_NORTH; break; case Player.Direction.NORTH: nextSpawnDir = PlayerSpawnDir.SPAWN_SOUTH; break; } Hashtable data = new Hashtable(); data.Add("entrance", ((int)dir).ToString()); data.Add("hash", currentStageHash); data.Add("username", SystemInfo.deviceUniqueIdentifier); string strHostName = Dns.GetHostName(); IPHostEntry ipEntry = Dns.GetHostEntry(strHostName); IPAddress[] addr = ipEntry.AddressList; data.Add("ip", addr[addr.Length - 1].ToString()); Debug.Log("Send:"); foreach (string str in data.Keys) { Debug.Log(str + ": " + data[str]); } HTTP.Request req = new HTTP.Request("post", "http://143.248.139.70:8000/randomMapGenerator", data); req.Send((request) => { Hashtable result = request.response.Object; Debug.Log("Result"); foreach (string str in result.Keys) { Debug.Log(str + ": " + result[str]); if ((string)(result[str].ToString()) == "System.Collections.Hashtable") { Hashtable rr = result[str] as Hashtable; foreach (string strstr in rr.Keys) { Debug.Log(strstr + ": " + rr[strstr]); } } } if (result == null) { Debug.LogWarning("Could not parse JSON response!"); return; } else { // Receive String from server and generate room Hashtable hashmap = (Hashtable)JSON.JsonDecode(request.response.Text); BoardHolderClear(); BoardHolderInit(); generateMapAndPlayer(hashmap, nextSpawnDir); } }); }
IEnumerator movementCoroutine(Tile newTile) { //end coroutine of where do i go, and you have moved start it again from the new tile if (tileBelow.ONETIMETERRAIN) { tileBelow.TileDestroy(); } //Fan check needs to be at the top so whatever the new tile is, is treated normally if (newTile.FANTILE && newTile.FANON) { tileBelow = newTile; moving1 = true; yield return(new WaitForSeconds(.5f)); newTile = newTile.Destination; fanNoise.Play(); } if (newTile.DIRSWITCH && newTile.newDir != directionFacing) { directionFacing = newTile.newDir; //camera switching if (directionFacing == Player.Direction.Up) { newCam = upCam; transform.rotation = Quaternion.Euler(transform.rotation.x, 0, transform.rotation.z); } else if (directionFacing == Player.Direction.Down) { newCam = downCam; transform.rotation = Quaternion.Euler(transform.rotation.x, 180, transform.rotation.z); } else if (directionFacing == Player.Direction.Right) { newCam = rightCam; transform.rotation = Quaternion.Euler(transform.rotation.x, 90, transform.rotation.z); } else if (directionFacing == Player.Direction.Left) { newCam = leftCam; transform.rotation = Quaternion.Euler(transform.rotation.x, 270, transform.rotation.z); } blockManager.rotateSwitches(directionFacing); cameraMoving = true; } else if (newTile.CONTROLSWITCH) { if (newTile.switchRight) { onlyRight = true; hatRend.material.SetColor("_Color", Color.red); capeRend.material.SetColor("_Color", Color.red); } else { onlyRight = false; hatRend.material.SetColor("_Color", Color.blue); capeRend.material.SetColor("_Color", Color.blue); } } else if (newTile.KEYTILE) { hasKey = true; newTile.hideKey(); if (!pickedUpKeyPlayed) { pickedUpKeyPlayed = true; keyPickUp.Play(); } } else if (newTile.FANSWITCH) { blockManager.flipOnOff(); buttonPress.Play(); } tileBelow = newTile; moving1 = true; jumping.Play(); // yield return new WaitForSeconds(.5f); // canMove = true; }
void OnTriggerEnter2D(Collider2D other) { if (other.GetComponent<LevelBlock>() != null) { Level l = GameObject.Find("Level").GetComponent<Level>(); inBlock = other.GetComponent<LevelBlock>(); int[] myPos = l.GetTileCoords(inBlock); bool dugRight, dugLeft, dugUp, dugDown; dugRight = dugLeft = dugUp = dugDown = false; if (myPos[0] != 0) dugLeft = l.levelBlocks[myPos[0] - 1][myPos[1]].dug; if (myPos[0] != 11) dugRight = l.levelBlocks[myPos[0] + 1][myPos[1]].dug; if (myPos[1] != 0) dugUp = l.levelBlocks[myPos[0]][myPos[1] - 1].dug; if (myPos[1] != 11) dugDown = l.levelBlocks[myPos[0]][myPos[1] + 1].dug; Player.Direction prevFacing = facing; switch (facing) { case Player.Direction.right: if (!dugRight && !dugUp && !dugDown)//turn around facing = Player.Direction.left; if (!dugRight && dugUp && !dugDown)// turn up facing = Player.Direction.up; if (!dugRight && !dugUp && dugDown)// turn down facing = Player.Direction.down; if(!dugRight && dugUp && dugDown)// turn up or down { int rand = Random.Range(0,2); facing = (rand == 0? Player.Direction.up: Player.Direction.down); } break; case Player.Direction.left: if (!dugLeft && !dugUp && !dugDown)// turn around facing = Player.Direction.right; if (!dugLeft && dugUp && !dugDown)// turn up facing = Player.Direction.up; if (!dugLeft && !dugUp && dugDown) //turn down facing = Player.Direction.down; if (!dugLeft && dugUp && dugDown) //turn up or down { int rand = Random.Range(0, 2); facing = (rand == 0 ? Player.Direction.up : Player.Direction.down); } break; case Player.Direction.up: if (!dugUp && !dugLeft && !dugRight)// turn around facing = Player.Direction.down; if (!dugUp && dugLeft && !dugRight) //turn left facing = Player.Direction.left; if (!dugUp && !dugLeft && dugLeft) // turn right facing = Player.Direction.right; if(!dugUp && dugLeft && dugLeft) // turn right or left { int rand = Random.Range(0, 2); facing = (rand == 0 ? Player.Direction.left : Player.Direction.right); } break; case Player.Direction.down: if (!dugDown && !dugLeft && !dugRight) //turn around facing = Player.Direction.up; if (!dugDown && dugLeft && !dugRight) //turn left facing = Player.Direction.left; if (!dugDown && !dugLeft && dugRight) // turn right facing = Player.Direction.right; if (!dugDown && dugLeft && dugRight) //turn right or left { int rand = Random.Range(0, 2); facing = (rand == 0 ? Player.Direction.left : Player.Direction.right); } break; } if (prevFacing != facing) { Vector3 blockPos = other.gameObject.transform.position; transform.position = new Vector3(blockPos.x + 0.08f, blockPos.y - 0.08f, 0); } } }
public Vector2 GetPlayerPosition(Player.Direction dir) { return(new Vector2((dir == Player.Direction.LEFT ? POSITION_RIGHT : POSITION_LEFT), POSITION_Y)); }
void BeginPush() { firstFrame = false; pushDirection = direction; }
public void SetDirection(Player.Direction d) => direction = d;
// Requried methods /* * SetDirection * the grid will sends the current walls and the users direction to each player */ public abstract void setDirection(Wall[,] matrix, Player.Direction userDirection);