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. main.pwn
Mission NodeSDK 6.3PawnbasicsProject Included

main.pwn

Example: main.pwn

Examples / SDK 6.3 / Pawn / basics / Strings and Arrays / project / src
main.pwn
C
1// This PAWN script is generated by WOWCube SDK project wizard
2
3#define G2D
4
5#pragma warning disable 203
6#pragma warning disable 213
7#pragma warning disable 229
8
9// Includes
10// -----------------------------
11#include "wowcore.inc"
12#include "topology.inc"
13#include "graphics.inc"
14#include "fixed.inc"
15#include "motion_sensor.inc"
16#include "math.inc"
17#include "log.inc"
18#include "string.inc"
19
20// Application defines
21// -----------------------------
22#define TEXT_SIZE 10
23#define DISPLAY_HEIGHT 240
24
25// Application constants
26// ------------------------------
27new const Colors[.white, .black, .red, .green, .blue, .teal,.blue1, .blue2, .blue3, .pink1, .pink2, .pink3] =
28[
29 0xFFFFFFFF,
30 0xFF000000,
31 0xFFFF0000,
32 0xFF00FF00,
33 0xFF0000FF,
34 0xFF00FF99,
35 0xFF2828C8,
36 0xFF6464FF,
37 0xFF9696FF,
38 0xFFFF6464,
39 0xFF641E1E,
40 0xFF320F0F,
41];
42
43// Global variables and constants
44// ----------------------------
45new timer[.delay, .time]
46new timer2[.delay, .time]
47
48new arrayIndices[
49 .i1,
50 .i2
51 ];
52
53new buffers[
54 .buff[1], //character to string conversion
55 .buff2[4] //screen 1 text
56 ];
57
58new const arrWOWCUBE[8] = ['W','O','W','C','U','B','E',' ']; //array of characters
59
60new const arrWOWCUBE2[3]{10} = ["WOWCUBE","IS","COOL"]; //array of strings
61
62new const arrTWISTY[]{} = ["T","W","I","S","T","Y"]; //array of strings too
63new Fixed:fParam[] = [0 ,20 ,10 ,-10,-20,-10]; //fixed point parameters used to calculate vertical offsets of each letter
64new prevPos[][2] = [0,0,0,0,0,0,0,0,0,0,0,0]; //array of previous letter positions
65
66new firstFrame = 0;
67
68// WOWCube application callbacks
69// -----------------------------
70
71//Applicaton initialization callback. Called once when CUB application starts
72public ON_Init(id, size, const pkt[])
73{
74 LOG_i("\n");
75 LOG_i("*** WOWCube SDK Example \"Strings and Arrays\" ***\n\n");
76
77 //set up timers
78 timer.delay = 100;
79 timer.time = getTime();
80
81 timer2.delay = 1000;
82 timer2.time = getTime();
83
84 //initialize array indices
85 arrayIndices.i1 = 0;
86 arrayIndices.i2 = 0;
87
88 LOG_i("Done.\n");
89}
90
91//Saved application state data load callback. Gets called in response to loadState() function call
92public ON_Load(id, size, const pkt[])
93{
94}
95
96//Main run loop callback. Gets called recurrently by the CUB application as frequent as application code allows.
97public ON_Tick()
98{
99 //1 second timer
100 new currentTime = getTime();
101 if(currentTime - timer.time >= timer.delay)
102 {
103 timer.time = currentTime;
104 OnTimerTick(0);
105 }
106
107 if(currentTime - timer2.time >= timer2.delay)
108 {
109 timer2.time = currentTime;
110 OnTimerTick(1);
111 }
112}
113
114//This callback is gets called immediately after ON_Tick(). Use it for calling your rendering code.
115public ON_Render()
116{
117 //First screen
118 GFX_setRenderTarget(0);
119 GFX_clear(Colors.black);
120 GFX_drawText([ 120,120 ], TEXT_SIZE, 0, 0, TEXT_ALIGN_CENTER, Colors.teal, buffers.buff2);
121 GFX_render();
122
123 //Second screen
124 GFX_setRenderTarget(1);
125 GFX_clear(Colors.black);
126
127 if(arrayIndices.i2<3)
128 {
129 if(arrayIndices.i2>=0) GFX_drawText([ 120,120-50 ], TEXT_SIZE+2, 0, 0, TEXT_ALIGN_CENTER, Colors.blue1, arrWOWCUBE2[0]);
130 if(arrayIndices.i2>=1) GFX_drawText([ 120,120 ], TEXT_SIZE+2, 0, 0, TEXT_ALIGN_CENTER, Colors.blue2, arrWOWCUBE2[1]);
131 if(arrayIndices.i2>=2) GFX_drawText([ 120,120+50 ], TEXT_SIZE+2, 0, 0, TEXT_ALIGN_CENTER, Colors.blue3, arrWOWCUBE2[2]);
132 }
133 GFX_render();
134
135 //Third screen
136 GFX_setRenderTarget(2);
137 GFX_clear(Colors.black);
138
139 new x = 0;
140 new Fixed:offset
141
142 for(new i=0;i<sizeof(arrTWISTY);i++)
143 {
144 offset = FixedSin(fParam[i]);
145 fParam[i]+=0.015;
146
147 if(firstFrame==0)
148 {
149 firstFrame = 1;
150 }
151 else
152 {
153 if(firstFrame==1)
154 {
155 firstFrame = 2;
156 GFX_drawTextXY(10+x,DISPLAY_HEIGHT / 2+prevPos[i][0]+10, TEXT_SIZE, 0, 0, TEXT_ALIGN_LEFT_CORNER, Colors.pink2, arrTWISTY[i]);
157 }
158 else
159 {
160 GFX_drawTextXY(10+x,DISPLAY_HEIGHT / 2+prevPos[i][0]+20, TEXT_SIZE, 0, 0, TEXT_ALIGN_LEFT_CORNER, Colors.pink3, arrTWISTY[i]);
161 GFX_drawTextXY(10+x,DISPLAY_HEIGHT / 2+prevPos[i][0]+10, TEXT_SIZE, 0, 0, TEXT_ALIGN_LEFT_CORNER, Colors.pink2, arrTWISTY[i]);
162 }
163 }
164
165 prevPos[i][1] = prevPos[i][0];
166 prevPos[i][0] = fint(offset/fixed(4));
167
168 GFX_drawTextXY(10+x,DISPLAY_HEIGHT / 2+prevPos[i][0], TEXT_SIZE, 0, 0, TEXT_ALIGN_LEFT_CORNER, Colors.pink1, arrTWISTY[i]);
169 x+=40;
170 }
171 GFX_render();
172}
173
174//The "physics" callback. Gets called recurrently with 30ms resolution.
175public ON_PhysicsTick()
176{
177}
178
179//The "inner network" callback. Gets called when WOWCube module receives a data packet from other module
180public ON_Packet(type, size, const pkt[])
181{
182}
183
184//The cube topology change callback. Gets called when cube is twisted and its topological desctiption has been changed
185public ON_Twist(twist[TOPOLOGY_TWIST_INFO])
186{
187 if (SELF_ID == 0)
188 {
189 }
190 else
191 {
192 }
193}
194
195//Screen pat callback.
196public ON_Pat(const count, const display, const bool:opposite)
197{
198 if (SELF_ID == 0)
199 {
200 }
201 else
202 {
203 }
204}
205
206//Application quit callback.
207public ON_Quit()
208{
209 //
210 //Save game data here
211 //
212}
213
214// Functions
215//----------------
216
217OnTimerTick(timerID)
218{
219 if(timerID==0)
220 {
221 //convert current letter to string
222 strformat(buffers.buff,sizeof(buffers.buff), true, "%c",arrWOWCUBE[arrayIndices.i1]);
223 //append it
224 strcat(buffers.buff2,buffers.buff);
225
226 arrayIndices.i1++;
227 if(arrayIndices.i1>7) {
228 arrayIndices.i1=0;
229 strdel(buffers.buff2,0,strlen(buffers.buff2));
230 }
231 return;
232 }
233
234 if(timerID==1)
235 {
236 arrayIndices.i2++;
237 if(arrayIndices.i2>3) arrayIndices.i2 = 0;
238
239 return;
240 }
241}
Wrapped for easier reading. Turn wrap off to inspect exact line lengths.
Context Rail

Project files

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

Related nodes

Strings and Arrays
Examples / SDK 6.3 / Pawn / basics
info.json
Examples / SDK 6.3 / Pawn / basics / Strings and Arrays
wowcubeapp-build.json
Examples / SDK 6.3 / Pawn / basics / Strings and Arrays / project
Getting Started
Examples / SDK 6.3 / Pawn / basics
Previous Node
info.json
Examples / SDK 6.3 / Pawn / basics / Strings and Arrays
Next Node
wowcubeapp-build.json
Examples / SDK 6.3 / Pawn / basics / Strings and Arrays / project