summaryrefslogtreecommitdiffstats
path: root/KeyboardController.cpp
blob: 6ca58998edf7c45c84db6587bff5c41f2601a571 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "KeyboardController.h"

#include <iostream>

KeyboardController::KeyboardController(Player& player, uint leftKey, uint rightKey):
	Controller(player),
	m_leftKey(leftKey),
	m_rightKey(rightKey)
{
}

void KeyboardController::PressKey(KeyCode key)
{
	if (m_nextMove == NO_MOVE)
	{
		if (key == m_leftKey)
		{
			m_nextMove = MOVE_LEFT;
		}
		else if (key == m_rightKey)
		{
			m_nextMove = MOVE_RIGHT;
		}
	}
}

void KeyboardController::think()
{

	if (m_nextMove == MOVE_LEFT)
	{
		m_player.turnLeft();
	}
	else if (m_nextMove == MOVE_RIGHT)
	{
		m_player.turnRight();
	}
	m_nextMove = NO_MOVE;
}

void KeyboardController::reset()
{
	m_nextMove = NO_MOVE;
}

KeyboardController::~KeyboardController(void)
{
}