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
|
#include "character.h"
Character::Character(Level *lvl, DrawEngine *de, int s_index, float x, float y, int lives,
char u, char d, char l, char r)
: Sprite(lvl, de, s_index, x, y, lives)
{
up_key = u;
down_key = d;
left_key = l;
right_key = r;
classID = CHARACTER_CLASSID;
}
bool Character::keyPress(char c)
{
if (c == up_key)
{
return move(0, -1);
}
else if (c == down_key)
{
return move(0, 1);
}
else if ( c == right_key)
{
return move(1, 0);
}
else if (c == left_key)
{
return move(-1, 0);
}
return false;
}
void Character::addLives(int num)
{
Sprite::addLives(num);
if (Sprite::isAlive())
{
pos.x = 1;
pos.y = 1;
move(0,0);
}
}
|