public ClockDisplay(FrameClock clock, BitmapFont font, Vector2 position) { this.Clock = clock; this.font = font; this.Position = position; GenerateText(); }
/// <summary> /// Updates the time delta with a new value from the last frame. /// </summary> /// <param name="widget">The sending widget.</param> /// <param name="frameClock">The relevant frame clock.</param> /// <returns>true if the callback should be called again; otherwise, false.</returns> private bool UpdateFrameTime(Widget widget, FrameClock frameClock) { var frameTimeµSeconds = frameClock.FrameTime; if (!_PreviousFrameTime.HasValue) { _PreviousFrameTime = frameTimeµSeconds; return(true); } var frameTimeSeconds = (frameTimeµSeconds - _PreviousFrameTime) / 10e6; DeltaTime = (float)frameTimeSeconds; _PreviousFrameTime = frameTimeµSeconds; return(true); }
public void Run() { // Initializing the tilemap facade tileMapFacade = new TileMapFacade((int)VideoResolution[0], (int)VideoResolution[1], Properties.Resources.spritesheet2); BindKeys(); _boardBuilder = new BoardBuilder(); ConfigureHubConnections(); // Wall box _boxWall = SpriteLoader.LoadSprite(Properties.Resources.DesolatedHut, new IntRect(0, 0, 100, 100)); _boxWall.Position = new Vector2f(250, 250); _boxWall.Scale = new Vector2f(0.5f, 0.5f); // UI score object _renderWindow = CreateRenderWindow(Styles.Default); _renderWindow.SetFramerateLimit(60); _renderWindow.SetActive(); scoreBoard = new GameScore(_renderWindow, otherPlayers, mainPlayer.connectionId); _debugGui = new DebugGUI(_renderWindow); execRTCounter(); // sync with server // Player postion from left, top (x, y) var coordText = new Text("", new Font(Properties.Resources.arial)); coordText.CharacterSize = 20; coordText.Position = new Vector2f(10, 10); // BombKey [SPACE] event handler _renderWindow.KeyPressed += new EventHandler <KeyEventArgs>(OnKeyPressed); // damage - placeDelay - bombTimer mainPlayer.Bomb = new Bomb(20, 2500, 0); // Chain object init // connecting chains chainLogger.setNextLogger(chainLogger2); chainLogger2.setNextLogger(chainLogger3); float RespawnPause = 0f; while (_renderWindow.IsOpen) { Time deltaTime = FrameClock.Restart(); // Requesting refresh data from server at every new frame _userHubConnection.InvokeAsync("RefreshPlayer", new PlayerDTO() { connectionId = mainPlayer.connectionId, position = mainPlayer.GetPointPosition(), IsDead = mainPlayer.IsDead }).Wait(); _renderWindow.DispatchEvents(); // event handler to processes keystrokes/mouse movements _renderWindow.Clear(); // TILES _renderWindow.Draw(tileMapFacade.GetTileMap()); if (!ghostDead) { foreach (var enemy in _boardBuilder._enemies) { var sprite = enemy.getSprite(); _renderWindow.Draw(sprite); } } foreach (Player p in otherPlayers) { if (!p.IsDead) { _renderWindow.Draw(p); } } if (!mainPlayer.IsDead) { _renderWindow.Draw(mainPlayer); //DEBUG - RED FRAME _renderWindow.Draw(mainPlayer.DrawFrame()); } // Update drawable destructor timers UpdateLoop(deltaTime); // BOMBS mainPlayer.Update(); // Update projectile placement positions (bombs) DrawLoop(); // Draw projectile buffer list // RESPAWN ROUTINE /*if(RespawnPause > 0) * RespawnPause -= deltaTime.AsSeconds();*/ /*if (mainPlayer.CheckDeathCollisions() && RespawnPause <= 0f) // if collided with flames? * { * RespawnPause = 2f; * scoreBoard.UpdateScore("P1"); * }*/ // Print player coordinates left, top (x, y) coordText.DisplayedString = $"x {mainPlayer.Position.X} y {mainPlayer.Position.Y}"; _renderWindow.Draw(coordText); _renderWindow.Draw(scoreBoard); _renderWindow.Draw(_debugGui); if (_renderWindow.HasFocus()) // if window is focused { InputControl(); } _renderWindow.Display(); // update screen } }
public ClockDisplay(FrameClock clock, BitmapFont font, Vector2 position, Color color) : this(clock, font, position) { this.Color = color; }
public ClockDisplay(FrameClock clock, BitmapFont font, Vector2 position, Vector4 color) : this(clock, font, position) { this.Color = Color.FromArgb((int)(color.X * 255), (int)(color.Y * 255), (int)(color.Z * 255), (int)(color.W * 255)); }
// ======================================================================== // =========================== 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(); } } }