// Function to check if path is free of any wall public static bool IsPathClear(Convertible c, Camera cam, Maze maze) { bool result = true; int x1, y1, x2, y2; x1 = (int)cam.Position.X; y1 = (int)cam.Position.Z; x2 = (int)c.Position.X; y2 = (int)c.Position.Z; if (IsInSameRow(c, cam)) { if (x1 <= x2) { while (result && x1 != x2) { x1++; result = !(maze.GetCube(x1, y1).Type == TileType.Wall); } } else { while (result && x1 != x2) { x2++; result = !(maze.GetCube(x2, y2).Type == TileType.Wall); } } } else { if (x1 <= x2) { while (result && y1 != y2) { y1++; result = !(maze.GetCube(x1, y1).Type == TileType.Wall); } } else { while (result && y1 != y2) { y2++; result = !(maze.GetCube(x2, y2).Type == TileType.Wall); } } } return(result); }
public void Update(GameTime gameTime) { if (Instance.IsActive) { Input.Update(); if (GameState == GameState.GameOver || GameState == GameState.Win) { if (Input.KeyPressed(Keys.Escape, true)) { Instance.Exit(); } } else { hud.Update(gameTime); Maze.Update(gameTime); if (Input.KeyPressed(Keys.E, true) && !Convertible.IsConversionOn) { closestConvertible = null; double minDist = 9999; // Find the closest Convertibles in the front of the camera foreach (Convertible c in Maze.Convertibles) { if (Maze.IsInFront(c, Camera)) { // Check if the distance is less than the previous minimum double distance = Math.Sqrt((double)(Math.Pow(c.Position.X - Camera.Position.X, 2) + Math.Pow(c.Position.Z - Camera.Position.Z, 2))); if (distance < minDist) { // Check if said convertible is visible by the camera if (Maze.IsPathClear(c, Camera, Maze)) { minDist = distance; closestConvertible = c; } } } } if (closestConvertible != null) { Debug.Print("Closest : " + closestConvertible.Position.X + ";" + closestConvertible.Position.Y); closestConvertible.DisplayConv = true; } else { Debug.Print("nothing found"); } if (closestConvertible != null) { EventManager.Instance.Raise(new OnConversionStartEvent() { convertible = closestConvertible }); conversionManager.Initialize(closestConvertible); } } else if (Input.KeyPressed(Keys.Escape, true) && Convertible.IsConversionOn) { EventManager.Instance.Raise(new OnConversionStopEvent() { convertible = closestConvertible }); closestConvertible.DisplayConv = false; } else if (Input.KeyPressed(Keys.Escape, true)) { Instance.Exit(); } // Move only if the player is not currently converting if (!Convertible.IsConversionOn) { Camera.Update(gameTime); } else { conversionManager.Update(gameTime); } if (GameState == GameState.Transition) { GameState = GameState.Playing; } } } }
// Check if Convertible is visible over the cam private static bool IsVisibleOver(Convertible c, Camera cam) { return(IsOverCam(c, cam) && (MathHelper.ToDegrees(cam.Rotation.Y) > 135) || (MathHelper.ToDegrees(cam.Rotation.Y) < -135)); }
// Check if Convertible is visible at the left of the cam private static bool IsVisibleLeft(Convertible c, Camera cam) { return(IsLeftOfCam(c, cam) && (MathHelper.ToDegrees(cam.Rotation.Y) > -135) && (MathHelper.ToDegrees(cam.Rotation.Y) < -45)); }
// Check if Convertible X value is lower than camera's private static bool IsLeftOfCam(Convertible c, Camera cam) { return(IsInSameRow(c, cam) && (int)c.Position.X <= cam.Position.X); }
// Check if Convertible is visible under the cam private static bool IsVisibleUnder(Convertible c, Camera cam) { return(IsUnderCam(c, cam) && (MathHelper.ToDegrees(cam.Rotation.Y) > -45) && (MathHelper.ToDegrees(cam.Rotation.Y) < 45)); }
// Check if Convertible Z value is lower than camera's private static bool IsOverCam(Convertible c, Camera cam) { return(IsInSameColumn(c, cam) && (int)c.Position.Z <= cam.Position.Z); }
// Check if Convertible in same column private static bool IsInSameColumn(Convertible c, Camera cam) { return((int)c.Position.X == (int)cam.Position.X); }
// Check if Convertible in same row private static bool IsInSameRow(Convertible c, Camera cam) { return((int)c.Position.Z == (int)cam.Position.Z); }
// *** Functions to check Convertible presence in field of view *** // Check if Convertible is in front of the camera public static bool IsInFront(Convertible c, Camera cam) { return(IsVisibleUnder(c, cam) || IsVisibleOver(c, cam) || IsVisibleRight(c, cam) || IsVisibleLeft(c, cam)); }
public void Initialize(Convertible convertible) { this.convertible = convertible; number = ""; firstInput = true; }