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.1Pawngetting all togetherProject Included

butterflies.pwn

Example: butterflies.pwn

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