-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnemy.cpp
More file actions
40 lines (33 loc) · 743 Bytes
/
Enemy.cpp
File metadata and controls
40 lines (33 loc) · 743 Bytes
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
#include "Enemy.h"
Enemy::Enemy(SDL_Renderer* renderer, int x, int y)
{
this->renderer = renderer;
current_texture = 0;
textures.push_back(IMG_LoadTexture(renderer, "assets/enemy1.png"));
textures.push_back(IMG_LoadTexture(renderer, "assets/enemy2.png"));
rect.x = x;
rect.y = y;
SDL_QueryTexture(textures[0], NULL, NULL, &rect.w, &rect.h);
frame=0;
}
Enemy::~Enemy()
{
//dtor
}
void Enemy::draw()
{
SDL_RenderCopy(renderer, textures[current_texture], NULL, &rect);
}
void Enemy::logic()
{
rect.x-=1;
if(rect.x==-100)
rect.x=500;
if(frame%10==0)
{
current_texture++;
if(current_texture>=textures.size())
current_texture=0;
}
frame++;
}