store current movements as array

This commit is contained in:
Josh Holtrop 2013-02-18 23:09:05 -05:00
parent 7f3185b26a
commit e839c1283a

View File

@ -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;