void Game::Init(bool enable_http) { // Init base game CIwGame::Init(enable_http); // Create a scene then add it to the game CIwGameScene* scene = new CIwGameScene(); scene->Init(); scene->setName("MyScene"); scene->setVirtualTransform(320, 480, 0, false, false); addScene(scene); // Create and load resource group that contains our font CIwGameResourceGroup* group = new CIwGameResourceGroup(); group->setGroupFilename("Common.group"); group->Load(); scene->getResourceManager()->addResource(group); // Add to scenes resource manager so that it is auto cleaned up // Create font CIwGameFont* font = new CIwGameFont(); font->setName("trebuchet_12"); font->Init("trebuchet_12", group->getResourceGroup()); scene->getResourceManager()->addResource(font); // Add to scenes resource manager so that it is auto cleaned up // Create a text actor and add it to the scene CIwGameActorText* text = new CIwGameActorText(); scene->addActor(text); CIwRect rect = CIwRect(-100, -20, 200, 40); CIwGameString string = "Hello World"; text->Init(font, rect, string, 0); text->setColour(0xff, 0xff, 0xff, 0xff); }
// // // // InertActor implementation // // // bool FloaterActor::Init(CIwGameFont* font) { CIwRect rect = CIwRect(-64, -16, 128, 32); CIwGameString text; if (!CIwGameActorText::Init(font, rect, text, 0)) return false; Fade = 1.0f; FadeSpeed = 0.01f; ScaleSpeed = 0; return true; }
bool IIwGameBrush::LoadFromXoml(IIwGameXomlResource* parent, bool load_children, CIwGameXmlNode* node) { // Get brush data eIwGameBrushType type = BT_Solid; CIwFVec4 colour; CIwGameString* name = NULL; CIwGameString* image_name = NULL; CIwRect rect = CIwRect(0, 0, 0, 0); CIwRect scale_area = CIwRect(0, 0, 0, 0); CIwGameString* condition = NULL; CIwGameScene* scene = NULL; if (parent != NULL && parent->getClassTypeHash() == CIwGameXomlNames::Actor_Hash) scene = ((CIwGameActor*)parent)->getScene(); else if (parent != NULL && parent->getClassTypeHash() == CIwGameXomlNames::Scene_Hash) scene = (CIwGameScene*)parent; for (CIwGameXmlNode::_AttribIterator it = node->attribs_begin(); it != node->attribs_end(); ++it) { unsigned int attrib_hash = (*it)->getName().getHash(); if (attrib_hash == CIwGameXomlNames::Name_Hash) { name = &(*it)->GetValue(); } else if (attrib_hash == CIwGameXomlNames::Type_Hash) { unsigned int type_hash = (*it)->GetValue().getHash(); if (type_hash == CIwGameXomlNames::Solid_Hash) type = BT_Solid; else if (type_hash == CIwGameXomlNames::Gradient_Hash) type = BT_Gradient; else if (type_hash == CIwGameXomlNames::Image_Hash) type = BT_Image; else if (type_hash == CIwGameXomlNames::Patch9_Hash) type = BT_9Patch; else { CIwGameError::LogError("Error: XOML - Invalid brush type - ", (*it)->GetValue().c_str()); return false; } } else if (attrib_hash == CIwGameXomlNames::Colour_Hash) { if (!(*it)->GetValueAsPoint4(colour)) CIwGameError::LogError("Warning: XOML - Brush Colour should be a vec4"); } else if (attrib_hash == CIwGameXomlNames::Image_Hash) { image_name = &(*it)->GetValue(); type = BT_Image; } else if (attrib_hash == CIwGameXomlNames::SrcRect_Hash) { if (!(*it)->GetValueAsRect(rect)) CIwGameError::LogError("Warning: XOML - Brush SrcRect should be a rect"); } else if (attrib_hash == CIwGameXomlNames::Tag_Hash) { setTag((*it)->GetValue().c_str()); } else if (attrib_hash == CIwGameXomlNames::ScaleArea_Hash) { if (!(*it)->GetValueAsRect(scale_area)) CIwGameError::LogError("Warning: XOML - Brush ScaleArea should be a rect"); } else if (attrib_hash == CIwGameXomlNames::Condition_Hash) { condition = &(*it)->GetValue(); } } if (condition != NULL) { // Find the condition variable bool condition_not = false; CIwGameXomlVariable* var = NULL; if (*(condition->c_str()) == '!') { condition_not = true; CIwGameString cond = condition->c_str() + 1; var = CIwGameXomlVariable::GetVariable(cond, scene); } else var = CIwGameXomlVariable::GetVariable(*condition, scene); if (var != NULL) { bool res = var->isTrue(); if (condition_not) res = !res; if (!res) { IW_GAME_XOML->setExitOnError(false); return false; } } #if defined (_DEBUG) else CIwGameError::LogError("Warning: condition variable not found - ", condition->c_str()); #endif // _DEBUG } IIwGameBrush* brush = NULL; switch (type) { case BT_Solid: { CIwGameBrushSolid* b = new CIwGameBrushSolid(); b->setColour((uint8)colour.x, (uint8)colour.y, (uint8)colour.z, (uint8)colour.w); brush = b; } break; case BT_Gradient: { } break; case BT_Image: case BT_9Patch: { CIwGameImage* image = NULL; if (image_name == NULL) { CIwGameError::LogError("Error: An image / patch9 brush requires an image to be specified"); return false; } if (scene != NULL) { image = (CIwGameImage*)scene->getResourceManager()->findResource(image_name->getHash(), CIwGameXomlNames::Image_Hash); if (image == NULL) CIwGameError::LogError("Warning: XOML - Brush - Could not find brush image - ", image_name->c_str()); } else { image = (CIwGameImage*)IW_GAME_GLOBAL_RESOURCES->getResourceManager()->findResource(image_name->getHash(), CIwGameXomlNames::Image_Hash); if (image == NULL) CIwGameError::LogError("Warning: XOML - Brush - Could not find brush image - ", image_name->c_str()); } if (image != NULL) { if (type == BT_Image) { CIwGameBrushImage* b = new CIwGameBrushImage(); b->setImage(image); b->setSrcRect(rect); brush = b; } else if (type == BT_9Patch) { CIwGameBrushImage9* b = new CIwGameBrushImage9(); b->setImage(image); b->setSrcRect(rect); b->setScalableArea(scale_area); brush = b; } } } break; } if (brush != NULL) { brush->setName(name->c_str()); brush->setBrushType(type); // If we are declared inside a scene then material is local to the scene if (scene != NULL) scene->getResourceManager()->addResource(brush); else IW_GAME_GLOBAL_RESOURCES->getResourceManager()->addResource(brush); } IW_GAME_XOML->setExitOnError(false); return false; }
void MenuScreen::Render() { sprite.Render(); if( type == MENU ) { for( int i = 0; i < buttonCount; i++ ) { switch( i ) { case 0: //button[i].setLocation( sprite.position.x - 75, sprite.position.y + 122 ); button[i].setLocation( sprite.position.x, sprite.position.y); // The sprite is the center of the image break; case 1: //button[i].setLocation( sprite.position.x + IwGxGetScreenWidth() * .031, sprite.position.y + IwGxGetScreenHeight() * .381 ); button[i].setLocation( sprite.position.x, sprite.position.y + IwGxGetScreenHeight() * .381 ); break; } button[i].Render(); } } else if( type == CHALLENGE ) { int row = 1; int column = 1; for( int i = 0; i < buttonCount; i++ ) { button[i].setLocation( (column*buttonSprite[i].size.x + 30*(column) + 35) + (sprite.position.x - IwGxGetScreenWidth()/2), (row*buttonSprite[i].size.y + 15*(row) + 5) + (sprite.position.y - IwGxGetScreenHeight()/2) ); button[i].Render(); // increment the rows/columns column++; if( column >= 6 ) { column = 1; row++; } } } else if( type == HIGH_SCORE ) { if( s3eDeviceGetInt( S3E_DEVICE_OS ) == S3E_OS_ID_IPHONE ) { for( int i = 0; i < buttonCount; i++ ) { switch( i ) { case 0: //button[i].setLocation( sprite.position.x - 75, sprite.position.y + 122 ); button[i].setLocation( sprite.position.x - IwGxGetScreenWidth() * .156, sprite.position.y + IwGxGetScreenHeight() * .381 ); button[i].Render(); break; case 1: //button[i].setLocation( sprite.position.x + 97, sprite.position.y + 122 ); button[i].setLocation( sprite.position.x + IwGxGetScreenWidth() * .202, sprite.position.y + IwGxGetScreenHeight() * .381); button[i].Render(); break; case 2: // render black trophies //button[i].setLocation( sprite.position.x - 190, sprite.position.y - 75 ); button[i].setLocation( sprite.position.x - IwGxGetScreenWidth() * .396, sprite.position.y - IwGxGetScreenHeight() * .234); if( trophies[0] == false ) { button[i].Render(); } break; case 3: //button[i].setLocation( sprite.position.x + 183, sprite.position.y - 80 ); button[i].setLocation( sprite.position.x + IwGxGetScreenWidth() * .381, sprite.position.y - IwGxGetScreenHeight() * .25 ); if( trophies[1] == false ) { button[i].Render(); } break; case 4: //button[i].setLocation( sprite.position.x - 190, sprite.position.y + 50 ); button[i].setLocation( sprite.position.x - IwGxGetScreenWidth() * .396, sprite.position.y + IwGxGetScreenHeight() * .156); if( trophies[2] == false ) { button[i].Render(); } break; case 5: //button[i].setLocation( sprite.position.x + 12, sprite.position.y + 63 ); button[i].setLocation( sprite.position.x + IwGxGetScreenWidth() * .025, sprite.position.y + IwGxGetScreenHeight() * .197); if( trophies[3] == false ) { button[i].Render(); } break; case 6: //button[i].setLocation( sprite.position.x + 187, sprite.position.y + 45 ); button[i].setLocation( sprite.position.x + IwGxGetScreenWidth() * .390, sprite.position.y + IwGxGetScreenHeight() * .141); if( trophies[4] == false ) { button[i].Render(); } break; case 7: //button[i].setLocation( sprite.position.x - 190, sprite.position.y - 75 ); button[i].setLocation( sprite.position.x - IwGxGetScreenWidth() * .396, sprite.position.y - IwGxGetScreenHeight() * .234); if( trophies[0] == true ) { button[i].Render(); } break; case 8: //button[i].setLocation( sprite.position.x + 183, sprite.position.y - 80 ); button[i].setLocation( sprite.position.x + IwGxGetScreenWidth() * .381, sprite.position.y - IwGxGetScreenHeight() * .25); if( trophies[1] == true ) { button[i].Render(); } break; case 9: //button[i].setLocation( sprite.position.x - 190, sprite.position.y + 50 ); button[i].setLocation( sprite.position.x - IwGxGetScreenWidth() * .396, sprite.position.y + IwGxGetScreenHeight() * .156); if( trophies[2] == true ) { button[i].Render(); } break; case 10: //button[i].setLocation( sprite.position.x + 12, sprite.position.y + 63 ); button[i].setLocation( sprite.position.x + IwGxGetScreenWidth() * .025, sprite.position.y + IwGxGetScreenHeight() * .197); if( trophies[3] == true ) { button[i].Render(); } break; case 11: //button[i].setLocation( sprite.position.x + 187, sprite.position.y + 45 ); button[i].setLocation( sprite.position.x + IwGxGetScreenWidth() * .390, sprite.position.y + IwGxGetScreenHeight() * .141); if( trophies[4] == true ) { button[i].Render(); } break; case 12: //button[i].setLocation( sprite.position.x + 187, sprite.position.y + 45 ); button[i].setLocation( sprite.position.x + IwGxGetScreenWidth() * 0, sprite.position.y + IwGxGetScreenHeight() * .381); button[i].Render(); break; } } } // end of if OS is iphone, and rendering trophies else // if OS is NOT iphone, do not render rate trophy, or rate button. In fact, just move them off the screen. { for( int i = 0; i < buttonCount; i++ ) { switch( i ) { case 0: // RATE BUTTON OFFSET OFF SCREEN //button[i].setLocation( sprite.position.x - 75, sprite.position.y + 122 ); //button[i].setLocation( sprite.position.x - IwGxGetScreenWidth() * .156, sprite.position.y + IwGxGetScreenHeight() * .381 ); button[i].setLocation( -IwGxGetScreenWidth() * 2, IwGxGetScreenHeight() ); button[i].Render(); break; case 1: // BACK button //button[i].setLocation( sprite.position.x + 97, sprite.position.y + 122 ); button[i].setLocation( sprite.position.x + IwGxGetScreenWidth() * .202, sprite.position.y + IwGxGetScreenHeight() * .381); button[i].Render(); break; case 2: // render black trophies //button[i].setLocation( sprite.position.x - 190, sprite.position.y - 75 ); button[i].setLocation( sprite.position.x - IwGxGetScreenWidth() * .396, sprite.position.y - IwGxGetScreenHeight() * .234); if( trophies[0] == false ) { button[i].Render(); } break; case 3: //button[i].setLocation( sprite.position.x + 183, sprite.position.y - 80 ); button[i].setLocation( sprite.position.x + IwGxGetScreenWidth() * .381, sprite.position.y - IwGxGetScreenHeight() * .25 ); if( trophies[1] == false ) { button[i].Render(); } break; case 4: // Fuzzy Reviewer Trophy OFFSET OFF SCREEN //button[i].setLocation( sprite.position.x - 190, sprite.position.y + 50 ); //button[i].setLocation( sprite.position.x - IwGxGetScreenWidth() * .396, sprite.position.y + IwGxGetScreenHeight() * .156); button[i].setLocation( -IwGxGetScreenWidth() * 2, IwGxGetScreenHeight() ); if( trophies[2] == false ) { button[i].Render(); } break; case 5: // Fuzzy 1 mill points shifted to reviewer spot //button[i].setLocation( sprite.position.x + 12, sprite.position.y + 63 ); //button[i].setLocation( sprite.position.x + IwGxGetScreenWidth() * .025, sprite.position.y + IwGxGetScreenHeight() * .197); button[i].setLocation( sprite.position.x - 190, sprite.position.y + 50 ); if( trophies[3] == false ) { button[i].Render(); } break; case 6: //button[i].setLocation( sprite.position.x + 187, sprite.position.y + 45 ); button[i].setLocation( sprite.position.x + IwGxGetScreenWidth() * .390, sprite.position.y + IwGxGetScreenHeight() * .141); if( trophies[4] == false ) { button[i].Render(); } break; case 7: //button[i].setLocation( sprite.position.x - 190, sprite.position.y - 75 ); button[i].setLocation( sprite.position.x - IwGxGetScreenWidth() * .396, sprite.position.y - IwGxGetScreenHeight() * .234); if( trophies[0] == true ) { button[i].Render(); } break; case 8: //button[i].setLocation( sprite.position.x + 183, sprite.position.y - 80 ); button[i].setLocation( sprite.position.x + IwGxGetScreenWidth() * .381, sprite.position.y - IwGxGetScreenHeight() * .25); if( trophies[1] == true ) { button[i].Render(); } break; case 9: // Fuzzy Reviewer Trophy OFFSET OFF SCREEN //button[i].setLocation( sprite.position.x - 190, sprite.position.y + 50 ); //button[i].setLocation( sprite.position.x - IwGxGetScreenWidth() * .396, sprite.position.y + IwGxGetScreenHeight() * .156); button[i].setLocation( -IwGxGetScreenWidth() * 2, IwGxGetScreenHeight() ); if( trophies[2] == true ) { button[i].Render(); } break; case 10: // Fuzzy 1 mill points shifted to reviewer spot //button[i].setLocation( sprite.position.x + 12, sprite.position.y + 63 ); //button[i].setLocation( sprite.position.x + IwGxGetScreenWidth() * .025, sprite.position.y + IwGxGetScreenHeight() * .197); button[i].setLocation( sprite.position.x - 190, sprite.position.y + 50 ); if( trophies[3] == true ) { button[i].Render(); } break; case 11: //button[i].setLocation( sprite.position.x + 187, sprite.position.y + 45 ); button[i].setLocation( sprite.position.x + IwGxGetScreenWidth() * .390, sprite.position.y + IwGxGetScreenHeight() * .141); if( trophies[4] == true ) { button[i].Render(); } break; case 12: //button[i].setLocation( sprite.position.x + 187, sprite.position.y + 45 ); button[i].setLocation( sprite.position.x + IwGxGetScreenWidth() * 0, sprite.position.y + IwGxGetScreenHeight()*.381); button[i].Render(); break; } } } // end of rendering non-iOS versions for trophies and buttons // need to render the current images because fonts are automatically displayed underneath them. IwGxFlush(); // the high score CIwGxFontPreparedData scoreData; char scoreChar[100] = ""; std::ostringstream scoreStringStream; scoreStringStream << highScore; string scoreString = scoreStringStream.str(); strcat( scoreChar, scoreString.c_str() ); // draw the shadow //IwGxFontSetCol(0xffaaffff); IwGxFontSetCol(0xff330000); //IwGxFontSetRect( CIwRect( sprite.position.x - (scoreString.length()/2 * 10), sprite.position.y - 100, 500, 300 ) ); // major glitch here. the size of score affects size of time. vice versa IwGxFontSetRect( CIwRect( sprite.position.x - (scoreString.length()/2 * 10), sprite.position.y - IwGxGetScreenHeight() * .312, 500, 300 ) ); // major glitch here. the size of score affects size of time. vice versa IwGxFontPrepareText( scoreData, scoreChar ); IwGxFontDrawText( scoreData ); // draw the text IwGxFontSetCol(0xff66ffff); //IwGxFontSetRect( CIwRect( sprite.position.x - (scoreString.length()/2 * 10) - 1, sprite.position.y - 100 - 2, 500, 300 ) ); // major glitch here. the size of score affects size of time. vice versa IwGxFontSetRect( CIwRect( sprite.position.x - (scoreString.length()/2 * 10) - IwGxGetScreenWidth()*.002, sprite.position.y - IwGxGetScreenHeight() * .319, 500, 300 ) ); // major glitch here. the size of score affects size of time. vice versa IwGxFontPrepareText( scoreData, scoreChar ); IwGxFontDrawText( scoreData ); // the time played // the high score CIwGxFontPreparedData timeData; char timeChar[100] = ""; std::ostringstream timeStringStream; timeStringStream << timeHours << " hours " << timeMinutes << " minutes " << timeSeconds << " seconds"; string timeString = timeStringStream.str(); strcat( timeChar, timeString.c_str() ); // draw the shadow //IwGxFontSetCol(0xffaaffff); IwGxFontSetCol(0xff330000); //IwGxFontSetRect( CIwRect( sprite.position.x - (timeString.length()/2 * 10), sprite.position.y - 15, 400, 300 ) ); if( IwGxGetScreenHeight() >= 640 ) { IwGxFontSetRect( CIwRect( sprite.position.x - (timeString.length()/2 * 20), sprite.position.y - IwGxGetScreenHeight() * .047, IwGxGetScreenWidth(), IwGxGetScreenHeight() ) ); } else if( IwGxGetScreenHeight() >= 480 ) { IwGxFontSetRect( CIwRect( sprite.position.x - (timeString.length()/2 * 15), sprite.position.y - IwGxGetScreenHeight() * .047, IwGxGetScreenWidth(), IwGxGetScreenHeight() ) ); } else //if( IwGxGetScreenHeight() >= 320 ) { IwGxFontSetRect( CIwRect( sprite.position.x - (timeString.length()/2 * 10), sprite.position.y - IwGxGetScreenHeight() * .047, IwGxGetScreenWidth(), IwGxGetScreenHeight() ) ); } IwGxFontPrepareText( timeData, timeChar ); IwGxFontDrawText( timeData ); // draw the text IwGxFontSetCol(0xff66ffff); //IwGxFontSetRect( CIwRect( sprite.position.x - (timeString.length()/2 * 10) - 1, sprite.position.y - 15 - 2, 400, 300 ) ); if( IwGxGetScreenHeight() >= 640 ) { IwGxFontSetRect( CIwRect( sprite.position.x - (timeString.length()/2 * 20) - IwGxGetScreenWidth()*.002, sprite.position.y - IwGxGetScreenHeight() * .053, IwGxGetScreenWidth(), IwGxGetScreenHeight() ) ); } else if( IwGxGetScreenHeight() >= 480 ) { IwGxFontSetRect( CIwRect( sprite.position.x - (timeString.length()/2 * 15) - IwGxGetScreenWidth()*.002, sprite.position.y - IwGxGetScreenHeight() * .053, IwGxGetScreenWidth(), IwGxGetScreenHeight() ) ); } else //if( IwGxGetScreenHeight() >= 320 ) { IwGxFontSetRect( CIwRect( sprite.position.x - (timeString.length()/2 * 10) - IwGxGetScreenWidth()*.002, sprite.position.y - IwGxGetScreenHeight() * .053, IwGxGetScreenWidth(), IwGxGetScreenHeight() ) ); } IwGxFontPrepareText( timeData, timeChar ); IwGxFontDrawText( timeData ); } else if( type == CREDITS ) { for( int i = 0; i < buttonCount; i++ ) { switch( i ) { case 0: //button[i].setLocation( sprite.position.x - 75, sprite.position.y + 122 ); button[i].setLocation( sprite.position.x - IwGxGetScreenWidth() * .156, sprite.position.y + IwGxGetScreenHeight() * .381 ); break; case 1: //button[i].setLocation( sprite.position.x + 15, sprite.position.y + 122 ); button[i].setLocation( sprite.position.x + IwGxGetScreenWidth() * .031, sprite.position.y + IwGxGetScreenHeight() * .381 ); button[i].Render(); // only render back button break; } } } else if( type == TUTORIAL ) { for( int i = 0; i < buttonCount; i++ ) { switch( i ) { case 0: // the back button //button[i].setLocation( sprite.position.x + 180, sprite.position.y + 122 ); button[i].setLocation( sprite.position.x + IwGxGetScreenWidth() * .375, sprite.position.y + IwGxGetScreenHeight() * .381); break; case 1: //button[i].setLocation( sprite.position.x - 60, sprite.position.y + 125 ); button[i].setLocation( sprite.position.x - IwGxGetScreenWidth() * .125, sprite.position.y + IwGxGetScreenHeight() * .390 ); break; case 2: //button[i].setLocation( sprite.position.x + 0, sprite.position.y + 125 ); button[i].setLocation( sprite.position.x + IwGxGetScreenWidth() * 0, sprite.position.y + IwGxGetScreenHeight() * .390); break; case 3: //button[i].setLocation( sprite.position.x + 60, sprite.position.y + 125 ); button[i].setLocation( sprite.position.x + IwGxGetScreenWidth() * .125, sprite.position.y + IwGxGetScreenHeight() * .390); break; } button[i].Render(); } } else if( type == QUIT_CONFIRMATION ) { for( int i = 0; i < buttonCount; i++ ) { switch( i ) { case 0: // the back button //button[i].setLocation( sprite.position.x - 60, sprite.position.y + 45 ); button[i].setLocation( sprite.position.x - IwGxGetScreenWidth() * .125, sprite.position.y + IwGxGetScreenHeight() * .140 ); break; case 1: //button[i].setLocation( sprite.position.x + 60, sprite.position.y + 45 ); button[i].setLocation( sprite.position.x + IwGxGetScreenWidth() * .125, sprite.position.y + IwGxGetScreenHeight() * .140 ); break; } button[i].Render(); } } else if( type == NEW_STORY_CONFIRMATION ) { for( int i = 0; i < buttonCount; i++ ) { switch( i ) { case 0: // the back button //button[i].setLocation( sprite.position.x - 60, sprite.position.y + 50 ); button[i].setLocation( sprite.position.x - IwGxGetScreenWidth() * .125, sprite.position.y + IwGxGetScreenHeight() * .156 ); break; case 1: //button[i].setLocation( sprite.position.x + 60, sprite.position.y + 50 ); button[i].setLocation( sprite.position.x + IwGxGetScreenWidth() * .125, sprite.position.y + IwGxGetScreenHeight() * .156 ); break; } button[i].Render(); } } }