-
Notifications
You must be signed in to change notification settings - Fork 0
/
crobby.cpp
86 lines (74 loc) · 2.22 KB
/
crobby.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
#include "crobby.h"
crobby::crobby(SDL_Renderer *rnd, int *screenW, int *screenH,int *tileSize)
{
m_screenW=screenW;
m_screenH=screenH;
_rnd=rnd;
m_tileSize=tileSize;
s_robby=new sprite(_rnd,"GFX/Robby_break.png");
s_robby->createFrame(21,1);
s_robby_dance=new sprite(_rnd,"GFX/Robby_dance.png");
s_robby_dance->createFrame(5,1);
s_robby_bad=new sprite(_rnd,"GFX/Robby_break_bad.png");
s_robby_bad->createFrame(21,1);
s_robby_dance_bad=new sprite(_rnd,"GFX/Robby_dance_bad.png");
s_robby_dance_bad->createFrame(5,1);
snd_hurra= Mix_LoadWAV("SND/Hurra.wav");
}
void crobby::spawn()
{
m_x=rand()%*m_screenW-*m_tileSize;
m_y=rand()%*m_screenH-*m_tileSize;
s_robby->setXY(m_x,m_y);
s_robby_dance->setXY(m_x,m_y);
s_robby_bad->setXY(m_x,m_y);
s_robby_dance_bad->setXY(m_x,m_y);
m_robby_state=0;
cout << "ORB X: "<< m_x <<", Y: "<<m_y<<endl;
}
int crobby::getX(){return m_x;}
int crobby::getY(){return m_y;}
void crobby::draw(int bad_or_good)
{
m_bad_or_good=bad_or_good;
if (bad_or_good<3)
{
if (m_robby_state==0)
{
s_robby->resetOneShot();
s_robby_dance->resetOneShot();
m_robby_state=1;
}
if (m_robby_state==1)
{
s_robby->drawOneShot(0);
if (s_robby->getCurrentFrame()==s_robby->getMaxFrames()-1)
m_robby_state=2;
if (s_robby->getCurrentFrame()==13)
if(Mix_Playing(5)==0)
Mix_PlayChannel(5, snd_hurra,0);
}
if(m_robby_state==2)
s_robby_dance->drawFrames(0);
}
else
{
if (m_robby_state==0)
{
s_robby_bad->resetOneShot();
s_robby_dance_bad->resetOneShot();
m_robby_state=1;
}
if (m_robby_state==1)
{
s_robby_bad->drawOneShot(0);
if (s_robby_bad->getCurrentFrame()==s_robby->getMaxFrames()-1)
m_robby_state=2;
if (s_robby_bad->getCurrentFrame()==13)
if(Mix_Playing(5)==0)
Mix_PlayChannel(5, snd_hurra,0);
}
if(m_robby_state==2)
s_robby_dance_bad->drawFrames(0);
}
}