Example: Jukebox.cpp
1// This file is generated by WOWCube SDK project wizard23#include <stdint.h>4#include <string>5#include <vector>6#include <string>7#include <memory>89#include "AppManager.h"10#include "Jukebox.h"111213using namespace Cubios;14using namespace Cubios::Math;15using namespace Cubios::Gfx;1617//Applicaton initialization callback. Called once when CUB application starts18void OnInit(Cubios::AppManager& appMgr)19{20 Jukebox* theApp = new Jukebox();2122 appMgr.SetApplication(theApp,"AAbbCCddEE");2324 theApp->InitializeResources();25}262728Jukebox::Jukebox()29{30 this->secondsCount = 5;31 this->playing = false;32 this->timer500Started = false;33}3435Jukebox::~Jukebox()36{37 this->Scene.DisposeAllObjects();38}3940void Jukebox::InitializeResources()41{42 this->Scene.CreateObjectWithID(GfxObjects::myBackground,new Background(0,0,0));4344 this->Scene.CreateObjectWithID(GfxObjects::myCountdown,new Countdown());45 this->countdown = dynamic_cast<Countdown*>(this->Scene[GfxObjects::myCountdown]);4647 std::vector<std::string> anim;48 anim.push_back("meter1.png");49 anim.push_back("meter2.png");50 anim.push_back("meter3.png");51 anim.push_back("meter4.png");5253 this->Scene.CreateObjectWithID(GfxObjects::myMeter,new AnimatedSprite(anim,Transform(120,120,0)));54 this->meter = dynamic_cast<AnimatedSprite*>(this->Scene[GfxObjects::myMeter]);55 this->meter->Visible = false;56 this->meter->SetPlaybackSpeed(107);5758 if(Cubios::cubeN==0)59 {60 this->Scene.CreateSoundWithID(0,new Sound("LastNinja_2.mp3"));61 }6263 this->SetTimer(1,430);6465 this->ShowFPSCounter(true);66}6768//This callback is called every "tick" of cubeapp application loop69void Jukebox::on_Tick(uint32_t currentTime, uint32_t deltaTime)70{71 this->countdown->Tick(deltaTime);72 this->meter->Tick(deltaTime);7374 if(Cubios::cubeN==0)75 {76 if(!this->timer500Started)77 {78 this->timerMessage.Reset(true);79 this->timerMessage.WriteInt(currentTime,32);80 this->receivedTime = currentTime;8182 this->SendNetworkMessage(0, &this->timerMessage);83 }84 }8586 if(currentTime>3000)87 {88 if(!this->countdown->Visible)89 {90 if(this->secondsCount>0)91 {92 this->countdown->SetContent(std::to_string(this->secondsCount));93 this->secondsCount--;94 }95 else96 {97 this->countdown->Visible = false;98 if(Cubios::cubeN==0)99 {100 if(!this->playing)101 {102 this->timerMessage.Reset(true);103104 //send empty message just to indicate the meter is visible now105 this->SendNetworkMessage(1,&this->timerMessage);106107 this->Scene.Play(0,100);108 this->playing = true;109110 if(!this->timer500Started)111 {112 this->StartTimer(1);113 this->timer500Started = true;114 this->meter->Visible = true;115 }116 }117 }118 }119 }120 }121}122123//This callback is called every time device is about to render visuals. Use it for calling your rendering code.124void Jukebox::on_Render(std::array<Cubios::Screen, 3>& screens)125{126 for(auto it = screens.begin(); it != screens.end(); ++it)127 {128 //Start adding objects to a screen129 it->Begin(TOPOLOGY_orientation_mode_t::ORIENTATION_MODE_GRAVITY,true);130131 //add background132 it->Add(this->Scene[GfxObjects::myBackground]);133134 //add sprites135 it->Add(this->countdown);136 it->Add(this->meter);137138 //Finish adding objects139 it->End();140 }141}142143//The "physics" callback. Gets called recurrently with at least 33ms resolution or less depending on the load.144void Jukebox::on_PhysicsTick(const std::array<Cubios::Screen, 3>& screens)145{146}147148//This callback is called on programmable timer (if any)149void Jukebox::on_Timer(uint8_t timerID)150{151 switch(timerID)152 {153 case 1:154 this->receivedTime+=500;155 this->meter->SetFrame(0);156 break;157 }158}159160//The cube topology change callback. Gets called when cube is twisted and its topological desctiption has been changed161void Jukebox::on_Twist(const Cubios::TOPOLOGY_twistInfo_t& twist)162{163}164165//The "inner network" callback. Gets called when WOWCube module receives a data packet from other module166void Jukebox::on_Message(uint32_t type, uint8_t* pkt, u32_t size)167{168 NetworkMessage nm(pkt,size);169 if(Cubios::cubeN!=0)170 {171 switch(type)172 {173 case 0:174 {175 this->receivedTime = nm.ReadInt(32);176 }177 break;178 case 1:179 {180 if(!this->timer500Started)181 {182 this->StartTimer(1);183 this->timer500Started = true;184 this->meter->Visible = true;185 }186 }187 default:break;188 }189 }190191}192193//The external data transfer callback. Gets called when WOWCube module receives a data over BLE from an external source194void Jukebox::on_ExternalMessage(uint8_t* pkt, u32_t size)195{196}197198//Screen pat callback199void Jukebox::on_Pat(uint32_t count)200{201}