WOWCube Docs logo
WOWCube Docs
Mission Control
Section Shortcuts
APIExamplesSourceWOWConnectChangelog
Filters
SDK and language defaults persist in cookies.
SDK version
Navigation Tree
Collapsed by default, focused on the active path.
Made byMcKay Seamons
GitHub
  1. Home
  2. Docs
  3. Examples
  4. butterflies.pwn
Mission NodeSDK 6.3Pawngetting all togetherProject Included

butterflies.pwn

Example: butterflies.pwn

Examples / SDK 6.3 / Pawn / getting all together / Butterflies - The Game / project / src
butterflies.pwn
C
1#pragma warning disable 203
2#pragma warning disable 213
3#pragma warning disable 229
4
5// #define LEVEL_DESIGN
6
7#define G2D
8
9#include "math.inc"
10#include "wowcore.inc"
11#include "motion_sensor.inc"
12#include "sound.inc"
13#include "splashscreen.inc"
14#include "splashscreen_user_defined.inc"
15#include "log.inc"
16
17#include "butterflies_vars.inc"
18#include "butterflies_map.inc"
19#include "butterflies_func.inc"
20
21public ON_PhysicsTick() {
22
23 if (!application.is_loaded) return;
24
25 CalcGameLogic();
26}
27public ON_Render() {
28
29 if (!application.is_loaded) return;
30
31 if (application.is_splash) {
32 ssON_Render();
33 } else {
34 switch (application.mode) {
35 case mode_selector: {
36 DrawSelector();
37 }
38 case mode_classic: {
39 DrawClassic();
40 }
41 case mode_endless: {
42 DrawEndless();
43 }
44 case mode_time_trial: {
45 DrawTimeTrial();
46 }
47 }
48 }
49}
50public ON_Tick() {
51
52 if (!application.is_loaded) return;
53
54 TestCompleteWings();
55
56 if (0 == SELF_ID) {
57
58 if ((application.count_to_generate != 0) && ((application.mode == mode_endless) || (application.mode == mode_time_trial))) {
59 if (GenerateButterly(application.count_to_generate))
60 application.count_to_generate = 0;
61 }
62 if ((application.is_change_level) && (!application.is_splash)) {
63 SetLevel();
64 }
65 }
66
67
68
69 CalcGameLogicTick();
70
71 SendMapping();
72 SendInfo();
73 SendSplashScreenData();
74}
75public ON_Load(id, size, const pkt[]) {
76 application.is_loaded = true;
77 if (size != 0) {
78 for (new i = 0; i < GAME_SAVE_SIZE; i++)
79 save_data[i] = pkt[i];
80 DeSerializeSaveData();
81 if (last_results[mode_classic].score > 0)
82 application.is_has_saves_classic = true;
83 if (last_results[mode_endless].total > 0)
84 application.is_has_saves_endless = true;
85 if (last_results[mode_time_trial].total > 0)
86 application.is_has_saves_time_trial = true;
87 }
88
89}
90public ON_Init(id, size, const pkt[]) {
91
92 if (0 == SELF_ID) {
93 loadState();
94 }
95
96 application.mode = mode_selector;
97 last_results[mode_classic].level = application.level = -1;
98 application.twist = -1;
99 application.is_loaded = false;
100 application.count_to_generate = 0;
101
102 application.is_splash = false;
103 application.is_set_splash = false;
104 application.is_has_saves_classic = false;
105 application.is_has_saves_endless = false;
106 application.is_has_saves_time_trial = false;
107
108 application.is_game_over = false;
109
110 application.is_get_mapping = false;
111 application.score = 0;
112 application.titres_plane = TOPOLOGY_FACES_MAX;
113
114 // SetInitData();
115 for (new moduleI = 0; moduleI < MODULES_MAX; moduleI++)
116 for (new screenI = 0; screenI < SCREENS_MAX; screenI++) {
117 mapping[moduleI][screenI].is_wing = false;
118 mapping[moduleI][screenI].color = color_wings_max;
119 }
120}
121public ON_Packet(type, size, const pkt[]) {
122 switch (type) {
123 case cmd_info: {
124 DeSerializeInfo(pkt);
125 }
126 case cmd_mapping: {
127 DeSerializeMapping(pkt);
128 }
129 case cmd_send_splash: {
130 DeSerializeSplashScreenData(pkt);
131 }
132 }
133}
134public ON_Twist(twist[TOPOLOGY_TWIST_INFO]) {
135
136
137 if (0 == SELF_ID) {
138
139 if ((application.mode != mode_selector) && (application.is_splash)) {
140 application.is_set_back = false;
141 application.is_splash = false;
142 application.twist = 0;
143
144 application.time_start = getTime();
145 application.time_finish = getTime();
146
147 application.is_complete = false;
148
149 application.is_change_level = true;
150 application.is_generate = false;
151 application.is_get_mapping = false;
152 if (application.mode == mode_endless && application.is_has_saves_endless) {
153 total_butterflies.total = last_results[mode_endless].total;
154 }
155
156 if (application.mode == mode_time_trial) {
157 SND_play(snd_round_start, snd_volume);
158 } else if (application.mode == mode_endless) {
159 SND_play(snd_mode_launch, snd_volume);
160 }
161 } else if (application.mode == mode_endless || (application.mode == mode_time_trial && !application.is_game_over)) {
162
163 application.is_complete = false;
164 application.twist++;
165 application.is_assembled_endless = false;
166 application.is_set_score = false;
167
168 for (new moduleI = 0; moduleI < MODULES_MAX; moduleI++) {
169 for (new screenI = 0; screenI < SCREENS_MAX; screenI++) {
170 if (is_fly[moduleI][screenI] || application.is_game_over) {
171 mapping[moduleI][screenI].is_wing = false;
172 }
173 is_fly[moduleI][screenI] = false;
174 }
175 }
176
177 if (application.twist % count_twists_to_generate == 0)
178 application.count_to_generate = count_butterflies_to_generate;
179
180 } else if (application.mode == mode_classic) {
181 if (application.is_complete) {
182 application.is_change_level = true;
183 application.score = 0;
184 application.twist = 0;
185 application.is_generate = false;
186 application.is_get_mapping = false;
187 } else {
188 application.twist++;
189 }
190 }
191 }
192
193 for (new moduleI = 0; moduleI < MODULES_MAX; moduleI++) {
194 for (new screenI = 0; screenI < SCREENS_MAX; screenI++) {
195 is_fly[moduleI][screenI] = false;
196 }
197 }
198}
199public ON_Quit() {
200 if (0 != SELF_ID) return;
201
202 if ((application.mode != mode_selector) && (!application.is_splash))
203 SaveData();
204
205}
206public ON_Pat(const count, const display, const bool:opposite) {
207
208 if (0 != SELF_ID) return;
209
210 if ((application.mode == mode_time_trial) && (application.is_game_over) && count >= selector_pat) {
211 // application.is_game_over = false;
212 application.seconds = start_time_trial;
213 application.count_to_generate = 0;
214 total_butterflies.total = 0;
215 application.twist = 0;
216 application.is_change_level = true;
217 application.score = 0;
218
219 application.is_get_mapping = false;
220 application.is_generate = false;
221 SND_play(snd_round_start, snd_volume);
222
223 } else if (application.is_splash && count >= splash_pat) {
224
225 if (((application.is_has_saves_classic) && (application.mode == mode_classic)) ||
226 ((application.is_has_saves_endless) && (application.mode == mode_endless))
227 ) {
228 application.is_splash = false;
229 application.is_change_level = true;
230 if (application.mode == mode_classic) {
231 application.level = -1;
232 application.score = 0;
233 last_results[mode_classic].score = 0;
234 last_results[mode_classic].time = 0;
235 last_results[mode_classic].level = -1;
236 } else if (application.mode == mode_endless) {
237 total_butterflies.total = 0;
238 last_results[mode_endless].time = 0;
239 last_results[mode_endless].twists = 0;
240 last_results[mode_endless].total = 0;
241
242 SND_play(snd_mode_launch, snd_volume);
243 }
244 } else if (application.mode == mode_time_trial) {
245 total_butterflies.total = 0;
246 total_butterflies.total_current = 0;
247 application.score = 0;
248 application.is_game_over = false;
249 last_results[mode_time_trial].score = 0;
250 last_results[mode_time_trial].time = 0;
251 last_results[mode_time_trial].total = 0;
252 // SND_play(snd_round_start, snd_volume);
253 }
254
255
256 if (application.mode != mode_endless) {
257 for (new planeI = 0; planeI < TOPOLOGY_FACES_MAX; planeI++) {
258 for (new posI = 0; posI < TOPOLOGY_POSITIONS_MAX; posI++) {
259 facelet_info = TOPOLOGY_getFacelet(SetPlace(planeI, posI));
260 mapping[facelet_info.module][facelet_info.screen].is_wing = false;
261 }
262 }
263 }
264 } else if (application.mode == mode_selector && count >= selector_pat) {
265 application.mode = TOPOLOGY_getFace(ORIENTATION_UP) % (modes_max - 1) + 1;
266 application.time_launch = getTime();
267 application.is_change_level = true;
268
269 application.is_splash = true;
270 SetSplashScreenData();
271 if (application.mode == mode_time_trial) {
272 SND_play(snd_mode_launch, snd_volume);
273 }
274 }
275}
Wrapped for easier reading. Turn wrap off to inspect exact line lengths.
Context Rail

Project files

butterflies.pwn
project/src/butterflies.pwn
wowcubeapp-build.json
project/wowcubeapp-build.json
Context Rail

Related nodes

Butterflies - The Game
Examples / SDK 6.3 / Pawn / getting all together
info.json
Examples / SDK 6.3 / Pawn / getting all together / Butterflies - The Game
wowcubeapp-build.json
Examples / SDK 6.3 / Pawn / getting all together / Butterflies - The Game / project
Butterflies - The Game
Examples / SDK 6.1 / Pawn / getting all together
Previous Node
info.json
Examples / SDK 6.3 / Pawn / getting all together / Butterflies - The Game
Next Node
wowcubeapp-build.json
Examples / SDK 6.3 / Pawn / getting all together / Butterflies - The Game / project