-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraphics.cpp
120 lines (97 loc) · 2.63 KB
/
graphics.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include "graphics.h"
Rect::Rect(float x, float y, float w, float h)
{
this->set_x(x);
this->set_y(y);
this->set_w(w);
this->set_h(h);
}
void Rect::init(float x, float y, float w, float h)
{
this->set_x(x);
this->set_y(y);
this->set_w(w);
this->set_h(h);
}
void Rect::init(Rect rect)
{
this->set_x(rect.get_x());
this->set_y(rect.get_y());
this->set_w(rect.get_w());
this->set_h(rect.get_h());
}
void Object::init(GameInterface* game, char* file, Rect rect)
{
this->game = game;
this->texture = NULL;
SDL_Surface* surface;
surface = IMG_Load(file);
this->texture = SDL_CreateTextureFromSurface(this->game->getRenderer(), surface);
SDL_FreeSurface(surface);
this->rect.init(rect);
}
void Object::draw() const
{
SDL_Rect t_rect;
t_rect.x = (int) (this->rect.get_x());
t_rect.y = (int) (this->rect.get_y());
t_rect.w = (int) (this->rect.get_w());
t_rect.h = (int) (this->rect.get_h());
SDL_RenderCopy(this->game->getRenderer(), this->texture, NULL, &(t_rect));
}
void Object::quit()
{
SDL_DestroyTexture(this->texture);
}
void Button::init(GameInterface* game, char* file, Rect rect, void (*action) (GameInterface*))
{
this->game = game;
this->but_body.init(game, file, rect);
this->action = action;
}
void Button::quit()
{
this->but_body.quit();
}
void PhObject::init(GameInterface* game, char* file, Rect rect)
{
this->init(game, file, rect, 0, 0, 0);
}
void PhObject::init(GameInterface* game, char* file, Rect rect, float vx, float vy, float vw)
{
this->game = game;
this->texture = NULL;
SDL_Surface* surface;
surface = IMG_Load(file);
this->texture = SDL_CreateTextureFromSurface(this->game->getRenderer(), surface);
SDL_FreeSurface(surface);
this->initial_rect.init(rect);
this->initial_vx = vx;
this->initial_vy = vy;
this->rect.init(rect);
this->set_vx(vx);
this->set_vy(vy);
this->set_vw(vw);
this->setAngle(0);
this->setLast_x(this->get_x());
this->setLast_y(this->get_y());
}
void PhObject::reset()
{
this->rect.init(this->initial_rect);
this->set_vx(this->initial_vx);
this->set_vy(this->initial_vy);
this->set_vw(0);
this->setAngle(0);
this->setLast_x(this->get_x());
this->setLast_y(this->get_y());
}
void PhObject::draw() const
{
SDL_Rect t_rect;
t_rect.x = (int) (this->rect.get_x());
t_rect.y = (int) (this->rect.get_y());
t_rect.w = (int) (this->rect.get_w());
t_rect.h = (int) (this->rect.get_h());
SDL_RenderCopyEx(this->game->getRenderer(), this->texture, NULL, &(t_rect), this->getAngle(), NULL, SDL_FLIP_NONE);
}