// ======================================================================== // =========================== MAIN ENTRY POINT =========================== // ======================================================================== public void Run() { // set up loggers using chain of responsibility pattern Console.ForegroundColor = ConsoleColor.White; defaultLogger.SetNext(importantLogger); importantLogger.SetNext(fileLogger); fileLogger.SetNext(criticalLogger); criticalLogger.SetNext(null); defaultLogger.LogMessage(60, "Loggers setup!"); // Create render window GameWindow = CreateRenderWindow(Styles.Close); Vector2f winSize = GameWindow.GetView().Size; // Load resources CreateSprites(); GameState.InitRandom(5); builder = new MapBuilder(); builder.LoadSprites(); director = new Director(builder); director.Construct(); GameState.TileMap = builder.GetResult(); // Portal creation PortalProspect portal = new PortalProspect(); Caretaker m1 = new Caretaker(); Caretaker m2 = new Caretaker(); portal.Pos = new Vector2f(3 * 64f, 45 * 64f); portal.Tex = TextureHolder.GetInstance().Get(TextureIdentifier.Portal); m1.Memento = portal.CreateMemento(); portal.Pos = new Vector2f(60 * 64f, 3 * 64f); portal.Tex = TextureHolder.GetInstance().Get(TextureIdentifier.PortalRed); m2.Memento = portal.CreateMemento(); GameState.NonCollidableRep.GetIterator().Add(portal); // Generate additional objects (destructibles, indestructibles, pickupables) SpawningManager(20, 15, 60, 20); // View MainView = GameWindow.DefaultView; ZoomedView = new View(MainView); GameWindow.SetView(ZoomedView); // weapon prototype weaponProtoype = new Pistol(mediator); // Player init CreateMainPlayer(); mediator.GetPlayerText(MainPlayer.PlayerBar); ConnectionManager connectionManager = new ConnectionManager("http://underpoweredserver.tplinkdns.com:51230/sd-server"); GameState.ConnectionManagerProxy = new Managers.Proxy.ConnectionManagerProxy(connectionManager); bool isPlayerSpawned = ForceSpawnObject(MainPlayer); if (isPlayerSpawned) { GameState.PlayerRep.GetIterator().Add(MainPlayer); GameState.PlayerRep.GetIterator().Add(SpawnFakePlayer(4000, 2000)); GameState.PlayerRep.GetIterator().Add(SpawnFakePlayer(4000, 2200)); GameState.PlayerRep.GetIterator().Add(SpawnFakePlayer(4000, 2400)); } PlayerEventManager.Subscribe(PlayerEventType.KilledPlayer, GameplayUI.KillNotifier); PlayerEventManager.Subscribe(PlayerEventType.KilledPlayer, GameplayUI.Scoreboard); var mPos = GameWindow.MapPixelToCoords(Mouse.GetPosition(GameWindow)); while (GameWindow.IsOpen) { GameWindow.Clear(); GameWindow.DispatchEvents(); if (this.HasFocus) { this.ProccesKeyboardInput(); mPos = GameWindow.MapPixelToCoords(Mouse.GetPosition(GameWindow)); } Time deltaTime = FrameClock.Restart(); if (GameState.ConnectionManagerProxy.ActivityClock.ElapsedTime.AsSeconds() > (1f / multiplayerSendRate) && GameState.ConnectionManagerProxy.IsConnected()) { GameState.ConnectionManagerProxy.ActivityClock.Restart(); SendPos(GameState.ConnectionManagerProxy.Connection); } var middlePoint = VectorUtils.GetMiddlePoint(MainPlayer.Position, mPos); MainPlayer.Heading = VectorUtils.GetAngleBetweenVectors(MainPlayer.Position, mPos); MainPlayer.LookingAtPoint = mPos; SpawnPortal(portal, m1, m2); UpdateLoop(deltaTime, mPos); lock (SFMLLock) { DrawLoop(); GameWindow.SetView(MainView); GameWindow.Draw(GameplayUI.Scoreboard); GameWindow.Draw(GameplayUI.RespawnMesage); GameWindow.Draw(GameplayUI.KillNotifier); GameWindow.Draw(GameplayUI.InGameLog); if (container.Show) { GameWindow.Draw(container.composite); } ZoomedView.Center = middlePoint; ZoomedView.Zoom(zoomView); zoomView = 1.0f; GameWindow.SetView(ZoomedView); GameWindow.Display(); } } }