diff options
| author | fschildt <florian.schildt@protonmail.com> | 2025-10-01 14:08:24 +0200 | 
|---|---|---|
| committer | fschildt <florian.schildt@protonmail.com> | 2025-10-01 14:09:13 +0200 | 
| commit | c775ca6133d93ed97359a6a50bd94a5563c740de (patch) | |
| tree | 9d3efb1c7e7538ff9d5cae408d2c29f9dd3daeab /src/games/snake | |
| parent | 41c2e2ecfcccf62b3c646980dd283848e33a8134 (diff) | |
general refactoring, prepare breakout game
Diffstat (limited to 'src/games/snake')
| -rw-r--r-- | src/games/snake/Snake.cpp | 44 | ||||
| -rw-r--r-- | src/games/snake/Snake.hpp | 10 | 
2 files changed, 27 insertions, 27 deletions
diff --git a/src/games/snake/Snake.cpp b/src/games/snake/Snake.cpp index a5fd76c..4c6ca18 100644 --- a/src/games/snake/Snake.cpp +++ b/src/games/snake/Snake.cpp @@ -12,8 +12,8 @@ Snake::Snake()      m_LastMillisecondsSinceT0 = SDL_GetTicks();      m_TilesPerSecond = 4.0f; -    m_Direction = DIRECTION_RIGHT; -    m_LastAdvancedDirection = DIRECTION_RIGHT; +    m_Direction = right; +    m_LastAdvancedDirection = right;      m_MapWidth = 16;      m_MapHeight = 16; @@ -84,16 +84,16 @@ void Snake::MaybeMoveSnake(float dt_in_seconds) {          // find head_pos -        if (m_Direction == DIRECTION_UP) { +        if (m_Direction == up) {              head_pos.y += 1;          } -        else if (m_Direction == DIRECTION_DOWN) { +        else if (m_Direction == down) {              head_pos.y -= 1;          } -        else if (m_Direction == DIRECTION_RIGHT) { +        else if (m_Direction == right) {              head_pos.x += 1;          } -        else if (m_Direction == DIRECTION_LEFT) { +        else if (m_Direction == left) {              head_pos.x -= 1;          }          if ((head_pos.x < 0 || head_pos.x >= m_MapWidth) || @@ -162,31 +162,31 @@ void Snake::ProcessEventDuringResume(SDL_Event &event) {      switch (event.type) {      case SDL_EVENT_KEY_DOWN: {          if (event.key.key == SDLK_UP) { -            if (m_LastAdvancedDirection == DIRECTION_RIGHT || -                m_LastAdvancedDirection == DIRECTION_LEFT) +            if (m_LastAdvancedDirection == right || +                m_LastAdvancedDirection == left)              { -                m_Direction = DIRECTION_UP; +                m_Direction = up;              }          }          else if (event.key.key == SDLK_DOWN) { -            if (m_LastAdvancedDirection == DIRECTION_RIGHT || -                m_LastAdvancedDirection == DIRECTION_LEFT) +            if (m_LastAdvancedDirection == right || +                m_LastAdvancedDirection == left)              { -                m_Direction = DIRECTION_DOWN; +                m_Direction = down;              }          }          else if (event.key.key == SDLK_RIGHT) { -            if (m_LastAdvancedDirection == DIRECTION_UP || -                m_LastAdvancedDirection == DIRECTION_DOWN) +            if (m_LastAdvancedDirection == up || +                m_LastAdvancedDirection == down)              { -                m_Direction = DIRECTION_RIGHT; +                m_Direction = right;              }          }          else if (event.key.key == SDLK_LEFT) { -            if (m_LastAdvancedDirection == DIRECTION_UP || -                m_LastAdvancedDirection == DIRECTION_DOWN) +            if (m_LastAdvancedDirection == up || +                m_LastAdvancedDirection == down)              { -                m_Direction = DIRECTION_LEFT; +                m_Direction = left;              }          }          else if (event.key.key == SDLK_ESCAPE) { @@ -270,7 +270,7 @@ void Snake::Draw() {      /* draw map background */      V3F32 map_world_pos = {map_x, map_y, 0.0f};      V2F32 map_world_dim = {map_view_width, map_view_height}; -    RectF32 map_world_rect = { +    Rectangle map_world_rect = {          map_world_pos.x,          map_world_pos.y,          map_world_pos.x + map_world_dim.x, @@ -298,7 +298,7 @@ void Snake::Draw() {                  1.0f              };              V2F32 world_dim = local_dim; -            RectF32 world_rect = { +            Rectangle world_rect = {                  world_pos.x,                  world_pos.y,                  world_pos.x + world_dim.x, @@ -326,7 +326,7 @@ void Snake::Draw() {              1.0f          };          V2F32 world_dim = local_dim; -        RectF32 world_rect = { +        Rectangle world_rect = {              world_pos.x,              world_pos.y,              world_pos.x + world_dim.x, @@ -346,7 +346,7 @@ void Snake::Draw() {          1.0f      };      V2F32 dim = {bodypart_size, bodypart_size}; -    RectF32 rect = { +    Rectangle rect = {          pos.x,          pos.y,          pos.x + dim.x, diff --git a/src/games/snake/Snake.hpp b/src/games/snake/Snake.hpp index 1223cbe..51d98fb 100644 --- a/src/games/snake/Snake.hpp +++ b/src/games/snake/Snake.hpp @@ -1,7 +1,7 @@  #pragma once  #include <games/Game.hpp> -#include <basic/math.hpp> +#include <common/math.hpp>  #include <random> @@ -9,10 +9,10 @@  class Snake : public Game {  public:      enum Direction : int32_t { -        DIRECTION_UP, -        DIRECTION_DOWN, -        DIRECTION_LEFT, -        DIRECTION_RIGHT, +        up, +        down, +        left, +        right,      };  | 
