From b2198f448b23223de9f357bd21a6c37b0ad14c25 Mon Sep 17 00:00:00 2001 From: Evan Hemsley Date: Sun, 19 Jul 2020 19:00:24 -0700 Subject: [PATCH] remove unnecessary class vars --- PongFE/Engines/GameStateEngine.cs | 33 +++++++++++++------------------ PongFE/PongFEGame.cs | 2 +- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/PongFE/Engines/GameStateEngine.cs b/PongFE/Engines/GameStateEngine.cs index bc97d51..9d9baa4 100644 --- a/PongFE/Engines/GameStateEngine.cs +++ b/PongFE/Engines/GameStateEngine.cs @@ -6,7 +6,7 @@ using PongFE.Messages; namespace PongFE.Engines { - [Reads(typeof(GameStateComponent))] + [Reads(typeof(GameStateComponent), typeof(PlayAreaComponent))] [Receives(typeof(ChangeGameStateMessage))] [Sends( typeof(BallSpawnMessage), @@ -17,15 +17,6 @@ namespace PongFE.Engines [Writes(typeof(GameStateComponent))] public class GameStateEngine : Engine { - private int PlayAreaWidth { get; } - private int PlayAreaHeight { get; } - - public GameStateEngine(int playAreaWidth, int playAreaHeight) - { - PlayAreaWidth = playAreaWidth; - PlayAreaHeight = playAreaHeight; - } - public override void Update(double dt) { ref readonly var gameStateEntity = ref ReadEntity(); @@ -66,9 +57,13 @@ namespace PongFE.Engines private void StartGame() { + ref readonly var playAreaComponent = ref ReadComponent(); + var playAreaWidth = playAreaComponent.Width; + var playAreaHeight = playAreaComponent.Height; + SendMessage( new PaddleSpawnMessage( - new MoonTools.Structs.Position2D(20, PlayAreaHeight / 2 - 40), + new MoonTools.Structs.Position2D(20, playAreaHeight / 2 - 40), Enums.PlayerIndex.One, PaddleControl.Player, 20, @@ -78,7 +73,7 @@ namespace PongFE.Engines SendMessage( new PaddleSpawnMessage( - new MoonTools.Structs.Position2D(PlayAreaWidth - 45, PlayAreaHeight / 2 - 40), + new MoonTools.Structs.Position2D(playAreaWidth - 45, playAreaHeight / 2 - 40), Enums.PlayerIndex.Two, PaddleControl.Computer, 20, @@ -88,7 +83,7 @@ namespace PongFE.Engines SendMessage( new BallSpawnMessage( - new MoonTools.Structs.Position2D(PlayAreaWidth / 2, PlayAreaHeight / 2), + new MoonTools.Structs.Position2D(playAreaWidth / 2, playAreaHeight / 2), 500, 16, 16 @@ -100,7 +95,7 @@ namespace PongFE.Engines SendMessage( new BoundarySpawnMessage( new MoonTools.Structs.Position2D(0, -6), - PlayAreaWidth, + playAreaWidth, 6 ) ); @@ -108,8 +103,8 @@ namespace PongFE.Engines // bottom boundary SendMessage( new BoundarySpawnMessage( - new MoonTools.Structs.Position2D(0, PlayAreaHeight), - PlayAreaWidth, + new MoonTools.Structs.Position2D(0, playAreaHeight), + playAreaWidth, 6 ) ); @@ -118,9 +113,9 @@ namespace PongFE.Engines SendMessage( new GoalBoundarySpawnMessage( Enums.PlayerIndex.One, - new MoonTools.Structs.Position2D(PlayAreaWidth, 0), + new MoonTools.Structs.Position2D(playAreaWidth, 0), 6, - PlayAreaHeight + playAreaHeight ) ); @@ -130,7 +125,7 @@ namespace PongFE.Engines Enums.PlayerIndex.Two, new MoonTools.Structs.Position2D(-6, 0), 6, - PlayAreaHeight + playAreaHeight ) ); } diff --git a/PongFE/PongFEGame.cs b/PongFE/PongFEGame.cs index 0131aa7..5f74205 100644 --- a/PongFE/PongFEGame.cs +++ b/PongFE/PongFEGame.cs @@ -69,7 +69,7 @@ namespace PongFE 48 ); - WorldBuilder.AddEngine(new GameStateEngine(PLAY_AREA_WIDTH, PLAY_AREA_HEIGHT)); + WorldBuilder.AddEngine(new GameStateEngine()); WorldBuilder.AddEngine(new InputEngine()); WorldBuilder.AddEngine(new PaddleMovementEngine()); WorldBuilder.AddEngine(new VelocityEngine());