-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSprite.cpp
99 lines (74 loc) · 1.24 KB
/
Sprite.cpp
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include "Sprite.h"
Sprite::Sprite(Level *l, DrawEngine *de, int s_index, float x, float y, int i_lives)
{
drawArea = de;
pos.x = x;
pos.y = y;
spriteIndex = s_index;
numLives = i_lives;
facingPosition.x = 1;
facingPosition.y = 0;
classID = SPRITE_CLASSID;
level = l;
}
Sprite::~Sprite()
{
Erase(pos.x, pos.y);
}
Vector Sprite::GetPosition(void)
{
return pos;
}
float Sprite::GetX(void)
{
return pos.x;
}
float Sprite::GetY(void)
{
return pos.y;
}
void Sprite::AddLives(int num)
{
numLives += num;
}
int Sprite::GetLives(void)
{
return numLives;
}
bool Sprite::IsAlive(void)
{
return (numLives > 0);
}
bool Sprite::Move(float x, float y)
{
int xPos = (int)pos.x + x;
int yPos = (int)pos.y + y;
if (IsValidLevelMove(xPos, yPos))
{
Erase(pos.x, pos.y);
pos.x += x;
pos.y += y;
facingPosition.x = x;
facingPosition.y = y;
Draw(pos.x, pos.y);
return true;
}
return false;
}
void Sprite::Draw(float x, float y)
{
drawArea->DrawSprite(spriteIndex, (int) x, (int) y);
}
void Sprite::Erase(float x, float y)
{
drawArea->EraseSprite((int) x, (int) y);
}
bool Sprite::IsValidLevelMove(int xPos, int yPos)
{
if (level->level[xPos][yPos] != TILE_WALL)
return true;
return false;
}
void Sprite::IdleUpdate(void)
{
}