-
Notifications
You must be signed in to change notification settings - Fork 0
/
cbombs.cpp
84 lines (73 loc) · 2.33 KB
/
cbombs.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
#include "cbombs.h"
cbombs::cbombs(SDL_Renderer *rnd, int x, int y, int *size)
{
m_x=x;
m_y=y;
m_size= *size;
s_segment=new sprite(rnd,"GFX/Snake_body.png");
s_segment->createFrame(15,1);
s_segment->setXY(m_x,m_y);
s_explosion=new sprite(rnd,"GFX/Snake_body_splat.png");
s_explosion->createFrame(11,1);
s_explosion2=new sprite(rnd,"GFX/Blood.png");
s_explosion2->createFrame(70,1);
m_offset=SDL_GetTicks();
snd_splat=Mix_LoadWAV("SND/Splat.wav");
}
void cbombs::update(snake *snake)
{
curTime=SDL_GetTicks()-m_offset;
if (_collision.rect({snake->getX(),snake->getY(),m_size,m_size},{m_x,m_y,m_size,m_size})==1)
snake->setDead(true);
if (state==0)
{
if ((curTime/1000)>=3)
{
state=1;
s_explosion->resetOneShot();
Mix_PlayChannel(-1,snd_splat,0);
}
s_segment->setXY(m_x,m_y);
s_segment->drawFrames(0);
}
if (state==1)
{
s_explosion->setXY(m_x,m_y);
s_explosion->drawOneShot(0);
s_explosion2->setXY(m_x+m_size,m_y);
s_explosion2->drawOneShot(0);
s_explosion2->setXY(m_x-m_size,m_y);
s_explosion2->drawOneShot(0);
s_explosion2->setXY(m_x,m_y+m_size);
s_explosion2->drawOneShot(0);
s_explosion2->setXY(m_x,m_y-m_size);
s_explosion2->drawOneShot(0);
if (_collision.rect({snake->getX(),snake->getY(),m_size,m_size},{m_x,m_y,m_size,m_size})==1)
snake->setDead(true);
if (_collision.rect({snake->getX(),snake->getY(),m_size,m_size},{m_x+m_size,m_y,m_size,m_size})==1)
snake->setDead(true);
if (_collision.rect({snake->getX(),snake->getY(),m_size,m_size},{m_x+m_size,m_y,m_size,m_size})==1)
snake->setDead(true);
if (_collision.rect({snake->getX(),snake->getY(),m_size,m_size},{m_x,m_y-m_size,m_size,m_size})==1)
snake->setDead(true);
if (_collision.rect({snake->getX(),snake->getY(),m_size,m_size},{m_x,m_y+m_size,m_size,m_size})==1)
snake->setDead(true);
if(s_explosion->getCurrentFrame()==s_explosion->getMaxFrames()-1)
m_dead=true;
}
}
void cbombs::setX(int X)
{
m_x=X;
}
void cbombs::setY (int Y)
{
m_y=Y;}
void cbombs::setDead(bool dead)
{
m_dead=dead;
}
bool cbombs::getDead()
{
return m_dead;
}