summaryrefslogtreecommitdiffstats
path: root/KeyboardController.cpp
blob: a6f0ec33fbe3d8cf94f431563f3917e9de609818 (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* pPlayer, uint leftKey, uint rightKey):
	Controller(pPlayer),
	m_leftKey(leftKey),
	m_rightKey(rightKey)
{
	m_nextMove = NO_MOVE;
}

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_pPlayer->turnLeft();
	}
	else if (m_nextMove == MOVE_RIGHT)
	{
		m_pPlayer->turnRight();
	}
	m_nextMove = NO_MOVE;
}

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

KeyboardController::~KeyboardController(void)
{
}