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 - Bitmaps / 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#include "random.inc"
21
22// Application defines
23// -----------------------------
24#define DISPLAY_CENTER_X 120
25#define DISPLAY_CENTER_Y 120
26
27#define SCREEN_WIDTH 240
28#define SCREEN_HEIGHT 240
29
30#define NUM_PLANETS 3
31
32// Global variables and constants
33// ----------------------------
34
35//Background image
36new bkg_image;
37//Foreground image
38new fg_image;
39
40//Star and planets
41new sun_image;
42new planets[NUM_PLANETS][.sprite, Fixed:.x, Fixed:.y,.z,.angle,Fixed:.radius,.speed,Fixed:.orbIncl];
43
44// WOWCube application callbacks
45// -----------------------------
46
47
48new Fixed: incl = 0.0;
49
50//Applicaton initialization callback. Called once when CUB application starts
51public ON_Init(id, size, const pkt[])
52{
53 LOG_i("\n");
54 LOG_i("*** WOWCube SDK Example \"Simple Shapes - Bitmaps\" ***\n\n");
55
56 //Load images
57 bkg_image = GFX_getAssetId("bkg.png");
58 fg_image = GFX_getAssetId("fg.png");
59 sun_image = GFX_getAssetId("star.png");
60
61 //Initialize sprites
62 planets[0].sprite = GFX_getAssetId("planet1.png");
63 planets[0].x = 120.0;
64 planets[0].y = 120.0;
65 planets[0].angle = 0;
66 planets[0].radius = 100;
67 planets[0].speed = 5;
68 planets[0].orbIncl = 0.2;
69
70 planets[1].sprite = GFX_getAssetId("planet2.png");
71 planets[1].x = 120.0;
72 planets[1].y = 120.0;
73 planets[1].angle = 30;
74 planets[1].radius = 60;
75 planets[1].speed = 7;
76 planets[1].orbIncl = 0.22;
77
78 planets[2].sprite = GFX_getAssetId("planet3.png");
79 planets[2].x = 120.0;
80 planets[2].y = 120.0;
81 planets[2].angle = 200;
82 planets[2].radius = 160;
83 planets[2].speed = 1;
84 planets[2].orbIncl = 0.6;
85
86 LOG_i("Done.\n");
87}
88
89//Saved application state data load callback. Gets called in response to loadState() function call
90public ON_Load(id, size, const pkt[])
91{
92}
93
94//Main run loop callback. Gets called recurrently by the CUB application as frequent as application code allows.
95public ON_Tick()
96{
97}
98
99//This callback is gets called immediately after ON_Tick(). Use it for calling your rendering code.
100public ON_Render()
101{
102 for(new screenNumber = 0; screenNumber<3; screenNumber++)
103 {
104 GFX_setRenderTarget(screenNumber);
105
106 //Render background
107 GFX_drawImage([128,128], 0xFF, 0, 100, 100, 0, MIRROR_BLANK, bkg_image);
108
109 //Render planets in proper z-order
110 for(new i=0;i<NUM_PLANETS;i++)
111 {
112 if(planets[i].z<0)
113 {
114 //Render planets behind the sun
115 GFX_drawImageXY(fint(planets[i].x),fint(planets[i].y), 0xFF, 0xFF00FF, 100, 100, 0, MIRROR_BLANK, planets[i].sprite);
116 }
117 }
118
119 //Render sun
120 GFX_drawImage([128,128], 0xFF, 0, 100, 100, 0, MIRROR_BLANK, sun_image);
121
122 for(new i=0;i<NUM_PLANETS;i++)
123 {
124 if(planets[i].z>0)
125 {
126 //Render planets in from of the sun
127 GFX_drawImageXY(fint(planets[i].x),fint(planets[i].y), 0xFF, 0xFF00FF, 100, 100, 0, MIRROR_BLANK, planets[i].sprite);
128 }
129 }
130
131 //Render foreground glow
132 GFX_drawImage([128,128], 0xFF, 0, 100, 100, 0, MIRROR_BLANK, fg_image);
133
134
135 //Commit to all three screens
136 GFX_render();
137 }
138}
139
140//The "physics" callback. Gets called recurrently with 30ms resolution.
141public ON_PhysicsTick()
142{
143 //Calculate positions of plantes
144 for(new i=0;i<NUM_PLANETS;i++)
145 {
146 new fs = FixedSin(planets[i].angle);
147
148 new Fixed:fSin = fixed(FixedSin(planets[i].angle))/256.0;
149 new Fixed:fCos = fixed(FixedCos(planets[i].angle))/256.0;
150
151 planets[i].angle += planets[i].speed;
152 if(planets[i].angle>360) planets[i].angle = planets[i].angle-360;
153
154 planets[i].x = 120.0 + planets[i].radius*fSin;
155 planets[i].y = 120.0 + planets[i].radius*fCos*planets[i].orbIncl*incl;
156
157 //Is the planet ahead of behind the sun?
158 if(planets[i].angle>90 && planets[i].angle<270)
159 {
160 planets[i].z = 1;
161 }
162 else
163 {
164 planets[i].z = -1;
165 }
166 }
167
168 //Animate global inclanation
169 if(incl<1.0)
170 incl+=0.001;
171 else
172 if(incl>-1.0)
173 {
174 incl-=0.001;
175 }
176}
177
178//The "inner network" callback. Gets called when WOWCube module receives a data packet from other module
179public ON_Packet(type, size, const pkt[])
180{
181}
182
183//The cube topology change callback. Gets called when cube is twisted and its topological desctiption has been changed
184public ON_Twist(twist[TOPOLOGY_TWIST_INFO])
185{
186 if (SELF_ID == 0)
187 {
188 }
189 else
190 {
191 }
192}
193
194//Screen pat callback.
195public ON_Pat(const count, const display, const bool:opposite)
196{
197 if (SELF_ID == 0)
198 {
199 }
200 else
201 {
202 }
203}
204
205//Application quit callback.
206public ON_Quit()
207{
208 //
209 //Save game data here
210 //
211}
212
213// Functions
214//----------------
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 - Bitmaps
Examples / SDK 6.3 / Pawn / rendering
info.json
Examples / SDK 6.3 / Pawn / rendering / Simple Shapes - Bitmaps
wowcubeapp-build.json
Examples / SDK 6.3 / Pawn / rendering / Simple Shapes - Bitmaps / project
Simple Shapes - Points
Examples / SDK 6.3 / Pawn / rendering
Previous Node
info.json
Examples / SDK 6.3 / Pawn / rendering / Simple Shapes - Bitmaps
Next Node
wowcubeapp-build.json
Examples / SDK 6.3 / Pawn / rendering / Simple Shapes - Bitmaps / project