-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnemy.cpp
More file actions
94 lines (69 loc) · 1.3 KB
/
Copy pathEnemy.cpp
File metadata and controls
94 lines (69 loc) · 1.3 KB
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
#include "Enemy.h"
enemy::enemy(SDL_Renderer* r)
{
re = r;
SDL_Log("Enemy Constructed");
Init();
}
enemy::~enemy()
{
SDL_Log("Enemy Destructed");
}
void enemy::Init()
{
surface = IMG_Load("content/Alien/alien.png");
tex = SDL_CreateTextureFromSurface(re, surface);
SDL_FreeSurface(surface);
xFrameIndex = 0;
yFrameIndex = 0;
enemySize = 50;
srcRect.x = 27 * xFrameIndex;
srcRect.y = 53 * yFrameIndex;
srcRect.w = 27;
srcRect.h = 53;
dstRect.x = 500;
dstRect.y = 500;
dstRect.h = enemySize+25;
dstRect.w = enemySize;
up = false;
down = false;
left = false;
right = false;
}
void enemy::Update(SDL_Rect playerRect)
{
if(dstRect.x < playerRect.x)
{
dstRect.x = dstRect.x + speed;
}
if(dstRect.y < playerRect.y)
{
dstRect.y = dstRect.y + speed;
}
if (dstRect.x > playerRect.x)
{
dstRect.x = dstRect.x - speed;
}
if (dstRect.y > playerRect.y)
{
dstRect.y = dstRect.y - speed;
}
Animate();
}
void enemy::Render()
{
SDL_RenderCopy(re, tex, &srcRect, &dstRect);
}
void enemy::Animate()
{
//int sheet[99] = { {0,0}, {0,1}, {0,2}, {1,0} };
unsigned int ticks = SDL_GetTicks();
unsigned int changeTimeMS = 200;
int changer = (ticks / changeTimeMS) % 4;
xFrameIndex = sheet[changer][0];
yFrameIndex = sheet[changer][1];
}
bool enemy::collision()
{
return false;
}