summaryrefslogtreecommitdiffstats
path: root/KeyboardController.cpp
blob: 856be38a809a11f72d126a0118b04a4ef5e376b1 (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
#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;
}


KeyboardController::~KeyboardController(void)
{
}