public void InitLogic(Dictionary <byte, NetworkPlayer> players) { PlayerCount = players.Count; Mediator = MainForm.Instance.Mediator; DoAfterGameLoop = new List <Action>(); PlayerPaddles = new Dictionary <byte, Paddle>(); ArenaBalls = new Dictionary <byte, IBall>(); ArenaObjects = new Dictionary <byte, ArenaObject>(); float deltaAngle = SharedUtilities.PI * 2 / PlayerCount; float angle = (-SharedUtilities.PI + deltaAngle) / 2f; foreach (var player in players.Values) { PaddleType pType = player.PaddleType; Paddle paddle = PaddleFactory.CreatePaddle(pType, player.Id); paddle.SetPosition(SharedUtilities.RadToDeg(angle)); PlayerPaddles.Add(player.Id, paddle); player.SetLife(paddle.Life); if (Mediator.GetBool("IdMatches", player.Id)) { LocalPaddle = paddle; } paddle.AddClampAngles(SharedUtilities.RadToDeg(angle - deltaAngle / 2), SharedUtilities.RadToDeg(angle + deltaAngle / 2)); angle += deltaAngle; } AlivePaddleCount = PlayerPaddles.Count; StartingAlivePaddleCount = AlivePaddleCount; UpdatableRoot = new UpdateComposite(); UpdatableRoot.Add(LocalPaddle.Id, LocalPaddle); UpdateComponent spawnerBranch = new UpdateComposite(); spawnerBranch.Add(spawnerBranch.GetNextId(), new ObstacleSpawner(GameData.ObstacleSpawnerParams, ArenaObjectFactories.Values.ToArray())); spawnerBranch.Add(spawnerBranch.GetNextId(), new PowerUpSpawner(GameData.PowerUpSpawnerParams, ArenaObjectFactories.Values.ToArray())); UpdatableRoot.Add(UpdatableRoot.GetNextId(), spawnerBranch); UpdateComponent objectBranch = new UpdateComposite(); ObjectBranchId = UpdatableRoot.GetNextId(); UpdatableRoot.Add(ObjectBranchId, objectBranch); UpdateComponent ballBranch = new UpdateComposite(); BallBranchId = UpdatableRoot.GetNextId(); UpdatableRoot.Add(BallBranchId, ballBranch); BallType bType = RoomSettings.Instance.BallType; Ball ball = Ball.CreateBall(0, bType, ArenaDimensions.Center, GameData.DefaultBallSpeed, Vector2.RandomInUnitCircle(), GameData.DefaultBallSize); ArenaBalls.Add(0, ball); ballBranch.Add(0, ball); IsInitted = true; PauseGame(false); }
public void OnArenaObjectCreated(ArenaObject obj) { byte id = idTmp++; UpdatableRoot.GetChild(ObjectBranchId).Add(id, obj); ArenaObjects.Add(id, obj); obj.SetId(id); if (Mediator.GetBool("IsRoomMaster", null)) { if (obj is Obstacle) { Mediator.Notify("SendObstacleSpawnedMessage", new object[] { id, obj }); } else if (obj is PowerUp) { Mediator.Notify("SendPowerupSpawnedMessage", new object[] { id, obj }); } } }