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

main.pwn

Example: main.pwn

Examples / SDK 6.2 / Pawn / rendering / Simple Shapes - Lines / 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, .prevx, .prevy, .vx, .vy];
29new numStars = 0;
30
31//new xorshift32_state[.a];
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 - Lines\" ***\n\n");
40
41 //Create starts
42 for(new n=0;n<50;n++)
43 {
44 AddStar();
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 RenderStarfield();
69
70 GFX_render();
71 }
72}
73
74//The "physics" callback. Gets called recurrently with 30ms resolution.
75public ON_PhysicsTick()
76{
77}
78
79//The "inner network" callback. Gets called when WOWCube module receives a data packet from other module
80public ON_Packet(type, size, const pkt[])
81{
82}
83
84//The cube topology change callback. Gets called when cube is twisted and its topological desctiption has been changed
85public ON_Twist(twist[TOPOLOGY_TWIST_INFO])
86{
87 if (SELF_ID == 0)
88 {
89 }
90 else
91 {
92 }
93}
94
95//Screen pat callback.
96public ON_Pat(const count, const display, const bool:opposite)
97{
98 if (SELF_ID == 0)
99 {
100 }
101 else
102 {
103 }
104}
105
106//Application quit callback.
107public ON_Quit()
108{
109 //
110 //Save game data here
111 //
112}
113
114// Functions
115//----------------
116
117//Adds a star object
118AddStar()
119{
120 //Random probability from 0% to 100%
121 new prob = RND_randomize(0,100);
122
123 //Velocity vector components filled with random values
124 new Fixed:vx = fdiv(fixed(400-RND_randomize(0,800)),fixed(RND_randomize(3,100)));
125 new Fixed:vy = fdiv(fixed(400-RND_randomize(0,800)),fixed(RND_randomize(3,100)));
126
127 //Create 50 unique stars that have non-zero velocity
128 if(numStars<50 && prob<50 && vx!=0 && vy!=0)
129 {
130 stars[numStars].x = 0;
131 stars[numStars].y = 0;
132 stars[numStars].prevx = 0;
133 stars[numStars].prevy = 0;
134 stars[numStars].vx = vx;
135 stars[numStars].vy = vy;
136
137 numStars++;
138 }
139}
140
141//Renders the starfield
142RenderStarfield()
143{
144 new position_from[GFX_POINT];
145 new position_to[GFX_POINT];
146
147 for(new n=0;n<numStars-1;n++)
148 {
149 //Move the star
150 stars[n].prevx = stars[n].x;
151 stars[n].prevy = stars[n].y;
152
153 stars[n].x = stars[n].x+fint(stars[n].vx)/1000;
154 stars[n].y = stars[n].y+fint(stars[n].vy)/1000;
155
156 //If star is out of screen, reset its position
157 if(stars[n].x>120 || stars[n].x<-120)
158 {
159 stars[n].x = 0;
160 stars[n].y = 0;
161 }
162
163 //Calculate star color
164 new color = (ABS(stars[n].x)+ABS(stars[n].y))*2;
165 if(color>255) color = 255;
166
167 //Draw a line
168
169 position_from.x = DISPLAY_CENTER_X+stars[n].prevx;
170 position_from.y = DISPLAY_CENTER_Y+stars[n].prevy;
171
172 position_to.x = DISPLAY_CENTER_X+stars[n].x;
173 position_to.y = DISPLAY_CENTER_Y+stars[n].y;
174
175 GFX_drawLine(position_from, position_to, 1, GFX_fromARGB8888(255,color,color,color));
176 }
177}
178
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 - Lines
Examples / SDK 6.2 / Pawn / rendering
info.json
Examples / SDK 6.2 / Pawn / rendering / Simple Shapes - Lines
wowcubeapp-build.json
Examples / SDK 6.2 / Pawn / rendering / Simple Shapes - Lines / project
Simple Shapes - Points
Examples / SDK 6.2 / Pawn / rendering
Previous Node
info.json
Examples / SDK 6.2 / Pawn / rendering / Simple Shapes - Lines
Next Node
wowcubeapp-build.json
Examples / SDK 6.2 / Pawn / rendering / Simple Shapes - Lines / project