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// Application defines21// -----------------------------22#define TEXT_SIZE 1023#define DISPLAY_HEIGHT 2402425// Application constants26// ------------------------------27new const Colors[.white, .black, .red, .green, .blue, .teal,.blue1, .blue2, .blue3, .pink1, .pink2, .pink3] =28[29 0xFFFFFFFF,30 0xFF000000,31 0xFFFF0000,32 0xFF00FF00,33 0xFF0000FF,34 0xFF00FF99,35 0xFF2828C8,36 0xFF6464FF,37 0xFF9696FF,38 0xFFFF6464,39 0xFF641E1E,40 0xFF320F0F,41];4243// Global variables and constants44// ----------------------------45new timer[.delay, .time]46new timer2[.delay, .time]4748new arrayIndices[49 .i1,50 .i251 ];5253new buffers[54 .buff[1], //character to string conversion55 .buff2[4] //screen 1 text56 ];5758new const arrWOWCUBE[8] = ['W','O','W','C','U','B','E',' ']; //array of characters5960new const arrWOWCUBE2[3]{10} = ["WOWCUBE","IS","COOL"]; //array of strings6162new const arrTWISTY[]{} = ["T","W","I","S","T","Y"]; //array of strings too63new Fixed:fParam[] = [0 ,20 ,10 ,-10,-20,-10]; //fixed point parameters used to calculate vertical offsets of each letter64new prevPos[][2] = [0,0,0,0,0,0,0,0,0,0,0,0]; //array of previous letter positions6566new firstFrame = 0;6768// WOWCube application callbacks69// -----------------------------7071//Applicaton initialization callback. Called once when CUB application starts72public ON_Init(id, size, const pkt[])73{74 LOG_i("\n");75 LOG_i("*** WOWCube SDK Example \"Strings and Arrays\" ***\n\n");7677 //set up timers78 timer.delay = 100;79 timer.time = getTime();8081 timer2.delay = 1000;82 timer2.time = getTime();8384 //initialize array indices85 arrayIndices.i1 = 0;86 arrayIndices.i2 = 0;8788 LOG_i("Done.\n");89}9091//Saved application state data load callback. Gets called in response to loadState() function call92public ON_Load(id, size, const pkt[])93{94}9596//Main run loop callback. Gets called recurrently by the CUB application as frequent as application code allows.97public ON_Tick()98{99 //1 second timer100 new currentTime = getTime();101 if(currentTime - timer.time >= timer.delay)102 {103 timer.time = currentTime;104 OnTimerTick(0);105 }106107 if(currentTime - timer2.time >= timer2.delay)108 {109 timer2.time = currentTime;110 OnTimerTick(1);111 }112}113114//This callback is gets called immediately after ON_Tick(). Use it for calling your rendering code.115public ON_Render()116{117 //First screen118 GFX_setRenderTarget(0);119 GFX_clear(Colors.black);120 GFX_drawText([ 120,120 ], TEXT_SIZE, 0, 0, TEXT_ALIGN_CENTER, Colors.teal, buffers.buff2);121 GFX_render();122123 //Second screen124 GFX_setRenderTarget(1);125 GFX_clear(Colors.black);126127 if(arrayIndices.i2<3)128 {129 if(arrayIndices.i2>=0) GFX_drawText([ 120,120-50 ], TEXT_SIZE+2, 0, 0, TEXT_ALIGN_CENTER, Colors.blue1, arrWOWCUBE2[0]);130 if(arrayIndices.i2>=1) GFX_drawText([ 120,120 ], TEXT_SIZE+2, 0, 0, TEXT_ALIGN_CENTER, Colors.blue2, arrWOWCUBE2[1]);131 if(arrayIndices.i2>=2) GFX_drawText([ 120,120+50 ], TEXT_SIZE+2, 0, 0, TEXT_ALIGN_CENTER, Colors.blue3, arrWOWCUBE2[2]);132 }133 GFX_render();134135 //Third screen136 GFX_setRenderTarget(2);137 GFX_clear(Colors.black);138139 new x = 0;140 new Fixed:offset141142 for(new i=0;i<sizeof(arrTWISTY);i++)143 {144 offset = FixedSin(fParam[i]);145 fParam[i]+=0.015;146147 if(firstFrame==0)148 {149 firstFrame = 1;150 }151 else152 {153 if(firstFrame==1)154 {155 firstFrame = 2;156 GFX_drawTextXY(10+x,DISPLAY_HEIGHT / 2+prevPos[i][0]+10, TEXT_SIZE, 0, 0, TEXT_ALIGN_LEFT_CORNER, Colors.pink2, arrTWISTY[i]);157 }158 else159 {160 GFX_drawTextXY(10+x,DISPLAY_HEIGHT / 2+prevPos[i][0]+20, TEXT_SIZE, 0, 0, TEXT_ALIGN_LEFT_CORNER, Colors.pink3, arrTWISTY[i]);161 GFX_drawTextXY(10+x,DISPLAY_HEIGHT / 2+prevPos[i][0]+10, TEXT_SIZE, 0, 0, TEXT_ALIGN_LEFT_CORNER, Colors.pink2, arrTWISTY[i]);162 }163 }164165 prevPos[i][1] = prevPos[i][0];166 prevPos[i][0] = fint(offset/fixed(4));167168 GFX_drawTextXY(10+x,DISPLAY_HEIGHT / 2+prevPos[i][0], TEXT_SIZE, 0, 0, TEXT_ALIGN_LEFT_CORNER, Colors.pink1, arrTWISTY[i]);169 x+=40;170 }171 GFX_render();172}173174//The "physics" callback. Gets called recurrently with 30ms resolution.175public ON_PhysicsTick()176{177}178179//The "inner network" callback. Gets called when WOWCube module receives a data packet from other module180public ON_Packet(type, size, const pkt[])181{182}183184//The cube topology change callback. Gets called when cube is twisted and its topological desctiption has been changed185public ON_Twist(twist[TOPOLOGY_TWIST_INFO])186{187 if (SELF_ID == 0)188 {189 }190 else191 {192 }193}194195//Device shake detection callback.196public ON_Shake(const count)197{198}199200//Screen tap callback.201public ON_Tap(const count, const display, const bool:opposite)202{203 if (SELF_ID == 0)204 {205 }206 else207 {208 }209}210211//Application quit callback.212public ON_Quit()213{214 //215 //Save game data here216 //217}218219// Functions220//----------------221222OnTimerTick(timerID)223{224 if(timerID==0)225 {226 //convert current letter to string227 strformat(buffers.buff,sizeof(buffers.buff), true, "%c",arrWOWCUBE[arrayIndices.i1]);228 //append it229 strcat(buffers.buff2,buffers.buff);230231 arrayIndices.i1++;232 if(arrayIndices.i1>7) {233 arrayIndices.i1=0;234 strdel(buffers.buff2,0,strlen(buffers.buff2));235 }236 return;237 }238239 if(timerID==1)240 {241 arrayIndices.i2++;242 if(arrayIndices.i2>3) arrayIndices.i2 = 0;243244 return;245 }246}