private static void UpdatePlayerState(PongPlayer player, PongPlayerState pongPlayer) { player.State = pongPlayer; player.PlayerStats.State = pongPlayer.StatsState; player.Goal.State = pongPlayer.GoalState; player.Paddle.State = pongPlayer.PaddleState; player.Paddle.SpriteState = pongPlayer.PaddleState.SpriteState; }
public static string forPlayerMove(PongPlayer player) { StringBuilder sb = new StringBuilder("{\"type\":\"").Append(PongCoordinator.TYPE_PLAYER_MOVE).Append("\", "); sb.Append("\"").Append(PongPlayer.FIELD_PLAYERID).Append("\": \"").Append(player.playerid).Append("\", "); sb.Append("\"").Append(PongPlayer.FIELD_POSITION).Append("\":").Append(player.position).Append(", "); sb.Append("\"").Append(PongPlayer.FIELD_VELOCITY).Append("\":").Append(player.velocity); sb.Append("}"); return sb.ToString(); }
private void StartGame() { int totalPlayer = PhotonNetwork.CurrentRoom.PlayerCount; float radius = 15f / Mathf.Tan(Mathf.PI / totalPlayer); if (totalPlayer <= 2) { radius = 12.5f; } for (int i = 0; i < totalPlayer; i++) { Vector3 position = CalculateCirclePosition(0, radius, i, totalPlayer); Quaternion rotation = CalculateCircleRotation(0, i, totalPlayer); PongWall wall = Instantiate(wallPrefab, position, rotation).GetComponent <PongWall>(); wall.WallPlayerId = PhotonNetwork.PlayerList[i].ActorNumber; wall.SetColor(GlobalGameManager.GetColor(wall.WallPlayerId) - Color.gray); if (totalPlayer % 2 != 0) { position = CalculateCirclePosition(180, radius + 3, i, totalPlayer); rotation = CalculateCircleRotation(180, i, totalPlayer); PongWall wallCorner = Instantiate(wallEmptyPrefab, position, rotation).GetComponent <PongWall>(); wallCorner.WallPlayerId = -1; } if (PhotonNetwork.LocalPlayer == PhotonNetwork.PlayerList[i]) { position = CalculateCirclePosition(0, radius - 2, i, totalPlayer); rotation = CalculateCircleRotation(0, i, totalPlayer); myPlayer = PhotonNetwork.Instantiate("PongPlayer", position, rotation, 0).GetComponent <PongPlayer>(); position = CalculateCirclePosition(0, radius, i, totalPlayer); rotation = CalculateCircleRotation(0, i, totalPlayer); camera.transform.rotation = rotation; camera.transform.Rotate(Vector3.right, 45); position += Vector3.up * 10; camera.transform.position = position; } } if (PhotonNetwork.IsMasterClient) { StartCoroutine(SpawnCase()); } gameStarted = true; }
public PongPlayer NextPlayer(PongPlayer pp) { var c = this.list.Count; var i = this.list.IndexOf(pp) + 1; if (i < c) { return(this.list[i]); } if (c > 0) { return(this.list[0]); } return(null); }
public void TestPlayerInfo() { var playa = new PongPlayer("id of player"); playa.goalLeft = new Vector2(1f, 2f); playa.goalRight = new Vector2(3f, 4f); playa.length = 5f; playa.height = 6f; string msg = playa.toJSON(); object boe = JSON.JsonDecode(msg); PongPlayer second = new PongPlayer((Hashtable) boe); string msg2 = second.toJSON(); Assert.AreEqual(msg, msg2); }
/* * Set ball to collide with a player. * Also sets color of ball to match player. * * If null player is null then ball is removed. */ public void ReTarget(GameObject ball, PongPlayer pp) { if (ball != null) { this.balls = this.balls.Where(pb => pb.ball != ball).ToList(); if (pp != null) { ball.GetComponent <PongBall>().color = pp.color; this.SetCollision(ball, pp.paddle); this.balls.Add(new PlayerBall(pp, ball)); } else { ball.GetComponent <PongBall>().Kill(); } } }
/* * Spawns a new ball for a certain player. */ public void SpawnBall(PongPlayer player) { if (player == null) { return; } var ball = (GameObject)Instantiate(Resources.Load("pong/ball")); ball.GetComponent <PongBall> ().onCollision = () => { this.onCollision(this.balls.Where(pb => pb.ball == ball).First()); }; ball.GetComponent <PongBall>().onLeaveGameArea = () => { this.SetCollision(ball, null); }; ball.GetComponent <PongBall> ().onExit = () => { var playerBall = this.balls.Where(pb => pb.ball == ball).First(); this.ReTarget(playerBall.ball, null); this.onLeave(playerBall); }; this.ReTarget(ball, player); }
public PlayerBall(PongPlayer player, GameObject ball) { this.ball = ball; this.player = player; }
public static PongPlayer fromPlayerMove(PongPlayer player, Hashtable playerMove) { player.position = Convert.ToSingle((double)playerMove[PongPlayer.FIELD_POSITION]); player.velocity = Convert.ToSingle((double)playerMove[PongPlayer.FIELD_VELOCITY]); return player; }
private void UpdateJoinedStarting() { //we're starting a new game this.playerInfo.Clear(); //@TODO: destroy gameobject paddles from previous game ArrayList players = (ArrayList)parsedGameSetup[PongPlayer.ARRAY_PLAYERS]; PongPlayer previousPlayer = null; for (int p = 0; p < players.Count; ++p) { PongPlayer newPlayer = new PongPlayer((Hashtable)players[p]); //now create the walls & goals: GameObject goal = Instantiate<GameObject>(PrefabGoal); createWall(goal, newPlayer.goalLeft, newPlayer.goalRight); goal.name = "Goal for " + newPlayer.playerid; newPlayer.paddle = CreatePaddle(newPlayer.playerid, goal.transform.rotation, newPlayer.playerLeft, newPlayer.playerRight); //@TODO: for local paddle, bind keys to the newly instantiated paddle this.playerInfo.Add(newPlayer.playerid, newPlayer); //@TODO: link goal to correct user, for points and awards if (previousPlayer != null) { GameObject wall = Instantiate<GameObject>(PrefabWall); createWall(wall, previousPlayer.goalRight, newPlayer.goalLeft); } previousPlayer = newPlayer; } this.localPlayer = this.playerInfo[this.localPlayerName]; //some ugly shenanigans to create the last wall (between first and last player) GameObject lastwall = Instantiate<GameObject>(PrefabWall); createWall(lastwall, previousPlayer.goalRight, PongSerializer.toVector((Hashtable) ((Hashtable)players[0])[PongPlayer.FIELD_GOALLEFT])); //now let's play ball! GameObject ballobject = Instantiate<GameObject>(PrefabBall); ballobject.name = "PongTestBall"; this.ball = new PongBall(ballobject.GetComponent<Rigidbody>()); //next frame, we can start playing! status = CoordinatorStatus.JOINED_PLAYING; }
private void ReceivePlayerJoined(Hashtable parsedPlayer) { //construct a place-holder player info. The coordinates and other details will be communicated by the host (later) PongPlayer playa = new PongPlayer((string)parsedPlayer[PongPlayer.FIELD_PLAYERID]); Debug.Log("player joined: " + playa.playerid); if (status == CoordinatorStatus.HOSTING_PLAYING) { status = CoordinatorStatus.HOSTING_WAITING_FOR_PLAYERS; } if (this.localPlayerName.Equals(playa.playerid)) { Debug.Log("hey, that's me joining!"); if (status == CoordinatorStatus.JOINING) { status = CoordinatorStatus.JOINED_STARTING; } //@TODO: bind this player's paddle to local keys //CORRECTION: binding should only happen during setup of the game (when host is building playfield) localPlayer = playa; } playerInfo.Add(playa.playerid, playa); Debug.Log("Total #players joined: " + playerInfo.Count); }