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 - Points / 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 "random.inc"
18#include "log.inc"
19#include "string.inc"
20
21// Application defines
22// -----------------------------
23#define DISPLAY_CENTER_X 120
24#define DISPLAY_CENTER_Y 120
25
26// Global variables and constants
27// ----------------------------
28new stars[50][.x, .y, .vx, .vy];
29new numStars = 0;
30
31// WOWCube application callbacks
32// -----------------------------
33
34//Applicaton initialization callback. Called once when CUB application starts
35public ON_Init(id, size, const pkt[])
36{
37 LOG_i("\n");
38 LOG_i("*** WOWCube SDK Example \"Simple Shapes - Points\" ***\n\n");
39
40 //Create starts
41 for(new n=0;n<50;n++)
42 {
43 AddStar();
44 }
45
46 LOG_i("Done.\n");
47}
48
49//Saved application state data load callback. Gets called in response to loadState() function call
50public ON_Load(id, size, const pkt[])
51{
52}
53
54//Main run loop callback. Gets called recurrently by the CUB application as frequent as application code allows.
55public ON_Tick()
56{
57}
58
59//This callback is gets called immediately after ON_Tick(). Use it for calling your rendering code.
60public ON_Render()
61{
62 for(new screenNumber = 0; screenNumber<3; screenNumber++)
63 {
64 GFX_setRenderTarget(screenNumber);
65 GFX_clear(0xFF000000);
66
67 RenderStarfield();
68
69 GFX_render();
70 }
71}
72
73//The "physics" callback. Gets called recurrently with 30ms resolution.
74public ON_PhysicsTick()
75{
76}
77
78//The "inner network" callback. Gets called when WOWCube module receives a data packet from other module
79public ON_Packet(type, size, const pkt[])
80{
81}
82
83//The cube topology change callback. Gets called when cube is twisted and its topological desctiption has been changed
84public ON_Twist(twist[TOPOLOGY_TWIST_INFO])
85{
86 if (SELF_ID == 0)
87 {
88 }
89 else
90 {
91 }
92}
93
94//Device shake detection callback.
95public ON_Shake(const count)
96{
97}
98
99//Screen tap callback.
100public ON_Tap(const count, const display, const bool:opposite)
101{
102 if (SELF_ID == 0)
103 {
104 }
105 else
106 {
107 }
108}
109
110//Application quit callback.
111public ON_Quit()
112{
113 //
114 //Save game data here
115 //
116}
117
118// Functions
119//----------------
120
121//Adds a star object
122AddStar()
123{
124 //Random probability from 0% to 100%
125 new prob = RND_randomize(0,100);
126
127 //Velocity vector components filled with random values
128 new Fixed:vx = fdiv(fixed(400-RND_randomize(0,800)),fixed(RND_randomize(10,100)));
129 new Fixed:vy = fdiv(fixed(400-RND_randomize(0,800)),fixed(RND_randomize(10,100)));
130
131 //Create 50 unique stars that have non-zero velocity
132 if(numStars<50 && prob<50 && vx!=0 && vy!=0)
133 {
134 stars[numStars].x = 0;
135 stars[numStars].y = 0;
136 stars[numStars].vx = vx;
137 stars[numStars].vy = vy;
138
139 numStars++;
140 }
141}
142
143//Renders the starfield
144RenderStarfield()
145{
146 for(new n=0;n<numStars;n++)
147 {
148 //Move the star
149 stars[n].x = stars[n].x+fint(stars[n].vx)/1000;
150 stars[n].y = stars[n].y+fint(stars[n].vy)/1000;
151
152 //If star is out of screen, reset its position
153 if(stars[n].x>120 || stars[n].x<-120 || stars[n].y>120 || stars[n].y<-120)
154 {
155 stars[n].x = 0;
156 stars[n].y = 0;
157 }
158
159 //Calculate star color
160 new color = (ABS(stars[n].x)+ABS(stars[n].y))*2;
161 if(color>255) color = 255;
162
163 //Draw a point
164 GFX_drawPointXY(DISPLAY_CENTER_X+stars[n].x,DISPLAY_CENTER_Y+stars[n].y, GFX_fromARGB8888(255,color,color,color));
165 }
166}
167
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 - Points
Examples / SDK 6.1 / Pawn / rendering
info.json
Examples / SDK 6.1 / Pawn / rendering / Simple Shapes - Points
wowcubeapp-build.json
Examples / SDK 6.1 / Pawn / rendering / Simple Shapes - Points / project
Simple Shapes - Lines
Examples / SDK 6.1 / Pawn / rendering
Previous Node
info.json
Examples / SDK 6.1 / Pawn / rendering / Simple Shapes - Points
Next Node
wowcubeapp-build.json
Examples / SDK 6.1 / Pawn / rendering / Simple Shapes - Points / project