From e839c1283a090d480e0d63195d37180f6e5c01ca Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Mon, 18 Feb 2013 23:09:05 -0500 Subject: [PATCH] store current movements as array --- src/game.d | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/src/game.d b/src/game.d index 40c8c68..1dc00e7 100644 --- a/src/game.d +++ b/src/game.d @@ -6,7 +6,8 @@ enum MOVE_LEFT, MOVE_RIGHT, MOVE_UP, - MOVE_DOWN + MOVE_DOWN, + MOVE_COUNT } struct Player @@ -31,33 +32,19 @@ public: } void handle_move_event(int type, bool active) { - final switch (type) - { - case MOVE_LEFT: - m_left = active; - break; - case MOVE_RIGHT: - m_right = active; - break; - case MOVE_UP: - m_up = active; - break; - case MOVE_DOWN: - m_down = active; - break; - } + m_movements[type] = active; } void update(uint ms) { while (ms > (m_last_tick_ms + TICK_MS)) { - if (m_left) + if (m_movements[MOVE_LEFT]) m_players[m_pindex].x -= MOVE_PER_TICK; - if (m_right) + if (m_movements[MOVE_RIGHT]) m_players[m_pindex].x += MOVE_PER_TICK; - if (m_up) + if (m_movements[MOVE_UP]) m_players[m_pindex].y += MOVE_PER_TICK; - if (m_down) + if (m_movements[MOVE_DOWN]) m_players[m_pindex].y -= MOVE_PER_TICK; m_last_tick_ms += TICK_MS; m_tick++; @@ -65,10 +52,7 @@ public: } Player[] get_players() { return m_players; } protected: - bool m_left; - bool m_right; - bool m_up; - bool m_down; + bool m_movements[MOVE_COUNT]; uint m_tick; uint m_last_tick_ms; Player[2] m_players;