// Main entry point for the application int main() { int i = 0; bool hidden = false; bool adsAvailable = false; bool noView = false; if(AdmobAdsAvailable()){ InitAds("a14bd815ee70598"); adsAvailable = true; } // Wait for a quit request from the host OS while (!s3eDeviceCheckQuitRequest()) { // Fill background blue s3eSurfaceClear(0, 0, 255); // Print a line of debug text to the screen at top left (0,0) // Starting the text with the ` (backtick) char followed by 'x' and a hex value // determines the colour of the text. s3eDebugPrint(120, 150, "`xffffffHello, World!", 0); if (noView){ s3eDebugPrint(120, 190, "`xff1111No view", 0); }else{ s3eDebugPrint(120, 190, "`x11ff11Ok", 0); } // Flip the surface buffer to screen s3eSurfaceShow(); // Sleep for 0ms to allow the OS to process events etc. s3eDeviceYield(1); if(adsAvailable){ i++; if(i>15000){ i = 0; if (hidden) { noView = ShowAds() != 0; } else { noView = HideAds() != 0; } hidden = !hidden; } } s3eKeyboardUpdate(); if(s3eKeyboardGetState(s3eKeyBack) & S3E_KEY_STATE_DOWN){ break; } } return 0; }
S3E_MAIN_DECL int main() { s3eBool available = FortumoAvailable(); Fortumo_SetLoggingEnabled(true); while(!s3eDeviceCheckQuitRequest()) { s3eDeviceYield(0); s3ePointerUpdate(); s3eDebugPrint(0, 30, (available) ? "Fortumo (OK)" : "Fortumo (ERR)", 0); s3eSurfaceShow(); if(available && (s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_PRESSED)) { Fortumo_PaymentRequest *request = Fortumo_PaymentRequest_Create(); Fortumo_PaymentRequest_SetDisplayString(request, "display_string_here"); Fortumo_PaymentRequest_SetService(request, "service_id_here", "app_secret_here"); Fortumo_PaymentRequest_SetProductName(request, "product_name_here"); Fortumo_PaymentRequest_SetConsumable(request, true); Fortumo_MakePayment(request, &Fortumo_OnPaymentComplete, NULL); Fortumo_PaymentRequest_Delete(request); } } return 0; }
void HelloWorldRender() { s3eDebugPrint(120, 150, "`x000000Hello, World!", 0); createButton("Exit"); buttonStatus = "Exit"; s3eSurfaceShow(); }
// Main entry point for the application int main() { message = "`xffffff"; if (s3ePushWooshNotificationsAvailable()) { s3ePushWooshRegister(S3E_PUSHWOOSH_REGISTRATION_SUCCEEDED, (s3eCallback)&OnPushRegistered, 0); s3ePushWooshRegister(S3E_PUSHWOOSH_MESSAGE_RECEIVED, (s3eCallback)&OnPushReceived, 0); s3ePushWooshRegister(S3E_PUSHWOOSH_REGISTRATION_ERROR, (s3eCallback)&OnPushRegisterError, 0); //s3ePushWooshNotificationRegister(); const char* cstrApp = PW_APPID.c_str(); s3ePushWooshNotificationRegisterWithPWAppID(cstrApp); s3ePushWooshStartLocationTracking(); s3ePushWooshNotificationSetBadgeNumber(6); //Sample code for using local notifications //Currently this is available for Android only. You can use default Marmalade extension for iOS local notifications at this time. //s3ePushWooshClearLocalNotifications(); //30 seconds for local notification to fire //s3ePushWooshScheduleLocalNotification("Your pumpkins are ready!", 30, 0); // postEvent example //s3ePushWooshSetUserId("${userId}"); //s3ePushWooshPostEvent("testEvent", "{ \"attribute\" : \"value\" }"); } // Wait for a quit request from the host OS while (!s3eDeviceCheckQuitRequest()) { // Fill background blue s3eSurfaceClear(0, 0, 255); // Print a line of debug text to the screen at top left (0,0) // Starting the text with the ` (backtick) char followed by 'x' and a hex value // determines the colour of the text. s3eDebugPrint(120, 150, message.c_str(), 0); // else // s3eDebugPrint(120, 150, "`xffffffNot available :(", 0); // Flip the surface buffer to screen s3eSurfaceShow(); // Sleep for 0ms to allow the OS to process events etc. s3eDeviceYield(0); } return 0; }
void onRender() { // Get pointer to the screen surface // (pixel depth is 2 bytes by default) uint16* screen = (uint16*)s3eSurfacePtr(); int height = s3eSurfaceGetInt(S3E_SURFACE_HEIGHT); int width = s3eSurfaceGetInt(S3E_SURFACE_WIDTH); int pitch = s3eSurfaceGetInt(S3E_SURFACE_PITCH); // Clear screen to white for (int i=0; i < height; i++) { memset((char*)screen + pitch * i, 255, (width * 2)); } // Print Hello World s3eDebugPrint(10, 20, "`x000000Hello World", 0); }
// Helper function to display message for Debug-Only Examples void DisplayMessage(const char* strmessage) { uint16* screen = (uint16*)s3eSurfacePtr(); int32 width = s3eSurfaceGetInt(S3E_SURFACE_WIDTH); int32 height = s3eSurfaceGetInt(S3E_SURFACE_HEIGHT); int32 pitch = s3eSurfaceGetInt(S3E_SURFACE_PITCH); for (int y = 0; y < height; y++) for (int x = 0; x < width; x++) screen[y * pitch/2 + x] = 0; s3eDebugPrint(0, 10, strmessage, 1); s3eSurfaceShow(); while (!s3eDeviceCheckQuitRequest() && !s3eKeyboardAnyKey()) { s3eDeviceYield(0); s3eKeyboardUpdate(); } }
static void SoftkeyRender(const char* text, s3eDeviceSoftKeyPosition pos, void(*handler)()) { // Get area of text displayed int width = s3eDebugGetInt(S3E_DEBUG_FONT_SIZE_WIDTH); int height = s3eDebugGetInt(S3E_DEBUG_FONT_SIZE_HEIGHT); width *= strlen(text) - 8; //-8 to ignore colour flag (e.g. "`x666666") // Expand area by half text height to make easier to click width += height; height += height; int x = 0; int y = 0; switch (pos) { case S3E_DEVICE_SOFTKEY_BOTTOM_LEFT: y = s3eSurfaceGetInt(S3E_SURFACE_HEIGHT) - height; x = 0; break; case S3E_DEVICE_SOFTKEY_BOTTOM_RIGHT: y = s3eSurfaceGetInt(S3E_SURFACE_HEIGHT) - height; x = s3eSurfaceGetInt(S3E_SURFACE_WIDTH) - width; break; case S3E_DEVICE_SOFTKEY_TOP_RIGHT: y = 0; x = s3eSurfaceGetInt(S3E_SURFACE_WIDTH) - width; break; case S3E_DEVICE_SOFTKEY_TOP_LEFT: x = 0; y = 0; break; } s3eDebugPrint(x + (height/4), y + (height/4), text, 0); // place in centre of touchable area if (s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_PRESSED) { int pointerx = s3ePointerGetX(); int pointery = s3ePointerGetY(); if (pointerx >= x && pointerx <= x+width && pointery >=y && pointery <= y+height) handler(); } }
void ExampleRender() { // Get pointer to the screen surface // (pixel depth is 2 bytes by default) uint16* screen = (uint16*)s3eSurfacePtr(); int height = s3eSurfaceGetInt(S3E_SURFACE_HEIGHT); int width = s3eSurfaceGetInt(S3E_SURFACE_WIDTH); int pitch = s3eSurfaceGetInt(S3E_SURFACE_PITCH); // Clear screen to white for (int i=0; i < height; i++) { memset((char*)screen + pitch * i, 255, (width * 2)); } // This was causing an error to pop up. s3ePointerUpdate(); ButtonsRender(); s3eDebugPrint(20, 365, g_TouchEventMsg, 1); }
static void RenderSoftkey(const char* text, s3eDeviceSoftKeyPosition pos, void(*handler)()) { int width = 7; int height = 10; width *= strlen(text); int x = 0; int y = 0; switch (pos) { case S3E_DEVICE_SOFTKEY_BOTTOM_LEFT: y = Iw2DGetSurfaceHeight() - height; x = 0; break; case S3E_DEVICE_SOFTKEY_BOTTOM_RIGHT: y = Iw2DGetSurfaceHeight() - height; x = Iw2DGetSurfaceWidth() - width; break; case S3E_DEVICE_SOFTKEY_TOP_RIGHT: y = 0; x = Iw2DGetSurfaceWidth() - width; break; case S3E_DEVICE_SOFTKEY_TOP_LEFT: x = 0; y = 0; break; } char buffer[256] = "`x808080"; strcat(buffer, text); s3eDebugPrint(x, y, buffer, false); if (s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_PRESSED) { int pointerx = s3ePointerGetX(); int pointery = s3ePointerGetY(); if (pointerx >= x && pointerx <= x+width && pointery >=y && pointery <= y+height) handler(); } }
void ButtonsRender() { int previousDebugTextSize = s3eDebugGetInt(S3E_DEBUG_FONT_SCALE); int fontScale = g_ButtonScale; char buf[128]; // select double sized text if (previousDebugTextSize != (int)g_ButtonScale) s3eDebugSetInt(S3E_DEBUG_FONT_SCALE, g_ButtonScale); // find out the dimensions of the font const int textWidthDefault = s3eDebugGetInt(S3E_DEBUG_FONT_SIZE_WIDTH); const int textHeight = s3eDebugGetInt(S3E_DEBUG_FONT_SIZE_HEIGHT); // get the current pointer position and selection state int pointerX = s3ePointerGetX(); int pointerY = s3ePointerGetY(); s3ePointerState pointerState = s3ePointerGetState(S3E_POINTER_BUTTON_SELECT); int x = 10; int y = 50; g_SelectedButton = 0; // draw the buttons for (Button* iter = g_ButtonsHead; iter; iter = iter->m_Next) { if (!iter->m_Display) continue; if (g_HideDisabledButtons && !iter->m_Enabled) continue; fontScale = g_ButtonScale; int textWidth = textWidthDefault; if (s3eDebugGetInt(S3E_DEBUG_FONT_SCALE) != fontScale) s3eDebugSetInt(S3E_DEBUG_FONT_SCALE, fontScale); if (iter->m_Key != S3E_KEY_INVALID) { if (s3eKeyboardGetState(iter->m_Key) & S3E_KEY_STATE_PRESSED) { g_SelectedButton = iter; s3eDebugTracePrintf("button selected using key"); } } if (iter->m_Key != S3E_KEY_INVALID) { char keyName[32]; s3eKeyboardGetDisplayName(keyName, iter->m_Key); if (iter->m_Enabled) snprintf(buf, sizeof(buf), "`x000000%s: %s", keyName, iter->m_Name); else snprintf(buf, sizeof(buf), "`xa0a0a0%s: %s", keyName, iter->m_Name); } else { if (iter->m_Enabled) snprintf(buf, sizeof(buf), "`x000000%s", iter->m_Name); else snprintf(buf, sizeof(buf), "`xa0a0a0%s", iter->m_Name); } int len = strlen(buf) - 8; int _x0 = x - 2; int _y0 = y - 4; int _h = textHeight + 4; int _y1 = _y0 + _h; int _w; int _x1; int textOffset = 0; // Scale down font size if button contents are too long for screen while (true) { _w = (textWidth * len) + 8; _x1 = _x0 + _w; if (fontScale == 1 || _x1 <= s3eSurfaceGetInt(S3E_SURFACE_WIDTH)) break; fontScale -= 1; s3eDebugSetInt(S3E_DEBUG_FONT_SCALE, fontScale); textWidth = s3eDebugGetInt(S3E_DEBUG_FONT_SIZE_WIDTH); textOffset += (textHeight-s3eDebugGetInt(S3E_DEBUG_FONT_SIZE_HEIGHT))/2; } if (pointerX >= _x0 && pointerX <= _x1 && pointerY >= _y0 && pointerY <= _y1 && iter->m_Enabled) { if (pointerState & S3E_POINTER_STATE_DOWN) DrawRect(_x0, _y0, _w, _h, 0, 255, 0); else DrawRect(_x0, _y0, _w, _h, 255, 0, 0); if (pointerState & S3E_POINTER_STATE_RELEASED) g_SelectedButton = iter; } else { if (iter->m_Enabled) DrawRect(_x0, _y0, _w, _h, 255, 0, 0); else DrawRect(_x0, _y0, _w, _h, 127, 0, 0); } s3eDebugPrint(x, y+textOffset, buf, 0); // Store button's position and size iter->m_XPos = _x0; iter->m_YPos = _y0; iter->m_Width = _w; iter->m_Height = _h; y = y + textHeight * 2; } if (g_SelectedButton && g_SelectedButton->m_Callback) g_SelectedButton->m_Callback(g_SelectedButton); if (previousDebugTextSize != fontScale) s3eDebugSetInt(S3E_DEBUG_FONT_SCALE, previousDebugTextSize); g_YBelowButtons = y; }
void CGame::PlayAudio() { if(_currentLevel==0) { if(lastPlayedMusic==-1||lastPlayedMusic==0) { if(!_Music_1->Update(_UI->isMusicPlay)) s3eDebugPrint(300, 100, "error Audio support", 0); lastPlayedMusic=0; //std::cout<<"played first"<<std::endl; } else if(lastPlayedMusic==1) { _Music_2->Stop(); if(!_Music_1->Update(_UI->isMusicPlay)) s3eDebugPrint(300, 100, "error Audio support", 0); lastPlayedMusic=0; } } else { if(lastPlayedMusic==1) { if(!_Music_2->Update(_UI->isMusicPlay)) s3eDebugPrint(300, 100, "error Audio support", 0); lastPlayedMusic=1; //std::cout<<"played first"<<std::endl; } else { _Music_1->Stop(); if(!_Music_2->Update(_UI->isMusicPlay)) s3eDebugPrint(300, 100, "error Audio support", 0); lastPlayedMusic=1; } } //if(lastPlayedMusic==-1) //{ // if(!_Music_1->Update(_UI->isMusicPlay)) // s3eDebugPrint(300, 100, "error Audio support", 0); // lastPlayedMusic=0; // //std::cout<<"played first"<<std::endl; //} //else if(lastPlayedMusic==0) //{ // if(_Music_1->g_Status_RN==STOPPED) // { // if(!_Music_2->Update(_UI->isMusicPlay)) // s3eDebugPrint(300, 100, "error Audio support", 0); // lastPlayedMusic=1; // //std::cout<<"played second"<<std::endl; // } // else // { // if(!_Music_1->Update(_UI->isMusicPlay)) // s3eDebugPrint(300, 100, "error Audio support", 0); // } //} //else if(lastPlayedMusic==1) //{ // if(_Music_2->g_Status_RN==STOPPED) // { // if(!_Music_1->Update(_UI->isMusicPlay)) // s3eDebugPrint(300, 100, "error Audio support", 0); // lastPlayedMusic=0; // } // else // { // if(!_Music_2->Update(_UI->isMusicPlay)) // s3eDebugPrint(300, 100, "error Audio support", 0); // } //} }
void CGame::OnPlaying(int deltaTime) { if(!_levelFinish) _timeLevelCost+=deltaTime; //UpdateInput(deltaTime); if(currentMap->m_tileRotating) _SE->Play(2); if(current_States==S3E_POINTER_STATE_PRESSED)// Checking if screen has been touched first, otherwise keep character still when start a stage { //CIwFVec2 touch=currentMap->m_Position+GetTouches(S3E_POINTER_STATE_RELEASED); _Character->m_TargetOnScreen=GetTouches(S3E_POINTER_STATE_PRESSED); _Character->m_Target=_Character->m_TargetOnScreen+currentMap->m_Position; } currentMap->SetCharacterIndex(_Character->m_Position); if(currentMap->CheckBlock())// enter maze entrance { if(!currentMap->CheckMazePath()) return; } if(currentMap->CheckEndPoint())// finish a level { _levelFinish=true; if(!_setEndingText) { std::string s="Time: "; float tlc=((float)_timeLevelCost)/1000.0f; //std::string s_temp = boost::lexical_cast<std::string>(tlc); std::ostringstream ss; ss << tlc; s.append(ss.str()); s.append("\tRotate: "); //char *txt=(char*)s.c_str(); ss.flush(); ss.clear(); std::ostringstream ss_R; ss_R<<currentMap->m_rotateCount; ss_R.flush(); ss_R.clear(); s.append(ss_R.str()); std::cout<<s<<std::endl; _UI->m_EndPanel->SetText(s,CIwSVec2(Iw2DGetSurfaceWidth()/2-150,Iw2DGetSurfaceHeight()/2+50),2,0x00008800); _setEndingText=true; } _UI->m_EndPanel->SetVisible(true); int tou=_UI->IsTouched(); if(tou==BTN_E_RETURN) { delete _MapLevel[_MapLevel.size()-1]; _MapLevel.pop_back(); int door_Index=_MapLevel[0]->m_doors[_currentLevel-1]; _currentLevel=0; currentMap=_MapLevel[_currentLevel]; int pos[2]={door_Index%currentMap->_width+1,door_Index/currentMap->_width+2}; //_Character->Init(currentMap->_StartPos); _Character->Init(pos); currentMap->SetCharacterIndex(_Character->m_Position); //currentMap->Init(); currentMap->Init(pos); } else return; } if(_currentLevel==0) { int doorIndex=currentMap->CheckDoor()+1; //1st level->1st & 2nd level->all levels if(doorIndex>0) EnterLevel(doorIndex); } if(_Character->GetDistanceToTarget()>10.0f) { CIwFVec2 deltaPos=_Character->m_Target - _Character->m_Position; if(deltaPos.x>0) { _Character->_CS=right; } else if(deltaPos.x<0) { _Character->_CS=left; } if(!currentMap->CheckMapEdge()) _Character->m_Target=_Character->m_Position; else { if(_Character->m_Target.x<_Character->m_Position.x-currentMap->m_Position.x) _Character->m_Target.x=_Character->m_Position.x-currentMap->m_Position.x; if(_Character->m_Target.y<_Character->m_Position.y-currentMap->m_Position.y) _Character->m_Target.y=_Character->m_Position.y-currentMap->m_Position.y; if(_Character->m_Target.x>_Character->m_Position.x+currentMap->GetMapSize().x-Iw2DGetSurfaceWidth()-currentMap->m_Position.x) _Character->m_Target.x=_Character->m_Position.x+currentMap->GetMapSize().x-Iw2DGetSurfaceWidth()-currentMap->m_Position.x; if(_Character->m_Target.y>_Character->m_Position.y+currentMap->GetMapSize().y-Iw2DGetSurfaceHeight()-currentMap->m_Position.y) _Character->m_Target.y=_Character->m_Position.y+currentMap->GetMapSize().y-Iw2DGetSurfaceHeight()-currentMap->m_Position.y; float r=deltaPos.x*deltaPos.x+deltaPos.y*deltaPos.y; r=sqrt(r); deltaPos=CIwFVec2(deltaPos.x/r,deltaPos.y/r); CIwFVec2 delta=deltaPos * 9.0f;//calc move steps //CIwFVec2 delta=deltaPos * 0.05f;//calc move steps _Character->m_Position+=delta; currentMap->m_Position+=delta; if(!_SE->Update(true)) s3eDebugPrint(300, 100, "error Audio support", 0); if(currentMap->CheckCollision(_Character->m_Position,_Character->m_CollisionBox,_Character->m_Target,_Character->m_PositionPrev)) { _Character->m_Position=_Character->m_PositionPrev; currentMap->m_Position=currentMap->m_PositionPrev; //CIwFVec2 deltaPos=_Character->m_Target - _Character->m_Position; //float r=deltaPos.x*deltaPos.x+deltaPos.y*deltaPos.y; //r=sqrt(r); //deltaPos=CIwFVec2(deltaPos.x/r,deltaPos.y/r); //CIwFVec2 delta=deltaPos * 10.0f;//calc move steps //CIwFVec2 delta=deltaPos * 0.05f;//calc move steps // //_Character->m_Position+=delta; //currentMap->m_Position+=delta; } } } /*else if(_Character->GetDistanceToTarget()<10.0f) { _Character->m_Position=_Character->m_Target; currentMap->m_Position=_Character->m_Target; }*/ _Character->m_TargetOnScreen=_Character->m_Target-currentMap->m_Position; _Character->m_PositionPrev=_Character->m_Position; currentMap->m_PositionPrev=currentMap->m_Position; }
void createButton(char* p_btnName) { // Draw button area int fontWidth = s3eDebugGetInt(S3E_DEBUG_FONT_WIDTH); int x,y,width; if(p_btnName != NULL && strlen(p_btnName) > 1) width = strlen(p_btnName)*fontWidth+10; int height = 40; //x = IwGxGetScreenWidth() - width; x = s3eSurfaceGetInt(S3E_SURFACE_WIDTH) - width; y = 2; if (!(s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_UP)) { int pointerx = s3ePointerGetX(); int pointery = s3ePointerGetY(); if (pointerx >=x && pointerx <= x+width && pointery >=y && pointery <= y+height) { if (s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_DOWN) { keyPressedState = S3E_KEY_STATE_DOWN; } if (s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_PRESSED) { keyPressedState = S3E_KEY_STATE_PRESSED; } if (s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_RELEASED) { keyPressedState = S3E_KEY_STATE_RELEASED; s3eDebugTraceLine("-------------Example Update Key Released-------------------"); } } } if (s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_RELEASED) { char color[64] = "`xe0ff00"; char* dispText = strcat(color,p_btnName); s3eDebugPrint(x+5, 20, dispText, 0); } if (s3ePointerGetInt(S3E_POINTER_AVAILABLE)) { if (keyPressedState == S3E_KEY_STATE_DOWN) { char color[64] = "`xe0ff00"; char* dispText = strcat(color,p_btnName); s3eDebugPrint(x+5, 20, dispText, 0); } else if(keyPressedState == S3E_KEY_STATE_PRESSED) { DrawButtonRect(x, y, width, height,97,97,249); char color[64] = "`xe0ff00"; char* dispText = strcat(color,p_btnName); s3eDebugPrint(x+5, 20, dispText, 0); } else if(keyPressedState == S3E_KEY_STATE_RELEASED) { s3eSurfaceClear(0,0,0); char color[64] = "`xe0ff00"; char* dispText = strcat(color,p_btnName); s3eDebugPrint(x+5, 20, dispText, 0); } else { char color[64] = "`xD8F809"; char* dispText = strcat(color,p_btnName); s3eDebugPrint(x+5, 20, dispText, 0); } } }