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.1PawnrenderingProject Included

main.pwn

Example: main.pwn

Examples / SDK 6.1 / Pawn / rendering / Simple Shapes - Rectangles / 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 DISPLAY_CENTER_X 120
23#define DISPLAY_CENTER_Y 120
24
25// Global variables and constants
26// ----------------------------
27new rects[2][.dist,.xoffset];
28
29new Fixed:fParam = 0;
30new Fixed:fOffset = 0;
31
32// WOWCube application callbacks
33// -----------------------------
34
35//Applicaton initialization callback. Called once when CUB application starts
36public ON_Init(id, size, const pkt[])
37{
38 LOG_i("\n");
39 LOG_i("*** WOWCube SDK Example \"Simple Shapes - Rectangles\" ***\n\n");
40
41 //Create rects
42 for(new i=0;i<2;i++)
43 {
44 rects[i].dist = 90-40*i;
45 }
46
47 LOG_i("Done.\n");
48}
49
50//Saved application state data load callback. Gets called in response to loadState() function call
51public ON_Load(id, size, const pkt[])
52{
53}
54
55//Main run loop callback. Gets called recurrently by the CUB application as frequent as application code allows.
56public ON_Tick()
57{
58}
59
60//This callback is gets called immediately after ON_Tick(). Use it for calling your rendering code.
61public ON_Render()
62{
63 for(new screenNumber = 0; screenNumber<3; screenNumber++)
64 {
65 GFX_setRenderTarget(screenNumber);
66 GFX_clear(0xFF000000);
67
68 if(rects[0].dist>rects[1].dist)
69 {
70 for(new i=1;i>=0;i--)
71 {
72 DrawRect(128, 128, rects[i].dist,rects[i].xoffset);
73
74 rects[i].dist-=5;
75 if(rects[i].dist<=0) rects[i].dist = 90;
76
77 rects[i].xoffset = fint(fOffset)/4;
78 }
79 }
80 else
81 {
82 for(new i=0;i<2;i++)
83 {
84 DrawRect(128, 128, rects[i].dist,rects[i].xoffset);
85
86 rects[i].dist-=5;
87 if(rects[i].dist<=0) rects[i].dist = 90;
88
89 rects[i].xoffset = fint(fOffset)/4;
90 }
91 }
92
93 GFX_render();
94 }
95}
96
97//The "physics" callback. Gets called recurrently with 30ms resolution.
98public ON_PhysicsTick()
99{
100 fOffset = FixedSin(fParam);
101 fParam+=0.015;
102}
103
104//The "inner network" callback. Gets called when WOWCube module receives a data packet from other module
105public ON_Packet(type, size, const pkt[])
106{
107}
108
109//The cube topology change callback. Gets called when cube is twisted and its topological desctiption has been changed
110public ON_Twist(twist[TOPOLOGY_TWIST_INFO])
111{
112 if (SELF_ID == 0)
113 {
114 }
115 else
116 {
117 }
118}
119
120//Device shake detection callback.
121public ON_Shake(const count)
122{
123}
124
125//Screen tap callback.
126public ON_Tap(const count, const display, const bool:opposite)
127{
128 if (SELF_ID == 0)
129 {
130 }
131 else
132 {
133 }
134}
135
136//Application quit callback.
137public ON_Quit()
138{
139 //
140 //Save game data here
141 //
142}
143
144// Functions
145//----------------
146
147//Render a rectangle
148DrawRect(cx, cy, dist, xoffset)
149{
150 new rect[GFX_RECTANGLE];
151
152 // d = (dist*100)/128
153 new Fixed:d = fmul(fdiv(fixed(dist),fixed(100)),fixed(128));
154
155 //cacluclate size of a rectange
156 new size = 128-fint(d);
157
158 //calculate colors
159 new color = (size+10)*2;
160 if(color>255) color = 255;
161
162 new bgcolor = color/15;
163 if(bgcolor>100) bgcolor = 100;
164
165 //calculate horizontal offset
166 new xoff = (fint(d)*xoffset)/90;
167 cx+=xoff;
168
169 //calculate border withd
170 new border = 7-(dist*6)/90;
171
172 //Render rectangles
173
174 rect.x = cx-size;
175 rect.y = cy-size;
176 rect.w = size*2;
177 rect.h = size*2;
178
179 GFX_drawRectangle(rect, GFX_fromARGB8888(255,color,0,0));
180
181 rect.x = cx-size+border;
182 rect.y = cy-size+border;
183 rect.w = (size-border)*2;
184 rect.h = (size-border)*2;
185
186 GFX_drawRectangle(rect, GFX_fromARGB8888(255,bgcolor,bgcolor,bgcolor));
187}
188
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

Simple Shapes - Rectangles
Examples / SDK 6.1 / Pawn / rendering
info.json
Examples / SDK 6.1 / Pawn / rendering / Simple Shapes - Rectangles
wowcubeapp-build.json
Examples / SDK 6.1 / Pawn / rendering / Simple Shapes - Rectangles / project
Simple Shapes - Points
Examples / SDK 6.1 / Pawn / rendering
Previous Node
info.json
Examples / SDK 6.1 / Pawn / rendering / Simple Shapes - Rectangles
Next Node
wowcubeapp-build.json
Examples / SDK 6.1 / Pawn / rendering / Simple Shapes - Rectangles / project