public static int InitialJumps(Ghosts ghost, bool newLevel) { if (newLevel) { switch (ghost) { case Ghosts.Inky: return((int)MathHelper.Clamp((20 - Level) / 2, 0, 10)); case Ghosts.Clyde: return(InitialJumps(Ghosts.Inky, true) + 2); default: return(0); } } else { switch (ghost) { case Ghosts.Inky: return(1); case Ghosts.Clyde: return(2); default: return(0); } } }
IEnumerator GetRequest(string uri) { UnityWebRequest uwr = UnityWebRequest.Get(uri); yield return(uwr.SendWebRequest()); if (uwr.isNetworkError) { Debug.Log("Error While Sending: " + uwr.error); } else { string s = uwr.downloadHandler.text; //Debug.Log("Received: " + s); Ghosts newGhosts = JsonUtility.FromJson <Ghosts>(s); foreach (Ghost g in newGhosts.ghosts) { GameObject newGhost = Instantiate(ghostPrefab, transform); newGhost.transform.position = g.ghostData.position; newGhost.transform.rotation = g.ghostData.rotation; newGhost.name = g.inserterID; } } }
public void Initialize() { //Initialize game if started for the first time if (this.IsInicialize == false) { this.IsInicialize = true; this.InitializeMatrix(); this.InicializeFruits(); this.DrawContent(); this.InicializeLeftScores(); this.TaskRenderingPacMan = new Task(this.RenderPacMan); this.TaskRenderingGhost = new Task(this.RenderGhost); this.PacMan = new PacMan(0, 0, this.GraphicsPacMan); for (int i = 0; i < Global.GhostElements; i++) { Ghosts.Add(new Ghost(PacMan.PositionQuadrantX, PacMan.PositionQuadrantY, this.GraphicsGhost)); } this.TaskRenderingPacMan.Start(); this.TaskRenderingGhost.Start(); Control.CheckForIllegalCrossThreadCalls = false; } else { this.DrawContent(); } }
public static void SaveLocalGhostAttempt(List <Ghosts.GhostFrame> frames) //This saves the local player's current attempt on this level. { string str = Ghosts.FramesToString(frames); Debug.Log("saving local ghost attempt: " + str); PlayerPrefs.SetString("localGhostAttempt_" + SceneManager.GetActiveScene().name, str); PlayerPrefs.Save(); }
void Start() { currentlyEdible = true; hasBeenEaten = false; score = 50; GetComponent <SpriteRenderer>().enabled = true; GetComponent <SpriteRenderer>().sprite = sprite; ghosts = FindObjectOfType <Ghosts>(); gameState = FindObjectOfType <GameState>(); }
public void LoadLevel(Level level) { State = GameState.Initialising; Level = level; Ghosts.Clear(); foreach (var ghost in level.Ghosts) { Ghosts.Add(new Ghost(ghost.X, ghost.Y, ghost.Logic)); } ResetCharacters(); FillPellets(); HasWon = false; }
public static List<Point> scatterTiles(Ghosts identity) { switch (identity) { case Ghosts.Blinky: return scatterTilesBlinky; case Ghosts.Clyde: return scatterTilesClyde; case Ghosts.Inky: return scatterTilesInky; case Ghosts.Pinky: return scatterTilesPinky; default: throw new ArgumentException(); } }
public string PrettyString() { var ghosts = string.Join(Environment.NewLine, Ghosts.Select(g => $"M, {g.Position.X}, {g.Position.Y}")); Func <bool, string> playerPL = a => a ? "P" : "L"; var players = string.Join(Environment.NewLine, Players.Select(p => $"P{p.Id}, {playerPL(p.Alive)}, {p.Position.X}, {p.Position.Y}")); var coins = string.Join(Environment.NewLine, Coins.Select(c => $"C, {c.Position.X}, {c.Position.Y}")); return(ghosts + Environment.NewLine + players + Environment.NewLine + coins + Environment.NewLine); }
public static Position startPosition(Ghosts identity) { switch (identity) { case Ghosts.Blinky: return startPositionBlinky; case Ghosts.Pinky: return startPositionPinky; case Ghosts.Clyde: return startPositionClyde; case Ghosts.Inky: return startPositionInky; default: throw new ArgumentException(); } }
/// <summary> /// Initialize the instance. This method MUST BE called before using this class. /// </summary> /// <param name="maze">The current maze</param> /// <param name="pac">The pac the user is playing</param> /// <param name="leader">The leader of the ghost (often, it is Blinky, the red ghost)</param> /// <param name="others">Array containing the others ghosts (all ghosts except the leader)</param> public void Initialize(Maze maze, Pac pac, Ghost leader, Ghost[] others) { PlayBeginning = -1; if (Ghosts == null) { Ghosts = new List <Ghost>(4); } else { Ghosts.Clear(); } Map = maze; Pac = pac; Ghosts.Add(leader); Ghosts.AddRange(others); // Search startup points for every ghosts List <Cell> list = Map.SearchTile(TileType.BLINKY_STARTUP); if (list != null && list.Count > 0) { Vector3 result = list[0].Dimension.Min; Ghosts[0].StartingPoint = Entrance = new Vector2(result.X, result.Y); // Now, the program must find the start area for the other ghosts list = Map.SearchTile(TileType.GHOSTS_STARTUP); if (list != null && list.Count >= (Ghosts.Count - 1)) { for (int i = 1, maxi = Ghosts.Count; i < maxi; i++) { // 1 <= i <= Ghosts.Count, but Ghosts.Count-1 <= list.Count. Therefore, list[i-1] will not throw an ArrayOutOfBoundException result = list[i - 1].Dimension.Min; Ghosts[i].StartingPoint = new Vector2(result.X, result.Y); } } else { throw new InvalidOperationException("No start point for the ghosts in the maze"); } } else { throw new InvalidOperationException("No start point for Blinky in the maze"); } IsInitialized = true; }
/// <summary> /// Instantiates a ghost. /// </summary> /// <param name="game">A reference to the Game object, needed for access to services.</param> /// <param name="player">A reference to the Pac Man, needed for AI.</param> /// <param name="identity">Which ghost, needed for appearance and behavior.</param> public Ghost(Game game, Player player, Ghosts identity) { spriteBatch_ = (SpriteBatch)game.Services.GetService(typeof(SpriteBatch)); ghostBase1_ = game.Content.Load<Texture2D>("sprites/GhostBase"); ghostBase2_ = game.Content.Load<Texture2D>("sprites/GhostBase2"); ghostChased_ = game.Content.Load<Texture2D>("sprites/GhostChased"); eyesBase_ = game.Content.Load<Texture2D>("sprites/GhostEyes"); eyesCenter_ = game.Content.Load<Texture2D>("sprites/GhostEyesCenter"); colorBase_ = Constants.colors(identity); identity_ = identity; previousNumCrumps_ = 0; Reset(true, player); wiggle_ = true; direction_ = new Direction(); lastJunction_ = new Point(); scatterTiles_ = Constants.scatterTiles(identity); }
public override CommonInterfaces.GameState Copy() { lock (this) { var gameState = new GameState(); gameState.Players = Players.ConvertAll((p) => p.Copy()); gameState.Coins = Coins.ConvertAll((c) => c.Copy()); gameState.Ghosts = Ghosts.ConvertAll((g) => g.Copy()); gameState.Walls = Walls.ConvertAll((w) => w.Copy()); gameState.Board = Board.Copy(); //last_inputs foreach (var input in lastInputs) { gameState.lastInputs.Add(input.Key, input.Value); } return(gameState); } }
/// <summary> /// Instantiates a ghost. /// </summary> /// <param name="game">A reference to the Game object, needed for access to services.</param> /// <param name="player">A reference to the Pac Man, needed for AI.</param> /// <param name="identity">Which ghost, needed for appearance and behavior.</param> public Ghost(Game game, Player player, Ghosts identity) { spriteBatch_ = (SpriteBatch)game.Services.GetService(typeof(SpriteBatch)); ghostBase1_ = game.Content.Load <Texture2D>("sprites/GhostBase"); ghostBase2_ = game.Content.Load <Texture2D>("sprites/GhostBase2"); ghostChased_ = game.Content.Load <Texture2D>("sprites/GhostChased"); eyesBase_ = game.Content.Load <Texture2D>("sprites/GhostEyes"); eyesCenter_ = game.Content.Load <Texture2D>("sprites/GhostEyesCenter"); colorBase_ = Constants.colors(identity); identity_ = identity; previousNumCrumps_ = 0; Reset(true, player); wiggle_ = true; direction_ = new Direction(); lastJunction_ = new Point(); scatterTiles_ = Constants.scatterTiles(identity); }
public static Position startPosition(Ghosts identity) { switch (identity) { case Ghosts.Blinky: return(startPositionBlinky); case Ghosts.Pinky: return(startPositionPinky); case Ghosts.Clyde: return(startPositionClyde); case Ghosts.Inky: return(startPositionInky); default: throw new ArgumentException(); } }
public static Color colors(Ghosts identity) { switch (identity) { case Ghosts.Blinky: return(Color.Red); case Ghosts.Clyde: return(Color.Orange); case Ghosts.Inky: return(Color.LightSkyBlue); case Ghosts.Pinky: return(Color.LightPink); default: throw new ArgumentException(); } }
public static List <Point> scatterTiles(Ghosts identity) { switch (identity) { case Ghosts.Blinky: return(scatterTilesBlinky); case Ghosts.Clyde: return(scatterTilesClyde); case Ghosts.Inky: return(scatterTilesInky); case Ghosts.Pinky: return(scatterTilesPinky); default: throw new ArgumentException(); } }
public static int InitialJumps(Ghosts ghost, bool newLevel) { if (newLevel) { switch (ghost) { case Ghosts.Inky: return (int)MathHelper.Clamp((20 - Level) / 2, 0, 10); case Ghosts.Clyde: return InitialJumps(Ghosts.Inky, true) + 2; default: return 0; } } else { switch (ghost) { case Ghosts.Inky: return 1; case Ghosts.Clyde: return 2; default: return 0; } } }
private IEnumerator GetGhosts() { string result = ""; string uri = "http://" + ghostServerHost + "/stages/" + sceneName + "/ghosts?app=" + app; List <Ghost> ghostList = new List <Ghost>(); yield return(StartCoroutine(GetRequest(uri, value => result = value))); if (!string.IsNullOrEmpty(result)) { Ghosts newGhosts = JsonUtility.FromJson <Ghosts>(result); foreach (Ghost g in newGhosts.ghosts) { ghostList.Add(g); } ghostList = CutDownGhosts(ghostList, maxNumberOfGhosts); foreach (Ghost g in ghostList) { SpawnGhost(g); } } }
private bool PacmanTouchingGhost() { return(Ghosts.Any(ghost => Pacman.X == ghost.X && Pacman.Y == ghost.Y)); }
public static void ResetSpeedrun() { Ghosts.ResetRecording(); //Resets (wipes) but stays in active recording mode speedrunTimeSet = timeInSeconds; //sets the timeset (the amount subtracted) from speedrun, forward. }
public static Color colors(Ghosts identity) { switch (identity) { case Ghosts.Blinky: return Color.Red; case Ghosts.Clyde: return Color.Orange; case Ghosts.Inky: return Color.LightSkyBlue; case Ghosts.Pinky: return Color.LightPink; default: throw new ArgumentException(); } }
public IGhost GetGhost(GhostNickname nickName) { var index = Ghosts.Single(g => g.NickName == nickName); return(index); }
public static bool IsExistGhost(int quadrantX, int quadrantY) { return(Convert.ToBoolean(Ghosts.FirstOrDefault(g => g.PositionQuadrantX == quadrantX && g.PositionQuadrantY == quadrantY))); }
// Use this for initialization void Start() { sk = FindObjectOfType <ScoreKeeper> (); source = GetComponent <AudioSource> (); ghosts = FindObjectOfType <Ghosts> (); }
public static void InitializeMap() { Walls.Clear(); Nodes.Clear(); EmptySquares.Clear(); Dots.Clear(); Powerups.Clear(); Ghosts.Clear(); Invaders.Clear(); //Initializes border of map string line = ""; int number = 0; using (StreamReader sr = new StreamReader("Maps/pacman" + PacmanGame.maps[PacmanGame.mapNumber].ToString() + ".txt")) { while (true) { line = sr.ReadLine(); if (line == null) { break; } for (int counter = 0; counter < line.Length; counter++) { wallMap[counter, number] = line[counter].ToString() == "0"; } number++; } } //Fills in rest of map using two dimensional bool array wallMap for (int x = 0; x < wallMap.GetLength(0); x++) { for (int y = 0; y < wallMap.GetLength(1); y++) { if (!wallMap[x, y]) { Walls.Add(new Wall(new Rectangle(x * PacmanGame.gridSize + PacmanGame.horizontalSpace, y * PacmanGame.gridSize + PacmanGame.verticalSpace, PacmanGame.gridSize, PacmanGame.gridSize))); } } } //Fills map with empty squares, dots and nodes in all places without walls //variable used to count nodes int variable = 0; for (int y = 1; y < PacmanGame.mapHeight / PacmanGame.gridSize - 1; y++) { for (int x = 1; x < PacmanGame.mapWidth / PacmanGame.gridSize - 1; x++) { Rectangle rectangle = new Rectangle(PacmanGame.gridSize * x + PacmanGame.horizontalSpace, PacmanGame.gridSize * y + PacmanGame.verticalSpace, PacmanGame.gridSize, PacmanGame.gridSize); bool value = true; foreach (Wall wall in Walls) { if (wall.Position == rectangle) { value = false; } } if (value) { EmptySquares.Add(new EmptySquare(rectangle)); Dots.Add(new Dot(rectangle)); Nodes.Add(new Node(variable, rectangle)); variable++; } } } //Remove the dot where the pacman starts Dots.Remove(new Dot(new Rectangle(PacmanGame.gridSize, PacmanGame.gridSize, PacmanGame.gridSize, PacmanGame.gridSize))); //Adds powerups Random random = new Random(); int[] values = Enumerable.Range(0, Map.Nodes.Count).OrderBy(x => random.Next()).ToArray(); for (int counter = 0; counter < 4; counter++) { int index = values[counter]; Rectangle rectangleValue = Map.Nodes.ElementAt(index).Position; Powerups.Add(new Powerup(rectangleValue)); //Remove the dot where the powerup is Dots.Remove(new Dot(rectangleValue)); } createAdjacencyList(); Paddles[0] = new Paddle(new Rectangle(PacmanGame.horizontalSpace / 2, PacmanGame.screenHeight / 2, PacmanGame.gridSize, PacmanGame.gridSize * 5), Player.Left); Paddles[1] = new Paddle(new Rectangle(PacmanGame.screenWidth - PacmanGame.horizontalSpace / 2, PacmanGame.screenHeight / 2, PacmanGame.gridSize, PacmanGame.gridSize * 5), Player.Right); }
public override byte[] Serialize() { List <byte> s = new List <byte>(); // serialize Width s.Add((byte)((Width == null) ? 0 : 1)); if (Width != null) { s.AddRange(BitConverter.GetBytes((int)Width)); } // serialize Height s.Add((byte)((Height == null) ? 0 : 1)); if (Height != null) { s.AddRange(BitConverter.GetBytes((int)Height)); } // serialize Board s.Add((byte)((Board == null) ? 0 : 1)); if (Board != null) { List <byte> tmp14 = new List <byte>(); tmp14.AddRange(BitConverter.GetBytes((uint)Board.Count())); while (tmp14.Count > 0 && tmp14.Last() == 0) { tmp14.RemoveAt(tmp14.Count - 1); } s.Add((byte)tmp14.Count); s.AddRange(tmp14); foreach (var tmp15 in Board) { s.Add((byte)((tmp15 == null) ? 0 : 1)); if (tmp15 != null) { List <byte> tmp16 = new List <byte>(); tmp16.AddRange(BitConverter.GetBytes((uint)tmp15.Count())); while (tmp16.Count > 0 && tmp16.Last() == 0) { tmp16.RemoveAt(tmp16.Count - 1); } s.Add((byte)tmp16.Count); s.AddRange(tmp16); foreach (var tmp17 in tmp15) { s.Add((byte)((tmp17 == null) ? 0 : 1)); if (tmp17 != null) { s.Add((byte)((sbyte)tmp17)); } } } } } // serialize Scores s.Add((byte)((Scores == null) ? 0 : 1)); if (Scores != null) { List <byte> tmp18 = new List <byte>(); tmp18.AddRange(BitConverter.GetBytes((uint)Scores.Count())); while (tmp18.Count > 0 && tmp18.Last() == 0) { tmp18.RemoveAt(tmp18.Count - 1); } s.Add((byte)tmp18.Count); s.AddRange(tmp18); foreach (var tmp19 in Scores) { s.Add((byte)((tmp19.Key == null) ? 0 : 1)); if (tmp19.Key != null) { List <byte> tmp20 = new List <byte>(); tmp20.AddRange(BitConverter.GetBytes((uint)tmp19.Key.Count())); while (tmp20.Count > 0 && tmp20.Last() == 0) { tmp20.RemoveAt(tmp20.Count - 1); } s.Add((byte)tmp20.Count); s.AddRange(tmp20); s.AddRange(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(tmp19.Key)); } s.Add((byte)((tmp19.Value == null) ? 0 : 1)); if (tmp19.Value != null) { s.AddRange(BitConverter.GetBytes((int)tmp19.Value)); } } } // serialize Pacman s.Add((byte)((Pacman == null) ? 0 : 1)); if (Pacman != null) { s.AddRange(Pacman.Serialize()); } // serialize Ghosts s.Add((byte)((Ghosts == null) ? 0 : 1)); if (Ghosts != null) { List <byte> tmp21 = new List <byte>(); tmp21.AddRange(BitConverter.GetBytes((uint)Ghosts.Count())); while (tmp21.Count > 0 && tmp21.Last() == 0) { tmp21.RemoveAt(tmp21.Count - 1); } s.Add((byte)tmp21.Count); s.AddRange(tmp21); foreach (var tmp22 in Ghosts) { s.Add((byte)((tmp22 == null) ? 0 : 1)); if (tmp22 != null) { s.AddRange(tmp22.Serialize()); } } } // serialize Constants s.Add((byte)((Constants == null) ? 0 : 1)); if (Constants != null) { s.AddRange(Constants.Serialize()); } return(s.ToArray()); }