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//Device shake detection callback.
96public ON_Shake(const count)
97{
98}
99
100//Screen tap callback.
101public ON_Tap(const count, const display, const bool:opposite)
102{
103 if (SELF_ID == 0)
104 {
105 }
106 else
107 {
108 }
109}
110
111//Application quit callback.
112public ON_Quit()
113{
114 //
115 //Save game data here
116 //
117}
118
119// Functions
120//----------------
121
122//Adds a star object
123AddStar()
124{
125 //Random probability from 0% to 100%
126 new prob = RND_randomize(0,100);
127
128 //Velocity vector components filled with random values
129 new Fixed:vx = fdiv(fixed(400-RND_randomize(0,800)),fixed(RND_randomize(3,100)));
130 new Fixed:vy = fdiv(fixed(400-RND_randomize(0,800)),fixed(RND_randomize(3,100)));
131
132 //Create 50 unique stars that have non-zero velocity
133 if(numStars<50 && prob<50 && vx!=0 && vy!=0)
134 {
135 stars[numStars].x = 0;
136 stars[numStars].y = 0;
137 stars[numStars].prevx = 0;
138 stars[numStars].prevy = 0;
139 stars[numStars].vx = vx;
140 stars[numStars].vy = vy;
141
142 numStars++;
143 }
144}
145
146//Renders the starfield
147RenderStarfield()
148{
149 new position_from[GFX_POINT];
150 new position_to[GFX_POINT];
151
152 for(new n=0;n<numStars-1;n++)
153 {
154 //Move the star
155 stars[n].prevx = stars[n].x;
156 stars[n].prevy = stars[n].y;
157
158 stars[n].x = stars[n].x+fint(stars[n].vx)/1000;
159 stars[n].y = stars[n].y+fint(stars[n].vy)/1000;
160
161 //If star is out of screen, reset its position
162 if(stars[n].x>120 || stars[n].x<-120)
163 {
164 stars[n].x = 0;
165 stars[n].y = 0;
166 }
167
168 //Calculate star color
169 new color = (ABS(stars[n].x)+ABS(stars[n].y))*2;
170 if(color>255) color = 255;
171
172 //Draw a line
173
174 position_from.x = DISPLAY_CENTER_X+stars[n].prevx;
175 position_from.y = DISPLAY_CENTER_Y+stars[n].prevy;
176
177 position_to.x = DISPLAY_CENTER_X+stars[n].x;
178 position_to.y = DISPLAY_CENTER_Y+stars[n].y;
179
180 GFX_drawLine(position_from, position_to, 1, GFX_fromARGB8888(255,color,color,color));
181 }
182}
183