-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathObject.cpp
213 lines (181 loc) · 3.92 KB
/
Object.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#include "Object.h"
#ifndef LTEXTURE_H_INCLUDED
#include "LTexture.h"
#endif // LTEXTURE_H_INCLUDED
extern const int SCREEN_WIDTH;
extern const int SCREEN_HEIGHT;
//The window we'll be rendering to
extern SDL_Window* gWindow;
//The window renderer
extern SDL_Renderer* gRenderer;
//Scene textures
extern LTexture gFooTexture[5];
extern LTexture gWoodTexture;
extern LTexture gBatTexture;
extern LTexture gStrikeTexture;
extern LTexture gWarningTexture;
extern LTexture gShieldTexture;
Wood::Wood() :height(20){
mCollider.w = 0;
mCollider.h = 0;
mCollider.x = 0;
mCollider.y = 0;
}
Wood::Wood(int x,int y):height(20){
mCollider.x = x;
mCollider.y = y;
}
Bat::Bat() {
exist = false;
mCollider.w = 50;
mCollider.h = 50;
mCollider.x = -50;
mCollider.y = -50;
}
Bat::Bat(int x,int y){
mCollider.x = x;
mCollider.y = y;
}
Shield::Shield() {
mCollider.w = 50;
mCollider.h = 50;
mCollider.x = -50;
mCollider.y = -50;
}
void Wood::Init(int type)
{
if(type == 1){
mCollider.x = 0;
mCollider.y = 0;
mCollider.w = 75+(rand()%75);
mCollider.h = height;
}
if(type == 2){
mCollider.x = 175+(rand()%75);
mCollider.y = 0;
mCollider.w = 75+rand()%(250-mCollider.x);
mCollider.h = height;
}
if(type == 3){
mCollider.w = 75+rand()%75;
mCollider.x = 500-mCollider.w;
mCollider.y = 0;
mCollider.h = height;
}
}
Thunder::Thunder()
{
strike = false;
exist = false;
cnt = 0;
mCollider.w = 30 + rand()%40;
mCollider.x = rand()%(SCREEN_WIDTH-mCollider.w);
mCollider.y = 0;
mCollider.h = 0;
}
void Wood::render() {
//Show the dot
gWoodTexture.render( mCollider.x, mCollider.y,&mCollider);
}
void Wood::reset()
{
mCollider.x = 0;
mCollider.y = -height;
mCollider.w = 0;
mCollider.h = height;
}
void Wood::operator+=(int t)
{
mCollider.y += t;
return ;
}
void Bat::render() {
//Show the dot
gBatTexture.render( mCollider.x, mCollider.y,&mCollider);
}
void Bat::init()
{
exist = true;
if(rand()%2==1){
mCollider.x = 0;
mCollider.y = 750;
}
else{
mCollider.x = 450;
mCollider.y = 750;
}
}
void Bat::reset()
{
exist = false;
mCollider.x = -50;
mCollider.y = -50;
}
void Bat::operator+=(int &direction)
{
if(mCollider.x>=450) direction = -1;
else if(mCollider.x<=0) direction = 1;
mCollider.x += direction;
mCollider.y -= 1;
return ;
}
void Bat::operator=(Bat &temp)
{
this->mCollider.x = temp.mCollider.x;
this->mCollider.y = temp.mCollider.y;
this->mCollider.h = temp.mCollider.h;
this->mCollider.w = temp.mCollider.w;
return ;
}
Thunder& Thunder::operator++()
{
cnt++;
if(cnt >= 100 && cnt<150)
{
strike = true;
mCollider.h = SCREEN_HEIGHT/2;
}
else if(cnt >= 150 && cnt < 250)
{
mCollider.h = SCREEN_HEIGHT;
}
else if(cnt == 250) this->reset();
return *this;
}
void Thunder::reset()
{
strike = false;
exist = false;
cnt = 0;
mCollider.w = 30 + rand()%40;
mCollider.x = rand()%(SCREEN_WIDTH-mCollider.w);
mCollider.h = 0;
}
void Thunder::render(){
if(strike && exist) gStrikeTexture.render(mCollider.x, 0, &mCollider);
else if(exist)
{
SDL_Rect pic = {mCollider.x, 50, 50, 50};
gWarningTexture.render(mCollider.x, 50, &pic);
}
}
void Shield::init()
{
mCollider.x = rand()%450;
mCollider.y = 0;
exist = true;
}
void Shield::reset()
{
mCollider.x = -50;
mCollider.y = -50;
}
void Shield::operator+=(int t)
{
mCollider.y += t;
return ;
}
void Shield::render() {
//Show the dot
gShieldTexture.render( mCollider.x, mCollider.y,&mCollider);
}