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

main.pwn

Example: main.pwn

Examples / SDK 6.3 / 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
121//Screen pat callback.
122public ON_Pat(const count, const display, const bool:opposite)
123{
124 if (SELF_ID == 0)
125 {
126 }
127 else
128 {
129 }
130}
131
132//Application quit callback.
133public ON_Quit()
134{
135 //
136 //Save game data here
137 //
138}
139
140// Functions
141//----------------
142
143//Render a rectangle
144DrawRect(cx, cy, dist, xoffset)
145{
146 new rect[GFX_RECTANGLE];
147
148 // d = (dist*100)/128
149 new Fixed:d = fmul(fdiv(fixed(dist),fixed(100)),fixed(128));
150
151 //cacluclate size of a rectange
152 new size = 128-fint(d);
153
154 //calculate colors
155 new color = (size+10)*2;
156 if(color>255) color = 255;
157
158 new bgcolor = color/15;
159 if(bgcolor>100) bgcolor = 100;
160
161 //calculate horizontal offset
162 new xoff = (fint(d)*xoffset)/90;
163 cx+=xoff;
164
165 //calculate border withd
166 new border = 7-(dist*6)/90;
167
168 //Render rectangles
169
170 rect.x = cx-size;
171 rect.y = cy-size;
172 rect.w = size*2;
173 rect.h = size*2;
174
175 GFX_drawRectangle(rect, GFX_fromARGB8888(255,color,0,0));
176
177 rect.x = cx-size+border;
178 rect.y = cy-size+border;
179 rect.w = (size-border)*2;
180 rect.h = (size-border)*2;
181
182 GFX_drawRectangle(rect, GFX_fromARGB8888(255,bgcolor,bgcolor,bgcolor));
183}
184
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.3 / Pawn / rendering
info.json
Examples / SDK 6.3 / Pawn / rendering / Simple Shapes - Rectangles
wowcubeapp-build.json
Examples / SDK 6.3 / Pawn / rendering / Simple Shapes - Rectangles / project
Simple Shapes - Points
Examples / SDK 6.3 / Pawn / rendering
Previous Node
info.json
Examples / SDK 6.3 / Pawn / rendering / Simple Shapes - Rectangles
Next Node
wowcubeapp-build.json
Examples / SDK 6.3 / Pawn / rendering / Simple Shapes - Rectangles / project