aboutsummaryrefslogtreecommitdiff
path: root/src/game.cpp
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-03-21 13:22:38 +0100
committerCharles <sircharlesaze@gmail.com>2020-03-21 13:22:38 +0100
commitad8ae988ba1928af5063ca1dc7375356e467979b (patch)
tree27a6738ff0172e4ebdaed7174cd7b47cc3ec9d59 /src/game.cpp
parent88f5eb3447073fc6a87786da6a9b6b788f9bde66 (diff)
downloadmario_sokoban-ad8ae988ba1928af5063ca1dc7375356e467979b.tar.gz
mario_sokoban-ad8ae988ba1928af5063ca1dc7375356e467979b.tar.bz2
mario_sokoban-ad8ae988ba1928af5063ca1dc7375356e467979b.zip
Sprites loading and display, player move
Diffstat (limited to 'src/game.cpp')
-rw-r--r--src/game.cpp34
1 files changed, 30 insertions, 4 deletions
diff --git a/src/game.cpp b/src/game.cpp
index 3e94883..88ff394 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -6,8 +6,8 @@
#define PAYLOAD_CHAR '*'
#define MARIO_CHAR 'm'
-#include <iostream>
Game::Game(std::string fmt)
+ : m_playerDirection(DirectionDown)
{
size_t p;
@@ -35,10 +35,12 @@ Game::Game(std::string fmt)
m_grid[i][j] = CellPayload;
break;
case MARIO_CHAR:
+ m_grid[i][j] = CellEmpty;
m_playerPos.y = i;
m_playerPos.x = j;
break;
default:
+ m_grid[i][j] = CellEmpty;
exit(1);
}
}
@@ -53,17 +55,41 @@ Game::~Game()
delete []m_grid;
}
-Game::Cell Game::get(int y, int x)
+void Game::move(Direction direction)
+{
+ m_playerDirection = direction;
+ switch (direction)
+ {
+ case DirectionUp:
+ m_playerPos.y--;
+ break;
+ case DirectionDown:
+ m_playerPos.y++;
+ break;
+ case DirectionLeft:
+ m_playerPos.x--;
+ break;
+ case DirectionRight:
+ m_playerPos.x++;
+ }
+}
+
+Game::Cell Game::get(int y, int x) const
{
return m_grid[y][x];
}
-size_t Game::getHeight()
+size_t Game::getHeight() const
{
return m_height;
}
-size_t Game::getWidth()
+size_t Game::getWidth() const
{
return m_width;
}
+
+Game::Position const &Game::getPlayer() const
+{
+ return m_playerPos;
+}