-
Notifications
You must be signed in to change notification settings - Fork 0
/
bubbles.cpp
executable file
·88 lines (82 loc) · 2.42 KB
/
bubbles.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
#include <SDL/SDL_image.h>
#include <SDL/SDL_rotozoom.h>
#include <ctime>
#include "base/func_tool.h"
#include "bubbles.h"
Bubbles::Bubbles(SDL_Rect* v, SDL_Rect fan_rect, int sens, int min_tar, int max_tar):
m_sens(sens), viewport(v)
{
int s = ((sens==DROITE or sens==BAS)?1:-1);
type.push_back("Bubble");
image = rotozoomSurface(IMG_Load("images/Other/Dust Particle.png"), 0, 10.0/(randint(15, 25)), true);
if (!image)
{
std::cerr << IMG_GetError();
exit(EXIT_FAILURE);
}
rect.w = rect.h = image->h;
acc = s*0.05;
// vertical
if (sens==HAUT or sens==BAS)
{
fan_rect.w = 32;
fan_rect.h = 8;
if (sens == HAUT)
y = fan_rect.y - rect.h;
else
y = fan_rect.y + fan_rect.h;
x_vel = ((rand()%2)?1:-1)*0.5;
y_vel = s*1.5;
l_bound = fan_rect.x;
u_bound = fan_rect.x+fan_rect.w - rect.w;
x = randint(l_bound, u_bound);
target = y+s*randint(min_tar, max_tar);
}
// horizontal
else if (sens==GAUCHE or sens==DROITE)
{
fan_rect.w = 8;
fan_rect.h = 32;
if (sens == DROITE)
x = fan_rect.x+fan_rect.w;
else
x = fan_rect.x-rect.w;
x_vel = s*1.5;
y_vel = ((rand()%2)?1:-1)*0.5;
l_bound = fan_rect.y;
u_bound = fan_rect.y+fan_rect.h - rect.h;
y = randint(l_bound, u_bound);
target = x+s*randint(min_tar, max_tar);
}
cinematic = (max_tar-min_tar <= 30);
}
void Bubbles::update()
{
if ( (m_sens==HAUT and y<=target) or (m_sens==BAS and y>=target) or
(m_sens==GAUCHE and x<=target) or (m_sens==DROITE and x>=target) )
kill();
// vertical
if (m_sens==HAUT or m_sens==BAS)
{
if ((x_vel<0 and x<l_bound) or (x_vel>0 and get_right()>u_bound))
x_vel *= -1;
}
// horizontal
else if (m_sens==DROITE or m_sens==GAUCHE)
{
if ((y_vel<0 and y<l_bound) or (y_vel>0 and get_bottom()>u_bound))
y_vel *= -1;
}
x += x_vel;
y += y_vel;
if (m_sens==DROITE or m_sens==GAUCHE)
x_vel += acc;
else if (m_sens==HAUT or m_sens==BAS)
y_vel += acc;
}
void Bubbles::draw(SDL_Surface* screen)
{
rect.x = Sint16(x-viewport->x);
rect.y = Sint16(y-viewport->y);
SDL_BlitSurface(image, NULL, screen, &rect);
}