Example: main.pwn
1// This PAWN script is generated by WOWCube SDK project wizard23#define G2D45#pragma warning disable 2036#pragma warning disable 2137#pragma warning disable 22989// Includes10// -----------------------------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"1920#include "random.inc"2122// Application defines23// -----------------------------24#define DISPLAY_CENTER_X 12025#define DISPLAY_CENTER_Y 1202627#define SCREEN_WIDTH 24028#define SCREEN_HEIGHT 2402930#define NUM_PLANETS 33132// Global variables and constants33// ----------------------------3435//Background image36new bkg_image;37//Foreground image38new fg_image;3940//Star and planets41new sun_image;42new planets[NUM_PLANETS][.sprite, Fixed:.x, Fixed:.y,.z,.angle,Fixed:.radius,.speed,Fixed:.orbIncl];4344// WOWCube application callbacks45// -----------------------------464748new Fixed: incl = 0.0;4950//Applicaton initialization callback. Called once when CUB application starts51public ON_Init(id, size, const pkt[])52{53 LOG_i("\n");54 LOG_i("*** WOWCube SDK Example \"Simple Shapes - Bitmaps\" ***\n\n");5556 //Load images57 bkg_image = GFX_getAssetId("bkg.png");58 fg_image = GFX_getAssetId("fg.png");59 sun_image = GFX_getAssetId("star.png");6061 //Initialize sprites62 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;6970 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;7778 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;8586 LOG_i("Done.\n");87}8889//Saved application state data load callback. Gets called in response to loadState() function call90public ON_Load(id, size, const pkt[])91{92}9394//Main run loop callback. Gets called recurrently by the CUB application as frequent as application code allows.95public ON_Tick()96{97}9899//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);105106 //Render background107 GFX_drawImage([128,128], 0xFF, 0, 100, 100, 0, MIRROR_BLANK, bkg_image);108109 //Render planets in proper z-order110 for(new i=0;i<NUM_PLANETS;i++)111 {112 if(planets[i].z<0)113 {114 //Render planets behind the sun115 GFX_drawImageXY(fint(planets[i].x),fint(planets[i].y), 0xFF, 0xFF00FF, 100, 100, 0, MIRROR_BLANK, planets[i].sprite);116 }117 }118119 //Render sun120 GFX_drawImage([128,128], 0xFF, 0, 100, 100, 0, MIRROR_BLANK, sun_image);121122 for(new i=0;i<NUM_PLANETS;i++)123 {124 if(planets[i].z>0)125 {126 //Render planets in from of the sun127 GFX_drawImageXY(fint(planets[i].x),fint(planets[i].y), 0xFF, 0xFF00FF, 100, 100, 0, MIRROR_BLANK, planets[i].sprite);128 }129 }130131 //Render foreground glow132 GFX_drawImage([128,128], 0xFF, 0, 100, 100, 0, MIRROR_BLANK, fg_image);133134135 //Commit to all three screens136 GFX_render();137 }138}139140//The "physics" callback. Gets called recurrently with 30ms resolution.141public ON_PhysicsTick()142{143 //Calculate positions of plantes144 for(new i=0;i<NUM_PLANETS;i++)145 {146 new fs = FixedSin(planets[i].angle);147148 new Fixed:fSin = fixed(FixedSin(planets[i].angle))/256.0;149 new Fixed:fCos = fixed(FixedCos(planets[i].angle))/256.0;150151 planets[i].angle += planets[i].speed;152 if(planets[i].angle>360) planets[i].angle = planets[i].angle-360;153154 planets[i].x = 120.0 + planets[i].radius*fSin;155 planets[i].y = 120.0 + planets[i].radius*fCos*planets[i].orbIncl*incl;156157 //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 else163 {164 planets[i].z = -1;165 }166 }167168 //Animate global inclanation169 if(incl<1.0)170 incl+=0.001;171 else172 if(incl>-1.0)173 {174 incl-=0.001;175 }176}177178//The "inner network" callback. Gets called when WOWCube module receives a data packet from other module179public ON_Packet(type, size, const pkt[])180{181}182183//The cube topology change callback. Gets called when cube is twisted and its topological desctiption has been changed184public ON_Twist(twist[TOPOLOGY_TWIST_INFO])185{186 if (SELF_ID == 0)187 {188 }189 else190 {191 }192}193194//Device shake detection callback.195public ON_Shake(const count)196{197}198199//Screen tap callback.200public ON_Tap(const count, const display, const bool:opposite)201{202 if (SELF_ID == 0)203 {204 }205 else206 {207 }208}209210//Application quit callback.211public ON_Quit()212{213 //214 //Save game data here215 //216}217218// Functions219//----------------