Skip to content

Commit

Permalink
Merge pull request #2 from Apostrov/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Apostrov authored Feb 24, 2023
2 parents 4c3d0e2 + ff8f3c7 commit 6c0150f
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 43 deletions.
7 changes: 3 additions & 4 deletions Code/DrawLogic/DrawUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
11 changes: 5 additions & 6 deletions Code/DrawLogic/Systems/GameBoardDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
2 changes: 2 additions & 0 deletions Code/GameConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion Code/GameLogic/PiecePosition.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
namespace MonoMatch3.Code.GameLogic;
#nullable enable
namespace MonoMatch3.Code.GameLogic;

public struct PiecePosition
{
Expand Down
4 changes: 2 additions & 2 deletions Code/GameLogic/Systems/BonusSpawner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 3 additions & 5 deletions Code/GameLogic/Systems/FillBoardProcessing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions Code/GameLogic/Systems/GameBoardInit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions Code/GameLogic/Systems/PlayerClickedProcessing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ namespace MonoMatch3.Code.GameLogic.Systems;

public class PlayerClickedProcessing : IEcsRunSystem
{
private readonly EcsFilterInject<Inc<Components.GameplayState>> _gameplay;
private readonly EcsFilterInject<Inc<Components.GameplayState>> _gameplay = default;
private readonly EcsFilterInject<Inc<Components.GamePiece>, Exc<Components.DestroyPiece>> _pieces = default;
private readonly EcsFilterInject<Inc<Components.Selected>> _selected = default;
private readonly EcsFilterInject<Inc<Components.SwapWith>> _swapWait = default;
private readonly EcsFilterInject<Inc<Components.RearrangePiece>> _rearrangePiece = default;

private readonly EcsSharedInject<SharedData> _shared = default;
private readonly EcsWorldInject _world = default;

public void Run(IEcsSystems systems)
{
Expand Down
9 changes: 2 additions & 7 deletions Code/GameLogic/Systems/RearrangeBoardProcessing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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))
{
Expand Down Expand Up @@ -94,9 +94,4 @@ public void Run(IEcsSystems systems)
_fillBoard.Value.Add(_world.Value.NewEntity());
}
}

private void RearrangeBoard()
{

}
}
5 changes: 1 addition & 4 deletions Code/Match3Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ namespace MonoMatch3.Code
{
public class Match3Game : Game
{
private const int BOARD_SIZE = 8;

private readonly GraphicsDeviceManager _graphics;
private SpriteBatch _spriteBatch;

Expand All @@ -32,8 +30,7 @@ public Match3Game()
_sharedData = new SharedData
{
GraphicsDevice = GraphicsDevice,
Tweener = new Tweener(),
BoardSize = BOARD_SIZE
Tweener = new Tweener()
};
EcsInit();
}
Expand Down
1 change: 0 additions & 1 deletion Code/SharedData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@ public class SharedData
// game logic
public Tweener Tweener;
public GameTime GameTime;
public int BoardSize;
}
9 changes: 3 additions & 6 deletions Code/UI/Systems/RestartButtonClickedTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@ public class RestartButtonClickedTracker : IEcsRunSystem
private readonly EcsFilterInject<Inc<GameLogic.Components.GameEndState>> _gameEnd = default;
private readonly EcsFilterInject<Inc<Components.RestartButton>> _button = default;

private readonly EcsPoolInject<GameLogic.Components.GameStartState> _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)
Expand All @@ -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();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Monomatch3
# MonoMatch3
Simple Match-3 game written with MonoGame and LeoECSLite

## Based on
Expand Down

0 comments on commit 6c0150f

Please sign in to comment.