-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSprite.cpp
More file actions
90 lines (82 loc) · 2.39 KB
/
Sprite.cpp
File metadata and controls
90 lines (82 loc) · 2.39 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
#include "Sprite.h"
Sprite::Sprite(SDL_Renderer* renderer, string path, int frames,int align_x,int align_y,vector<Hitbox*>hitboxes,vector<Hitbox*>hurtboxes)
{
this->renderer = renderer;
texture = IMG_LoadTexture(renderer,path.c_str());
int w,h;
SDL_QueryTexture(texture,NULL,NULL,&w,&h);
rect.w=w;
rect.h=h;
rect.x=align_x;
rect.y=align_y;
this->frames = frames;
this->hitboxes=hitboxes;
this->hurtboxes=hurtboxes;
}
Sprite::~Sprite()
{
//dtor
}
void Sprite::draw(int character_x, int character_y, bool flipped)
{
SDL_Rect rect_temp;
rect_temp.w = rect.w;
rect_temp.h = rect.h;
if(flipped)
{
rect_temp.x = (-rect.x)+character_x-rect_temp.w/2;
rect_temp.y = rect.y+character_y-rect_temp.h;
}else
{
rect_temp.x = rect.x+character_x-rect_temp.w/2;
rect_temp.y = rect.y+character_y-rect_temp.h;
}
if(flipped)
{
SDL_RenderCopyEx( renderer, texture, NULL, &rect_temp,
NULL, NULL, SDL_FLIP_HORIZONTAL );
}else
{
SDL_RenderCopy(renderer, texture, NULL, &rect_temp);
}
for(int i=0;i<hitboxes.size();i++)
{
if(flipped)
{
drawRect(renderer,
-hitboxes[i]->rect.x-hitboxes[i]->rect.w+character_x,
-hitboxes[i]->rect.y+character_y,
hitboxes[i]->rect.w,
hitboxes[i]->rect.h,
255,0,0,0);
}else
{
drawRect(renderer,
hitboxes[i]->rect.x+character_x,
-hitboxes[i]->rect.y+character_y,
hitboxes[i]->rect.w,
hitboxes[i]->rect.h,
255,0,0,0);
}
}
for(int i=0;i<hurtboxes.size();i++)
{
if(flipped)
{
drawRect(renderer,
-hurtboxes[i]->rect.x-hurtboxes[i]->rect.w+character_x,
-hurtboxes[i]->rect.y+character_y,
hurtboxes[i]->rect.w,
hurtboxes[i]->rect.h,
0,0,255,0);
}else
{
drawRect(renderer,
hurtboxes[i]->rect.x+character_x,
-hurtboxes[i]->rect.y+character_y,
hurtboxes[i]->rect.w,
hurtboxes[i]->rect.h,
0,0,255,0);
}
}
}