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