-
Notifications
You must be signed in to change notification settings - Fork 0
/
DoubleGame.cpp
293 lines (264 loc) · 8.65 KB
/
DoubleGame.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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
#include "all.h"
#include "Game.h"
//updated at 2014/7/10
//已整理
//--------------------------------------------------------------
void DoubleGame::setup(){
scene = 2000;
bg.loadImage("image/welcome.jpg");
bg.resize(ofGetWindowWidth(),ofGetWindowHeight());
// choose player
FANG.loadImage("image/FANG.PNG");
FANG.resize(150,150);
BEI.loadImage("image/BEI.PNG");
BEI.resize(150,150);
CHUNG.loadImage("image/CHUNG.PNG");
CHUNG.resize(150,150);
HSUN.loadImage("image/SHUN.PNG");
HSUN.resize(150,150);
GUANG.loadImage("image/GUANG.PNG");
GUANG.resize(150,150);
//choose arena
b1.loadImage("image/b1.jpg");
b1.resize(150,150);
b2.loadImage("image/b2.jpg");
b2.resize(150,150);
b3.loadImage("image/b3.jpg");
b3.resize(150,150);
b4.loadImage("image/b4.jpg");
b4.resize(150,150);
b5.loadImage("image/b5.jpg");
b5.resize(150,150);
//initialize
p1 = 0,p2 = 0,arena = 0;
bGameChoosed = false;
b_p1Choosed = false;
b_p2Choosed = false;
bStageChoosed = false;
first = true; //used for the game setup
/*如果說,沒有做這個動作,在game內就會重複用一個pearlMap,就會出現那個bomb時消了兩個,fallDown卻只用一個的bug*/
//setup font
ofTrueTypeFont::setGlobalDpi(72);
title.loadFont("COOLSLIP.ttf",50,1,1);
title.setLineHeight(18.0f);
title.setLetterSpacing(1.037);
text.loadFont("COOLSLIP.ttf",35,1,1);
}
//--------------------------------------------------------------
void DoubleGame::update(int& scene){
if(b_p1Choosed == true && b_p2Choosed == true && bStageChoosed == true) //game前置動作已完成
{
if(bGameChoosed == false)//尚未進入遊戲
{ //game start
bGameChoosed = true;
_Game.setup(p1,p2,arena,first);
}
else
{
_Game.update();
if(_Game.getbGameFinished()){ //若遊戲結束...
//reset
p1 = 0,p2 = 0,arena = 0;
bGameChoosed = false;
b_p1Choosed = false;
b_p2Choosed = false;
bStageChoosed = false;
_Game.reset();//game 的reset
first = false;//代表至少已經進過遊戲一次了
scene = 0; //return to welcome
}
}
}
}
//--------------------------------------------------------------
void DoubleGame::draw(int& scene){
if(b_p1Choosed == false || b_p2Choosed == false || bStageChoosed == false) //option
{
//background
ofSetHexColor(0xffffff);
bg.draw(0,0);
ofSetHexColor(0xffff00);
//
title.drawString("* Choose player :",80,80);
title.drawString("* Choose arena :",80,400);
/*for choose player*/
ofSetHexColor(0x0000ff);
ofRect(50,140,150,200);
ofRect(250,140,150,200);
ofRect(450,140,150,200);
ofRect(650,140,150,200);
ofRect(850,140,150,200);
//being choosed
ofSetHexColor(0xff3333);
if(p1 == 1 || p2 == 1){ofRect(50,140,150,200);}
if(p1 == 2 || p2 == 2){ofRect(250,140,150,200);}
if(p1 == 3 || p2 == 3){ofRect(450,140,150,200);}
if(p1 == 4 || p2 == 4){ofRect(650,140,150,200);}
if(p1 == 5 || p2 == 5){ofRect(850,140,150,200);}
//photo
ofSetHexColor(0xffffff);
FANG.draw(50,140);
BEI.draw(250,140);
CHUNG.draw(450,140);
HSUN.draw(650,140);
GUANG.draw(850,140);
//name
ofSetHexColor(0xffff00);
text.drawString("FANG",63,330);
text.drawString("BEI",283,330);
text.drawString("CHUNG",450,330);
text.drawString("SHUN",663,330);
text.drawString("GUANG",850,330);
/*for choose arena*/
ofSetHexColor(0x0066ff);
ofRect(50,450,150,200);
ofRect(250,450,150,200);
ofRect(450,450,150,200);
ofRect(650,450,150,200);
ofRect(850,450,150,200);
//being choosed
ofSetHexColor(0xff3333);
if(arena == 1){ofRect(50,450,150,200);}
if(arena == 2){ofRect(250,450,150,200);}
if(arena == 3){ofRect(450,450,150,200);}
if(arena == 4){ofRect(650,450,150,200);}
if(arena == 5){ofRect(850,450,150,200);}
//photo
ofSetHexColor(0xffffff);
b1.draw(50,450);
b2.draw(250,450);
b3.draw(450,450);
b4.draw(650,450);
b5.draw(850,450);
}
else {_Game.draw();}
}
//--------------------------------------------------------------
void DoubleGame::keyPressed(int key,int& scene){
if(b_p1Choosed == true && b_p2Choosed == true && bStageChoosed ==true)
_Game.keyPressed(key);
}
//--------------------------------------------------------------
void DoubleGame::keyReleased(int key,int& scene){
if(b_p1Choosed == true && b_p2Choosed == true && bStageChoosed==true)
_Game.keyReleased(key);
}
//--------------------------------------------------------------
void DoubleGame::mouseMoved(int x, int y,int& scene){
if(b_p1Choosed == true && b_p2Choosed == true && bStageChoosed==true)
_Game.mouseMoved( x, y);
}
//--------------------------------------------------------------
void DoubleGame::mouseDragged(int x, int y, int button,int& scene){
if(b_p1Choosed == true && b_p2Choosed == true && bStageChoosed==true)
_Game.mouseDragged(x, y, button);
}
//--------------------------------------------------------------
void DoubleGame::mousePressed(int x, int y, int button,int& scene){
if(b_p1Choosed == false || b_p2Choosed == false || bStageChoosed == false) //option
{
if(b_p1Choosed == false) //choose player1
{
if(button == 0)
{
if(ofGetMouseX()>= 50&&ofGetMouseX()<= 200&& ofGetMouseY() >= 140&&ofGetMouseY()<=340){
b_p1Choosed = true;
p1 = 1;
}
if(ofGetMouseX()>= 250&&ofGetMouseX()<= 400&& ofGetMouseY() >= 140&&ofGetMouseY()<=340){
b_p1Choosed = true;
p1 = 2;
}
if(ofGetMouseX()>= 450&&ofGetMouseX()<= 600&& ofGetMouseY() >= 140&&ofGetMouseY()<=340){
b_p1Choosed = true;
p1 = 3;
}
if(ofGetMouseX()>= 650&&ofGetMouseX()<= 800&& ofGetMouseY() >= 140&&ofGetMouseY()<=340){
b_p1Choosed = true;
p1 = 4;
}
if(ofGetMouseX()>= 850&&ofGetMouseX()<= 1000&& ofGetMouseY() >= 140&&ofGetMouseY()<=340){
b_p1Choosed = true;
p1 = 5;
}
}
}
else
{
if(b_p2Choosed == false)//choose player2
{
if(button == 0)
{
if(ofGetMouseX()>= 50&&ofGetMouseX()<= 200&& ofGetMouseY() >= 140&&ofGetMouseY()<=340){
b_p2Choosed = true;
p2 = 1;
}
if(ofGetMouseX()>= 250&&ofGetMouseX()<= 400&& ofGetMouseY() >= 140&&ofGetMouseY()<=340){
b_p2Choosed = true;
p2 = 2;
}
if(ofGetMouseX()>= 450&&ofGetMouseX()<= 600&& ofGetMouseY() >= 140&&ofGetMouseY()<=340){
b_p2Choosed = true;
p2 = 3;
}
if(ofGetMouseX()>= 650&&ofGetMouseX()<= 800&& ofGetMouseY() >= 140&&ofGetMouseY()<=340){
b_p2Choosed = true;
p2 = 4;
}
if(ofGetMouseX()>= 850&&ofGetMouseX()<= 1000&& ofGetMouseY() >= 140&&ofGetMouseY()<=340){
b_p2Choosed = true;
p2 = 5;
}
}
}
if(bStageChoosed == false)//choose arena
{
if(button == 0)
{
if(ofGetMouseX()>= 50&&ofGetMouseX()<= 200&& ofGetMouseY() >= 450&&ofGetMouseY()<=600){
bStageChoosed = true;
arena = 1;
}
if(ofGetMouseX()>= 250&&ofGetMouseX()<= 400&&ofGetMouseY() >= 450&&ofGetMouseY()<=600){
bStageChoosed = true;
arena = 2;
}
if(ofGetMouseX()>= 450&&ofGetMouseX()<= 600&&ofGetMouseY() >= 450&&ofGetMouseY()<=600){
bStageChoosed = true;
arena = 3;
}
if(ofGetMouseX()>= 650&&ofGetMouseX()<= 800&& ofGetMouseY() >= 450&&ofGetMouseY()<=600){
bStageChoosed = true;
arena = 4;
}
if(ofGetMouseX()>= 850&&ofGetMouseX()<= 1000&&ofGetMouseY() >= 450&&ofGetMouseY()<=600){
bStageChoosed = true;
arena = 5;
}
}
}
}
}
if(bGameChoosed == true)
_Game.mousePressed(x,y,button);
}
//--------------------------------------------------------------
void DoubleGame::mouseReleased(int x, int y, int button,int& scene){
if(b_p1Choosed == true && b_p2Choosed == true && bStageChoosed==true)
_Game.mouseReleased(x,y, button);
}
//--------------------------------------------------------------
void DoubleGame::windowResized(int w, int h,int& scene){
if(b_p1Choosed == true && b_p2Choosed == true && bStageChoosed==true)
_Game.windowResized(w, h);
}
//--------------------------------------------------------------
void DoubleGame::gotMessage(ofMessage msg,int& scene){
if(b_p1Choosed == true && b_p2Choosed == true && bStageChoosed==true)
_Game.gotMessage( msg);
}
//--------------------------------------------------------------
void DoubleGame::dragEvent(ofDragInfo dragInfo,int& scene){
if(b_p1Choosed == true && b_p2Choosed == true && bStageChoosed==true)
_Game.dragEvent(dragInfo);
}