From ff8f3c772129a429958196b60c701f75eafdae06 Mon Sep 17 00:00:00 2001 From: Apostrov Date: Fri, 24 Feb 2023 17:52:39 +0300 Subject: [PATCH] Minor fixes --- Code/DrawLogic/DrawUtils.cs | 7 +++---- Code/DrawLogic/Systems/GameBoardDrawer.cs | 11 +++++------ Code/GameConfig.cs | 2 ++ Code/GameLogic/PiecePosition.cs | 3 ++- Code/GameLogic/Systems/BonusSpawner.cs | 4 ++-- Code/GameLogic/Systems/FillBoardProcessing.cs | 8 +++----- Code/GameLogic/Systems/GameBoardInit.cs | 8 ++++---- Code/GameLogic/Systems/PlayerClickedProcessing.cs | 3 +-- Code/GameLogic/Systems/RearrangeBoardProcessing.cs | 9 ++------- Code/Match3Game.cs | 5 +---- Code/SharedData.cs | 1 - Code/UI/Systems/RestartButtonClickedTracker.cs | 9 +++------ README.md | 2 +- 13 files changed, 29 insertions(+), 43 deletions(-) diff --git a/Code/DrawLogic/DrawUtils.cs b/Code/DrawLogic/DrawUtils.cs index 32d5fbf..77f1f00 100644 --- a/Code/DrawLogic/DrawUtils.cs +++ b/Code/DrawLogic/DrawUtils.cs @@ -16,13 +16,12 @@ public static Point GetTileSize(Texture2D atlas) return new Point(atlas.Width / ATLAS_SIZE, atlas.Height / ATLAS_SIZE); } - public static Vector2 GetTileScreenPosition(int row, int column, GraphicsDevice graphicsDevice, Point tileSize, - int boardSize) + public static Vector2 GetTileScreenPosition(int row, int column, GraphicsDevice graphicsDevice, Point tileSize) { int centerX = graphicsDevice.Viewport.Width / 2 + tileSize.X / 2; int centerY = graphicsDevice.Viewport.Height / 2 + tileSize.Y / 2; - int startX = centerX - tileSize.X * boardSize / 2; - int startY = centerY - tileSize.Y * boardSize / 2; + int startX = centerX - tileSize.X * GameConfig.BOARD_SIZE / 2; + int startY = centerY - tileSize.Y * GameConfig.BOARD_SIZE / 2; return new Vector2(startX + column * tileSize.X, startY + row * tileSize.Y); } } \ No newline at end of file diff --git a/Code/DrawLogic/Systems/GameBoardDrawer.cs b/Code/DrawLogic/Systems/GameBoardDrawer.cs index 69c5300..7c614dc 100644 --- a/Code/DrawLogic/Systems/GameBoardDrawer.cs +++ b/Code/DrawLogic/Systems/GameBoardDrawer.cs @@ -24,17 +24,16 @@ public void Init(IEcsSystems systems) public void Run(IEcsSystems systems) { - if(_gameplay.Value.GetEntitiesCount() < 1) + if (_gameplay.Value.GetEntitiesCount() < 1) return; - + _shared.Value.SpriteBatch.Begin(); - for (int row = 0; row < _shared.Value.BoardSize; row++) + for (int row = 0; row < GameConfig.BOARD_SIZE; row++) { - for (int column = 0; column < _shared.Value.BoardSize; column++) + for (int column = 0; column < GameConfig.BOARD_SIZE; column++) { - var position = DrawUtils.GetTileScreenPosition(row, column, _shared.Value.GraphicsDevice, _tileSize, - _shared.Value.BoardSize); + var position = DrawUtils.GetTileScreenPosition(row, column, _shared.Value.GraphicsDevice, _tileSize); _shared.Value.SpriteBatch.Draw(_backgroundTile, position); } } diff --git a/Code/GameConfig.cs b/Code/GameConfig.cs index ab59e9e..880426c 100644 --- a/Code/GameConfig.cs +++ b/Code/GameConfig.cs @@ -8,8 +8,10 @@ public static class GameConfig public const float SELECTED_ANIMATION_TIME = 0.75f; public const float DESTROY_ANIMATION_TIME = 0.35f; public const float REARRANGE_ANIMATION_TIME = 0.3f; + public const int SPAWN_PIECE_ROW = -5; // game logic + public const int BOARD_SIZE = 8; public const int MATCH_COUNT = 3; public const int LINE_BONUS_COUNT = 4; public const float LINE_DESTROYER_FLY_SPEED = 800f; diff --git a/Code/GameLogic/PiecePosition.cs b/Code/GameLogic/PiecePosition.cs index 1514379..34243d1 100644 --- a/Code/GameLogic/PiecePosition.cs +++ b/Code/GameLogic/PiecePosition.cs @@ -1,4 +1,5 @@ -namespace MonoMatch3.Code.GameLogic; +#nullable enable +namespace MonoMatch3.Code.GameLogic; public struct PiecePosition { diff --git a/Code/GameLogic/Systems/BonusSpawner.cs b/Code/GameLogic/Systems/BonusSpawner.cs index 3a824dd..a6ded34 100644 --- a/Code/GameLogic/Systems/BonusSpawner.cs +++ b/Code/GameLogic/Systems/BonusSpawner.cs @@ -54,8 +54,8 @@ private void SpawnBonus(int pieceEntity, Components.BonusSpawn bonusSpawn) ref var gameBoard = ref _gameBoard.Pools.Inc1.Get(gameBoardEntity); int row = bonusSpawn.Position.Row, column = bonusSpawn.Position.Column; var tileSize = DrawLogic.DrawUtils.GetTileSize(_shared.Value.TilesAtlas); - var position = DrawLogic.DrawUtils.GetTileScreenPosition(row, column, _shared.Value.GraphicsDevice, - tileSize, _shared.Value.BoardSize); + var position = + DrawLogic.DrawUtils.GetTileScreenPosition(row, column, _shared.Value.GraphicsDevice, tileSize); ref var piece = ref _piecePool.Value.Add(pieceEntity); piece.BoardPosition.Column = column; diff --git a/Code/GameLogic/Systems/FillBoardProcessing.cs b/Code/GameLogic/Systems/FillBoardProcessing.cs index d2a2612..0bf0e6a 100644 --- a/Code/GameLogic/Systems/FillBoardProcessing.cs +++ b/Code/GameLogic/Systems/FillBoardProcessing.cs @@ -35,9 +35,8 @@ public void Run(IEcsSystems systems) continue; var newPiece = _world.Value.NewEntity(); - var startPosition = DrawLogic.DrawUtils.GetTileScreenPosition(-5, column, - _shared.Value.GraphicsDevice, - tileSize, _shared.Value.BoardSize); + var startPosition = DrawLogic.DrawUtils.GetTileScreenPosition(GameConfig.SPAWN_PIECE_ROW, column, + _shared.Value.GraphicsDevice, tileSize); ref var piece = ref _piecePool.Value.Add(newPiece); piece.BoardPosition.Column = column; piece.BoardPosition.Row = row; @@ -51,8 +50,7 @@ public void Run(IEcsSystems systems) gameBoard.Board[row, column] = entityPacked; var endPosition = DrawLogic.DrawUtils.GetTileScreenPosition(row, column, - _shared.Value.GraphicsDevice, - tileSize, _shared.Value.BoardSize); + _shared.Value.GraphicsDevice, tileSize); _shared.Value.Tweener.TweenTo( target: piece.Transform, expression: t => t.Position, diff --git a/Code/GameLogic/Systems/GameBoardInit.cs b/Code/GameLogic/Systems/GameBoardInit.cs index 6cae581..0a0d66f 100644 --- a/Code/GameLogic/Systems/GameBoardInit.cs +++ b/Code/GameLogic/Systems/GameBoardInit.cs @@ -28,18 +28,18 @@ public void Init(IEcsSystems systems) // create board ref var gameBoard = ref _gameBoardPool.Value.Add(_world.Value.NewEntity()); - gameBoard.Board = new EcsPackedEntity[_shared.Value.BoardSize, _shared.Value.BoardSize]; + gameBoard.Board = new EcsPackedEntity[GameConfig.BOARD_SIZE, GameConfig.BOARD_SIZE]; var tileSize = DrawLogic.DrawUtils.GetTileSize(_shared.Value.TilesAtlas); // fill board - for (int row = 0; row < _shared.Value.BoardSize; row++) + for (int row = 0; row < GameConfig.BOARD_SIZE; row++) { - for (int column = 0; column < _shared.Value.BoardSize; column++) + for (int column = 0; column < GameConfig.BOARD_SIZE; column++) { var pieceEntity = _world.Value.NewEntity(); var position = DrawLogic.DrawUtils.GetTileScreenPosition(row, column, _shared.Value.GraphicsDevice, - tileSize, _shared.Value.BoardSize); + tileSize); ref var piece = ref _piecePool.Value.Add(pieceEntity); piece.BoardPosition.Column = column; piece.BoardPosition.Row = row; diff --git a/Code/GameLogic/Systems/PlayerClickedProcessing.cs b/Code/GameLogic/Systems/PlayerClickedProcessing.cs index a0c6a9a..f29c401 100644 --- a/Code/GameLogic/Systems/PlayerClickedProcessing.cs +++ b/Code/GameLogic/Systems/PlayerClickedProcessing.cs @@ -8,14 +8,13 @@ namespace MonoMatch3.Code.GameLogic.Systems; public class PlayerClickedProcessing : IEcsRunSystem { - private readonly EcsFilterInject> _gameplay; + private readonly EcsFilterInject> _gameplay = default; private readonly EcsFilterInject, Exc> _pieces = default; private readonly EcsFilterInject> _selected = default; private readonly EcsFilterInject> _swapWait = default; private readonly EcsFilterInject> _rearrangePiece = default; private readonly EcsSharedInject _shared = default; - private readonly EcsWorldInject _world = default; public void Run(IEcsSystems systems) { diff --git a/Code/GameLogic/Systems/RearrangeBoardProcessing.cs b/Code/GameLogic/Systems/RearrangeBoardProcessing.cs index f7df0c7..1521374 100644 --- a/Code/GameLogic/Systems/RearrangeBoardProcessing.cs +++ b/Code/GameLogic/Systems/RearrangeBoardProcessing.cs @@ -29,7 +29,7 @@ public void Run(IEcsSystems systems) { ref var rearrange = ref _rearrange.Pools.Inc1.Get(rearrangeEntity); rearrange.WaitTime -= _shared.Value.GameTime.GetElapsedSeconds(); - if (rearrange.WaitTime > 0.0f || + if (rearrange.WaitTime > 0.0f || _destroy.Value.GetEntitiesCount() > 0 || _destroyer.Value.GetEntitiesCount() > 0 || _explosion.Value.GetEntitiesCount() > 0) @@ -66,7 +66,7 @@ public void Run(IEcsSystems systems) ref var nextPiece = ref _piecePool.Value.Get(nextPieceEntity); nextPiece.BoardPosition = new PiecePosition(row, column); var position = DrawLogic.DrawUtils.GetTileScreenPosition(row, column, - _shared.Value.GraphicsDevice, tileSize, _shared.Value.BoardSize); + _shared.Value.GraphicsDevice, tileSize); if (_rearrangePiecePool.Value.Has(nextPieceEntity)) { @@ -94,9 +94,4 @@ public void Run(IEcsSystems systems) _fillBoard.Value.Add(_world.Value.NewEntity()); } } - - private void RearrangeBoard() - { - - } } \ No newline at end of file diff --git a/Code/Match3Game.cs b/Code/Match3Game.cs index 6b63d67..4a1e69c 100644 --- a/Code/Match3Game.cs +++ b/Code/Match3Game.cs @@ -10,8 +10,6 @@ namespace MonoMatch3.Code { public class Match3Game : Game { - private const int BOARD_SIZE = 8; - private readonly GraphicsDeviceManager _graphics; private SpriteBatch _spriteBatch; @@ -32,8 +30,7 @@ public Match3Game() _sharedData = new SharedData { GraphicsDevice = GraphicsDevice, - Tweener = new Tweener(), - BoardSize = BOARD_SIZE + Tweener = new Tweener() }; EcsInit(); } diff --git a/Code/SharedData.cs b/Code/SharedData.cs index f50db9c..a53ae91 100644 --- a/Code/SharedData.cs +++ b/Code/SharedData.cs @@ -16,5 +16,4 @@ public class SharedData // game logic public Tweener Tweener; public GameTime GameTime; - public int BoardSize; } \ No newline at end of file diff --git a/Code/UI/Systems/RestartButtonClickedTracker.cs b/Code/UI/Systems/RestartButtonClickedTracker.cs index c22373b..f21e8af 100644 --- a/Code/UI/Systems/RestartButtonClickedTracker.cs +++ b/Code/UI/Systems/RestartButtonClickedTracker.cs @@ -10,14 +10,11 @@ public class RestartButtonClickedTracker : IEcsRunSystem private readonly EcsFilterInject> _gameEnd = default; private readonly EcsFilterInject> _button = default; - private readonly EcsPoolInject _gameStartPool = default; - - private readonly EcsWorldInject _world = default; - private readonly Action OnRestart; + private readonly Action _onRestart; public RestartButtonClickedTracker(Action onRestart) { - OnRestart = onRestart; + _onRestart = onRestart; } public void Run(IEcsSystems systems) @@ -34,7 +31,7 @@ public void Run(IEcsSystems systems) ref var button = ref _button.Pools.Inc1.Get(entity); if (button.Button.Bounds.Contains(mouseState.Position)) { - OnRestart?.Invoke(); + _onRestart?.Invoke(); } } } diff --git a/README.md b/README.md index 06efe3e..84839dd 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Monomatch3 +# MonoMatch3 Simple Match-3 game written with MonoGame and LeoECSLite ## Based on