void renderMap() { IwGxLightingOff(); CIwMaterial* pMat = IW_GX_ALLOC_MATERIAL(); pMat->SetModulateMode(CIwMaterial::MODULATE_NONE); pMat->SetTexture(mapTexture); IwGxSetMaterial(pMat); IwGxSetScreenSpaceSlot(-1); float zoom = getMapZoom()->getZoom(); int16 hScrW = (double)IwGxGetScreenWidth()*0.5f; int16 hScrH = (double)IwGxGetScreenHeight()*0.5f; int16 x1 = hScrW - hScrW*zoom; int16 x2 = hScrW + hScrW*zoom; int16 y1 = hScrH - hScrH*zoom; int16 y2 = hScrH + hScrH*zoom; mapVertZoom[0].x = x1, mapVertZoom[0].y = y1; mapVertZoom[1].x = x1, mapVertZoom[1].y = y2; mapVertZoom[2].x = x2, mapVertZoom[2].y = y2; mapVertZoom[3].x = x2, mapVertZoom[3].y = y1; IwGxSetUVStream(mapDefaultUvs); IwGxSetVertStreamScreenSpace(mapVertZoom, 4); IwGxDrawPrims(IW_GX_QUAD_LIST, NULL, 4); }
void PatteRunGameEngine::RenderStatus(CIwUIRect& bounds) { IwGxLightingOn(); IwGxFontSetFont(g_pFont); IwGxFontSetCol(0xffffffff); IwGxFontSetAlignmentVer(IW_GX_FONT_ALIGN_MIDDLE); IwGxFontSetAlignmentHor(IW_GX_FONT_ALIGN_LEFT); CIwRect rect((int16)(bounds.x+5), (int16)bounds.y, (int16)(bounds.w-5), (int16)bounds.h); IwGxFontSetRect(rect); sprintf(g_szStatus, "%06d", g_iDisplayedScore); IwGxFontDrawText(g_szStatus); IwGxFontSetAlignmentHor(IW_GX_FONT_ALIGN_RIGHT); IwGxFontSetFont(g_pFontSmall); rect.w = 80; rect.x = bounds.w - 85; IwGxFontSetRect(rect); sprintf(g_szStatus, "%02d | %02d", g_iGameCounter, g_iLevel+1); IwGxFontDrawText(g_szStatus); IwGxLightingOff(); CIwSVec2 locFly(bounds.w - 85, (bounds.h - g_pTile->GetWidth()) / 2); Utils::AlphaRenderImage(g_pTile, locFly, 255); }
void renderMapHealth() { IwGxLightingOff(); Iw2DSetAlphaMode(IW_2D_ALPHA_NONE); Iw2DSetTransformMatrix(CIwFMat2D::g_Identity); int16 w = (double)IwGxGetScreenWidth() * 0.09f; if (w > (int16)healthTexture->GetWidth()) w = (int16)healthTexture->GetWidth(); float whScale = (float)((double)healthTexture->GetWidth() / healthTexture->GetHeight()); int16 h = w * 1/whScale; int leftPadding = IwGxGetScreenWidth() * 0.10f; int topPadding = IwGxGetScreenHeight() * 0.02f; int leftMargin = IwGxGetScreenWidth() * 0.03f; int topMargin = IwGxGetScreenHeight() * 0.05f; CIwFVec2 size = CIwFVec2(w, h); int vitality = getGameState()->getPlayer()->getVitality(); for (int i = 0; i < PLAYER_MAX_VITALITY; i++) { CIwFVec2 topLeft = CIwFVec2(leftPadding + (leftMargin+w)*i, topPadding); if (i < vitality) { Iw2DDrawImage(healthTexture, topLeft, size); } else { Iw2DDrawImage(healthLostTexture, topLeft, size); } } }
void CRenderer::DrawBatch() { if ( GetVBSize() > 0 ) { IwGxLightingOff(); IwGxSetMaterial( mCurrMtl ); IwGxSetUVStream( mUVB ); IwGxSetColStream(mCB, mCBSize); IwGxSetVertStreamScreenSpaceSubPixel( mVB, mVBSize ); if ( mIBSize == 0 ) { IwGxDrawPrims(mBuffType, NULL, mVBSize); } else { IwGxDrawPrims(mBuffType, mIB, mIBSize); } mCurrMtl = NULL; //DefaultMaterial(); IwGxFlush(); IwGxSetColStream(NULL); //IwGxSetUVStream( NULL ); ResetBuffers(); } }
void ExampleInit() { IW_PROFILE_INIT(); // Initialise IwGxInit(); // Set screen clear colour IwGxSetColClear(0x40, 0x40, 0x40, 0x00); // Turn all lighting off IwGxLightingOff(); // Set field of view IwGxSetPerspMul(0xa0); // Set near and far planes IwGxSetFarZNearZ(0x1000, 0x10); // Set the view matrix along the -ve z axis CIwMat view = CIwMat::g_Identity; view.t.z = -0x200; IwGxSetViewMatrix(&view); //IwGxSetScreenOrient(IW_GX_ORIENT_NONE); s_Accelerometer = (S3E_RESULT_SUCCESS == s3eAccelerometerStart()); m_pAnimator = new CSplineAnimator(); m_pAnimator->Init(); m_pSplinePoly2Tri = new CSplinePoly2Tri(m_pAnimator->GetCurrentSpline()); // ball m_pBall = new CBall(); }
void CRenderer::RenderText( CIwGxFont * font, const CIwRect & rect, const CIwColour & color, const CIwStringS & txt, IwGxFontAlignHor hAlign, IwGxFontAlignVer vAlign ) { iwsfixed scale = IW_SFIXED(mDeviceParams.scale); iwsfixed offX = mDeviceParams.offsetX; iwsfixed offY = mDeviceParams.offsetY; CIwRect r; r.x = IW_FIXED_MUL(rect.x, scale) + offX; r.y = IW_FIXED_MUL(rect.y, scale) + offY; r.w = IW_FIXED_MUL(rect.w, scale); r.h = IW_FIXED_MUL(rect.h, scale); Flush(); DefaultMaterial(); IwGxFontClearFlags(0xffffffff); IwGxLightingOn(); IwGxFontSetFont( font ); IwGxFontSetCol( color ); //IwGxFontSetScale( scale ); //Set the formatting rect - this controls where the text appears and what it is formatted against IwGxFontSetRect(r); IwGxFontSetAlignmentVer(vAlign); IwGxFontSetAlignmentHor(hAlign); //Draw the text IwGxFontDrawText(txt.c_str()); IwGxLightingOff(); IwGxFontFreeBuffers(); Flush(); }
//----------------------------------------------------------------------------- void HexMapTest::Init() { zoom = 1.0f; rotation = 0.0f; screenTranslationX = 0; screenTranslationY = 0; // Initialise the input system g_Input.Init(); // Initialise vectors s_left = CIwVec3::g_AxisX; s_up = -CIwVec3::g_AxisY; s_Angles = CIwSVec3::g_Zero; s_cameraPos = CIwVec3(0, 0, -0x80); // Initialise view matrix s_viewMatrix = CIwMat::g_Identity; s_viewMatrix.SetTrans(s_cameraPos); s_viewMatrix.LookAt( s_viewMatrix.GetTrans(), CIwVec3::g_Zero, -CIwVec3::g_AxisY); // Initialise IwGxInit(); IwResManagerInit(); // Set screen clear colour IwGxSetColClear(0x40, 0x40, 0x40, 0x00); // Turn all lighting off IwGxLightingOff(); // Set field of view IwGxSetPerspMul(0xa0); // Set near and far planes IwGxSetFarZNearZ(0x1000, 0x10); // Create empty texture object s_BitMapTexture = new CIwTexture; // Load image data from disk into texture s_BitMapTexture->LoadFromFile("./textures/testTexture_8bit.bmp"); // "Upload" texture to VRAM s_BitMapTexture->Upload(); // Set the view matrix along the -ve z axis CIwMat view = CIwMat::g_Identity; view.t.z = -0x100; IwGxSetViewMatrix(&view); IwGetResManager()->LoadGroup("TileRes.group"); pGroup = IwGetResManager()->GetGroupNamed("TileRes"); hexGrid = new HexGrid(hexGridMaxX, hexGridMaxY, textureMaxX, textureMaxY); hexGrid->setTexture(IW_TEXTURE(pGroup,"grid"),textureMaxX,textureMaxY); s_ModelMatrix.SetIdentity(); }
void Desktop::init() { IwGxInit(); IwGxLightingOff(); width = IwGxGetScreenWidth(); height = IwGxGetScreenHeight(); IwGxSetColClear(0, 0, 0, 0); vSize = 0; duration = 1000 / 60; devices = new vector<Device>(); defPath = NULL; }
void ciclo() { if (g_Input.getSound()) g_Input.playSong(); while (!s3eDeviceCheckQuitRequest()) { if (g_Input.getLifes()<1) { gameOver(); } if (menuB) break; s3eDeviceBacklightOn(); g_Input.updateSound(); s3eDeviceYield(0); int64 start = s3eTimerGetMs(); bool result = BaconUpdate(); bool result2 = FondoUpdate(); IwGxClear(IW_GX_COLOUR_BUFFER_F | IW_GX_DEPTH_BUFFER_F); IwGxLightingOff(); FondoRender(); LifeStatusRender(); BaconRender(); insertaObstaculos(); spriteManager->render(); chuletas->render(); tank->render(); IwGxLightingOn(); FontLifeRender(); FontCoinsRender(); IwGxFlush(); IwGxSwapBuffers(); //g_Input.setScore(g_Input.getScore()+1); // Attempt frame rate /*while ((s3eTimerGetMs() - start) < MS_PER_FRAME) { int32 yield = (int32) (MS_PER_FRAME - (s3eTimerGetMs() - start)); if (yield<0) break; s3eDeviceYield(yield); }*/ } }
void CRenderer::DrawDirect( IwGxPrimType type, CIwSVec2 * vertex, CIwSVec2 * uv, uint16* indexStream, CIwColour * colour, int32 vertexCount, CIwMaterial * mat ) { IwGxLightingOff(); IwGxSetMaterial( mat ); IwGxSetUVStream( uv ); IwGxSetColStream(colour, vertexCount); IwGxSetVertStreamScreenSpaceSubPixel( vertex, vertexCount ); IwGxDrawPrims(type, indexStream, vertexCount); IwGxFlush(); IwGxSetColStream(NULL); }
void Init() { IwGxInit(); IwGxLightingOff(); gEffects = new MarmaladeEffectsLibrary(); gEffects->Load("particles/data.xml"); gPM = new MarmaladeParticleManager(); gPM->SetScreenSize(IwGxGetScreenWidth(), IwGxGetScreenHeight()); gPM->SetOrigin(0, 0); TLFX::Effect *eff = gEffects->GetEffect("Area Effects/Swirly Balls"); TLFX::Effect *copy = new TLFX::Effect(*eff, gPM); copy->SetPosition(0.0f, 0.0f); gPM->AddEffect(copy); }
void CEndGameState::Render() { IW_CALLSTACK("CEndGameState::Render"); IwGxClear(IW_GX_COLOUR_BUFFER_F | IW_GX_DEPTH_BUFFER_F); GetWorld().Render(); IwGxLightingOff(); IwGxSetScreenSpaceOrg( &CIwSVec2::g_Zero ); CIwColour* cols = IW_GX_ALLOC(CIwColour, 4); memset(cols, 255, sizeof(CIwColour) * 4 ); if (GetWorld().GetUICar()->GetPosition() == 1 ) { CIwMaterial* mat = (CIwMaterial *)IwGetResManager()->GetGroupNamed("ui")->GetResNamed("youwin", IW_GX_RESTYPE_MATERIAL); IwGxSetMaterial(mat); } else { CIwMaterial* mat = (CIwMaterial *)IwGetResManager()->GetGroupNamed("ui")->GetResNamed("youlose", IW_GX_RESTYPE_MATERIAL); IwGxSetMaterial(mat); } const uint32 imageWidth = 128; const uint32 imageHeight = 32; CIwSVec2 XY( (int16)((IwGxGetScreenWidth()/2) - (imageWidth/2)), (int16)(IwGxGetScreenHeight()/4) ), dXY( (int16)imageWidth, (int16)imageHeight ); IwGxDrawRectScreenSpace(&XY, &dXY, cols); IwGxLightingOn(); IwGxFlush(); IwGxSwapBuffers(); #ifdef IW_DEBUG // Reset metrics for next frame IwGxMetricsReset(); #endif }
void renderMapXpBar() { IwGxLightingOff(); Iw2DSetAlphaMode(IW_2D_ALPHA_NONE); Iw2DSetTransformMatrix(CIwFMat2D::g_Identity); int16 w = (double)IwGxGetScreenWidth() * 0.40f; if (w > (double)xpBarTexture->GetWidth() * 1.80f) w = (double)xpBarTexture->GetWidth() * 1.80f; float whScale = (float)((double)xpBarTexture->GetWidth() / xpBarTexture->GetHeight()); int16 h = w * 1/whScale; int rightPadding = IwGxGetScreenWidth() * 0.10f; int topPadding = IwGxGetScreenHeight() * 0.015f; CIwFVec2 size = CIwFVec2(w, h); CIwFVec2 topLeft = CIwFVec2(IwGxGetScreenWidth() - rightPadding - w, topPadding); Iw2DDrawImage(xpBarTexture, topLeft, size); }
void renderCamera() { IwGxLightingOff(); // Refresh dynamic texture if (g_CameraTexture != NULL) g_CameraTexture->ChangeTexels((uint8*)g_pCameraTexelsRGB565, CIwImage::RGB_565); CIwMaterial* pMat = IW_GX_ALLOC_MATERIAL(); pMat->SetModulateMode(CIwMaterial::MODULATE_NONE); pMat->SetTexture(g_CameraTexture); IwGxSetMaterial(pMat); IwGxSetScreenSpaceSlot(-1); IwGxSetUVStream(cameraUvs); IwGxSetVertStreamScreenSpace(cameraVert, 4); IwGxDrawPrims(IW_GX_QUAD_LIST, NULL, 4); }
void CRenderer::Begin() { s3eDeviceYield(0); IwGxLightingOff(); //IwGxLightingAmbient(true); IwGxSetScreenSpaceOrg( &CIwSVec2::g_Zero ); //IwGxSetScreenSpaceSlot( 0 ); //IwGxLightingDiffuse( false ); IwGxClear(IW_GX_COLOUR_BUFFER_F | IW_GX_DEPTH_BUFFER_F); if (mIsResetDeviceparam) { mIsResetDeviceparam = false; UpdateDeviceParams(); if ( mOnResetparams != NULL ) { mOnResetparams(); } } ResetBuffers(); }
void renderMapPlayer() { IwGxLightingOff(); int16 w = IwGxGetScreenWidth()*0.085f; float whScale = (float)((double)playerTexture->GetWidth() / playerTexture->GetHeight()); int16 h = w * 1/whScale; Iw2DSetAlphaMode(IW_2D_ALPHA_NONE); double angle = rad(getGameState()->getPlayer()->getHeading()); Iw2DSetTransformMatrix(CIwFMat2D::g_Identity); CIwFVec2 centre = CIwFVec2((int16)Iw2DGetSurfaceWidth()/2, (int16)Iw2DGetSurfaceHeight()/2); CIwFMat2D rot; rot.SetRot(angle, (CIwFVec2)centre); Iw2DSetTransformMatrix(rot); CIwFVec2 size = CIwFVec2(w, h); CIwFVec2 topLeft = CIwFVec2(centre.x-size.x/2, centre.y-size.y/2); Iw2DDrawImage(playerTexture, topLeft, size); }
void CzPlatformRender::DrawText(CzFontPreparedText prepared_text, CzFont* font, CzMatrix3* transform, const CzColour& colour, CzVec4& skew, bool filter, eCzAlphaMode alpha_mode) { CIwMaterial::AlphaMode am = (CIwMaterial::AlphaMode)alpha_mode; // TODO Add proper method map Marmalade Alpha mode to Marmalade // Cache the transform float m00 = transform->m[0][0]; float m01 = transform->m[0][1]; float m10 = transform->m[1][0]; float m11 = transform->m[1][1]; float tx = transform->getX(); float ty = transform->getY(); float sx1 = (float)skew.x; float sx2 = (float)skew.y; float sy1 = (float)skew.z; float sy2 = (float)skew.w; /* CzIRect clip = ScreenClipRect; clip.x <<= 3; clip.y <<= 3; clip.w = clip.x + (clip.w << 3); clip.h = clip.y + (clip.h << 3);*/ IwGxLightingOn(); IwGxSetColStream(NULL); IwGxSetNormStream(NULL); CIwGxFont* mfont = static_cast<CIwGxFont*>(font->getFontHandle()); CIwGxFontPreparedData* prep_text = static_cast<CIwGxFontPreparedData*>(prepared_text); // A font can consist of multiple materials so we need to process all of them for (int t = 0; t < mfont->GetNumberMaterials(); t++) { // Set UV stream uint32* char_ids; int num_chars = IwGxFontSetUVs(*prep_text, -1, t, &char_ids); // Generate transformed vertices from glyphs int nv = num_chars << 2; CzVec2* pVerts = IW_GX_ALLOC(CzVec2, nv); CzVec2* pVert = pVerts; if (m01 == 0 && m10 == 0) { // No rotation optimisation for (int t2 = 0; t2 < num_chars; t2++) { CIwRect rc = prep_text->GetCharacterArea(char_ids[t2]); float x1 = (float)rc.x; float y1 = (float)rc.y; float x2 = x1 + (float)rc.w; float y2 = y1 + (float)rc.h; float ax = (m00 * x1) + tx; float ay = (m11 * y1) + ty; float bx = (m00 * x2) + tx; float by = (m11 * y2) + ty; // if ((ax < clip.w && bx >= clip.x) && (ay < clip.h && by >= clip.y)) // { pVert->x = ax + sx1; pVert->y = ay + sy1; pVert++; pVert->x = ax - sx1; pVert->y = by + sy2; pVert++; pVert->x = bx - sx2; pVert->y = by - sy2; pVert++; pVert->x = bx + sx2; pVert->y = ay - sy1; pVert++; // } } } else { for (int t2 = 0; t2 < num_chars; t2++) { CIwRect rc = prep_text->GetCharacterArea(char_ids[t2]); float x1 = (float)rc.x; float y1 = (float)rc.y; float x2 = x1 + (float)rc.w; float y2 = y1 + (float)rc.h; pVert->x = (m00 * x1 + m10 * y1 + tx + sx1); pVert->y = (m01 * x1 + m11 * y1 + ty + sy1); pVert++; pVert->x = (m00 * x1 + m10 * y2 + tx - sx1); pVert->y = (m01 * x1 + m11 * y2 + ty + sy2); pVert++; pVert->x = (m00 * x2 + m10 * y2 + tx - sx2); pVert->y = (m01 * x2 + m11 * y2 + ty - sy2); pVert++; pVert->x = (m00 * x2 + m10 * y1 + tx + sx2); pVert->y = (m01 * x2 + m11 * y1 + ty - sy1); pVert++; } } if (nv > 0) { // Set vertex stream IwGxSetVertStreamScreenSpace((CIwFVec2*)pVerts, nv); // Create a material CIwMaterial* mat = IW_GX_ALLOC_MATERIAL(); mat->Copy(*IwGxFontGetFont()->GetMaterial(t)); mat->SetDepthWriteMode(CIwMaterial::DEPTH_WRITE_DISABLED); mat->SetColEmissive(colour.get()); mat->SetClamping(true); mat->SetFiltering(filter); mat->SetAlphaMode(am); mat->SetCullMode(CIwMaterial::CULL_BACK); // mat->SetCullMode(CIwMaterial::CULL_NONE); IwGxSetMaterial(mat); // Finally draw the glyphs IwGxDrawPrims(IW_GX_QUAD_LIST, NULL, nv); CurrentAlphaMode = alpha_mode; } } IwGxLightingOff(); CurrentTexture = NULL; }
void CameraDefend::Render() { if (defended) { IwGxLightingOff(); animMatSuccess->SetModulateMode(CIwMaterial::MODULATE_NONE); animMatSuccess->SetAlphaMode(CIwMaterial::ALPHA_BLEND); IwGxSetMaterial(animMatSuccess); IwGxSetUVStream(anim_uvs_success); IwGxSetVertStreamScreenSpace(animVertsLeftSuccess, 4); IwGxDrawPrims(IW_GX_QUAD_LIST, NULL, 4); IwGxSetVertStreamScreenSpace(animVertsRightSuccess, 4); IwGxDrawPrims(IW_GX_QUAD_LIST, NULL, 4); if (animMatSuccess->GetAnimCelID() == animMatSuccess->GetAnimCelNum() - 1) { defended = false; } } else { animMatSuccess->SetAnimCelID(0); } if (!isActive()) return; { Ghost* ghost = getGameState()->getGhost(); GhostAttack* attack = (ghost != NULL) ? ghost->getAttack() : NULL; if (attack != NULL && ((attack->getInterval() < 750 && attack->getInterval() > 600) || (attack->getInterval() < 400 && attack->getInterval() > 250))) { dotTexture = dotTextureRed; } else { dotTexture = dotTextureGreen; } } Iw2DSetAlphaMode(IW_2D_ALPHA_NONE); Iw2DSetTransformMatrix(CIwFMat2D::g_Identity); CIwFMat2D rot; rot.SetRot(rad(dotAngle), CIwFVec2( dotVertsTopLeftLeft.x + dotVertsSizeLeft.x/2, dotVertsTopLeftLeft.y + dotVertsSizeLeft.y/2)); Iw2DSetTransformMatrix(rot); Iw2DDrawImage(dotTexture, dotVertsTopLeftLeft, dotVertsSizeLeft); rot.SetRot(rad(dotAngle), CIwFVec2( dotVertsTopLeftRight.x + dotVertsSizeRight.x/2, dotVertsTopLeftRight.y + dotVertsSizeRight.y/2)); Iw2DSetTransformMatrix(rot); Iw2DDrawImage(dotTexture, dotVertsTopLeftRight, dotVertsSizeRight); bool isDrwaing = true; for (int i = 0; i < DEFEND_TOUCHES_MAX; i++) { // Is any touch drawing? if (touch[i]->drawing) break; if (i == DEFEND_TOUCHES_MAX - 1) { isDrwaing = false; animMat->SetAnimCelID(0); } } if (isDrwaing) { IwGxLightingOff(); animMat->SetModulateMode(CIwMaterial::MODULATE_NONE); animMat->SetAlphaMode(CIwMaterial::ALPHA_BLEND); IwGxSetMaterial(animMat); IwGxSetUVStream(anim_uvs); IwGxSetVertStreamScreenSpace(animVertsLeft, 4); IwGxDrawPrims(IW_GX_QUAD_LIST, NULL, 4); IwGxSetVertStreamScreenSpace(animVertsRight, 4); IwGxDrawPrims(IW_GX_QUAD_LIST, NULL, 4); } }
void doMain() { if(s3ePointerGetInt(S3E_POINTER_MULTI_TOUCH_AVAILABLE)){ s3ePointerRegister(S3E_POINTER_TOUCH_EVENT, (s3eCallback)MultiTouchButtonCB, NULL); s3ePointerRegister(S3E_POINTER_TOUCH_MOTION_EVENT, (s3eCallback)MultiTouchMotionCB, NULL); } else { s3ePointerRegister(S3E_POINTER_BUTTON_EVENT, (s3eCallback)SingleTouchButtonCB, NULL); s3ePointerRegister(S3E_POINTER_MOTION_EVENT, (s3eCallback)SingleTouchMotionCB, NULL); } IwGetResManager()->LoadGroup("resource_groups/palate.group"); palateGroup = IwGetResManager()->GetGroupNamed("Palate"); std::vector<int> ui_texture_hashes; uint background_hash = IwHashString("background_clean"); CIwResList* resources = palateGroup->GetListHashed(IwHashString("CIwTexture")); for(CIwManaged** itr = resources->m_Resources.GetBegin(); itr != resources->m_Resources.GetEnd(); ++itr) { if(background_hash != (*itr)->m_Hash) { ui_texture_hashes.push_back((*itr)->m_Hash); } } CIwMaterial* background = new CIwMaterial(); background->SetTexture((CIwTexture*)palateGroup->GetResNamed("background_clean", IW_GX_RESTYPE_TEXTURE)); background->SetModulateMode(CIwMaterial::MODULATE_NONE); background->SetAlphaMode(CIwMaterial::ALPHA_DEFAULT); unit_ui = new CIwMaterial(); unit_ui->SetModulateMode(CIwMaterial::MODULATE_NONE); unit_ui->SetAlphaMode(CIwMaterial::ALPHA_DEFAULT); unit_ui->SetTexture((CIwTexture*)palateGroup->GetResNamed("TAKE2", IW_GX_RESTYPE_TEXTURE)); CIwSVec2 bg_wh(320, 480); CIwSVec2 ui_wh(80, 480); CIwSVec2 ui_offset(240, 0); CIwSVec2 uv(0, 0); CIwSVec2 duv(IW_GEOM_ONE, IW_GEOM_ONE); init(); IwGxLightingOff(); IwGxSetColClear(255, 255, 255, 255); float worldScrollMultiplier = 0.75; if(s3eDeviceGetInt(S3E_DEVICE_OS) == S3E_OS_ID_IPHONE) { worldScrollMultiplier = 0.925; } while (1) { int64 start = s3eTimerGetMs(); s3eDeviceYield(0); s3eKeyboardUpdate(); s3ePointerUpdate(); if ((s3eKeyboardGetState(s3eKeyEsc) & S3E_KEY_STATE_DOWN) || (s3eKeyboardGetState(s3eKeyAbsBSK) & S3E_KEY_STATE_DOWN) || (s3eDeviceCheckQuitRequest())) { break; } switch(currentState) { case MAIN_MENU: if(s3ePointerGetState(S3E_POINTER_BUTTON_SELECT) & S3E_POINTER_STATE_PRESSED) { currentState = IN_GAME; } if(frameCount % FRAMES_PER_UPDATE == 0) { mainMenu->tick(); } mainMenu->render(); break; case IN_GAME: IwGxSetMaterial(background); IwGxSetScreenSpaceSlot(-1); IwGxDrawRectScreenSpace(&CIwSVec2::g_Zero, &bg_wh, &uv, &duv); IwGxSetMaterial(unit_ui); IwGxSetScreenSpaceSlot(1); IwGxDrawRectScreenSpace(&ui_offset, &ui_wh, &uv, &duv); if (worldScrollSpeed > .0005 || worldScrollSpeed < -.0005) { game->rotate(worldScrollSpeed); worldScrollSpeed *= worldScrollMultiplier; } if(frameCount % FRAMES_PER_UPDATE == 0) { game->tick(); } game->render(); if(!renderTouches()) { break; } break; } IwGxFlush(); IwGxSwapBuffers(); // Attempt frame rate while ((s3eTimerGetMs() - start) < MS_PER_FRAME){ int32 yield = (MS_PER_FRAME - (s3eTimerGetMs() - start)); if (yield < 0) { break; } s3eDeviceYield(yield); } frameCount++; IwGxClear(IW_GX_COLOUR_BUFFER_F | IW_GX_DEPTH_BUFFER_F); } delete game; delete mainMenu; delete localPlayer; delete opponentPlayer; delete background; delete unit_ui; palateGroup->Finalise(); for(int i = 0; i < MAX_TOUCHES; ++i) if(touches[i].unit) delete touches[i].unit; }
void renderGhost() { if (!getGameState()->getPlayer()->isReady()) { return; } IwGxLightingOff(); Ghost *ghost = getGameState()->getGhost(); CIwFVec3 ghostPosition(0, 0, ghost->getDistance()); double ghostRotation = rad(ghost->getRotation()); // Place the markers on the edge of the compass radius // rotated to their correct bearing to current location ghostMatrix->SetRotY(rad(ghost->getBearing())); ghostMatrix->SetTrans(ghostMatrix->RotateVec(ghostPosition)); ghostMatrix->PostRotateY(ghostRotation); IwGxSetModelMatrix(ghostMatrix); if (ghost->pollAnimCaptured()) { ghost_Player->PlayAnim(ghost_Anims[GHOST_ANIM_CAPTURED], 1, 0, BLEND_DURATION); } else if (ghost->pollAnimAgro()) { ghost_Player->PlayAnim(ghost_Anims[GHOST_ANIM_AGRO], 1, 0, BLEND_DURATION); } else if (ghost->pollAnimDodge()) { ghost_Player->PlayAnim(ghost_Anims[GHOST_ANIM_DODGE], 1, 0, BLEND_DURATION); } else if (ghost->pollAnimAttack()) { ghost_Player->PlayAnim(ghost_Anims[GHOST_ANIM_ATTACK], 1, 0, BLEND_DURATION); } IwGxLightingAmbient(true); IwGxSetLightType(0, IW_GX_LIGHT_AMBIENT); int sinceHit = clock() - ghost->getHitTime(); CIwColour colAmbient; if (sinceHit < GHOST_HIT_LENGTH) { int halfAnimation = GHOST_HIT_LENGTH/2; float animState = (float) sinceHit / halfAnimation; if (animState > 1) { animState = 2 - animState; } colAmbient.Set(0xff, 0xff*(1-animState), 0xff*(1-animState), 0xff); } else { // The default state that displays the image as it is colAmbient.Set(0xff, 0xff, 0xff, 0xff); } IwGxSetLightCol(0, &colAmbient); IwGxSetScreenSpaceSlot(1); IwAnimSetSkelContext(ghost_Player->GetSkel()); IwAnimSetSkinContext(ghost_Skin); ghost_Model->Render(); //outline the face under the cursor if (clickX > 0 && clickY > 0) { int32 faceID = ghostCollision->GetFaceUnderCursor(clickX, clickY); if (faceID != -1) { getGameState()->getGhost()->tapped(); clickX = clickY = -1; } else { clickX = clickY = -1; } } // Tidier to reset these IwAnimSetSkelContext(NULL); IwAnimSetSkinContext(NULL); if (ghost->isFound() && !ghost->isDead()) { ghostCollision->RenderEctoplasmaBar((float)ghost->getEctoplasm() / GHOST_MAX_ECTOPLASM, ghostRotation); } }
void Graphics::preRender() { IwGxClear(IW_GX_COLOUR_BUFFER_F | IW_GX_COLOUR_BUFFER_F); IwGxLightingOff(); }
void PatteRunGameEngine::RenderPause() { int width = Iw2DGetSurfaceWidth(); int height = Iw2DGetSurfaceHeight(); int iconWidth = 40; int iconHeight = 40; CIwRect bounds(15, height - 170, width - 30, iconHeight); IwGxLightingOn(); IwGxFontSetFont(g_pFont); IwGxFontSetCol(0xffffffff); CIwRect rect(0, 0, width, bounds.y); IwGxFontSetRect(rect); IwGxFontAlignHor alignH = IwGxFontGetAlignmentHor(); IwGxFontAlignVer alignV = IwGxFontGetAlignmentVer(); IwGxFontSetAlignmentVer(IW_GX_FONT_ALIGN_MIDDLE); IwGxFontSetAlignmentHor(IW_GX_FONT_ALIGN_CENTRE); IwGxFontDrawText("Tap the screen to resume..."); /* CIwTexture* pCurrLevel = g_pTextureLevel1; switch (g_iLevel) { case 0 : { pCurrLevel = g_pTextureLevel1; } break; case 1 : { pCurrLevel = g_pTextureLevel2; } break; case 2 : { pCurrLevel = g_pTextureLevel3; } break; case 3 : { pCurrLevel = g_pTextureLevel4; } break; } int totalWidth = g_pTextureLevel->GetWidth() + pCurrLevel->GetWidth() + 10; int totalHeight = g_pTextureLevel->GetHeight(); CIwSVec2 locLevel((width - totalWidth) / 2, rect.h - totalHeight); Utils::AlphaRenderImage(g_pTextureLevel, locLevel, 255); locLevel.x += (int16)(g_pTextureLevel->GetWidth() + 10); Utils::AlphaRenderImage(pCurrLevel, locLevel, 255); Iw2DSetAlphaMode(IW_2D_ALPHA_HALF); Iw2DFillRect(CIwSVec2(10, height - 170), CIwSVec2(width - 20, 160)); Iw2DSetAlphaMode(IW_2D_ALPHA_NONE); IwGxFontSetAlignmentVer(IW_GX_FONT_ALIGN_MIDDLE); IwGxFontSetAlignmentHor(IW_GX_FONT_ALIGN_LEFT); IwGxFontSetFont(g_pFontSmall); CIwRect fontBounds(15 + iconWidth + 10, height - 170, width - 40 - iconWidth, iconHeight); CIwSVec2 loc1(bounds.x + (iconWidth - g_pTextureFirefly->GetWidth()) / 2, bounds.y + (iconHeight - g_pTextureFirefly->GetHeight()) / 2); Utils::AlphaRenderImage(g_pTextureFirefly, loc1, 255); IwGxFontSetRect(fontBounds); IwGxFontDrawText("Capture firelfies to gain points"); bounds.y += 40; fontBounds.y += 40; CIwSVec2 loc2(bounds.x + (iconWidth - g_pTextureDragon->GetWidth()) / 2, bounds.y + (iconHeight - g_pTextureDragon->GetHeight()) / 2); Utils::AlphaRenderImage(g_pTextureDragon, loc2, 255); IwGxFontSetRect(fontBounds); IwGxFontDrawText("Dragonflies capture fireflies"); bounds.y += 40; fontBounds.y += 40; CIwSVec2 loc3(bounds.x + (iconWidth - g_pTextureMine->GetWidth()) / 2, bounds.y + (iconHeight - g_pTextureMine->GetHeight()) / 2); Utils::AlphaRenderImage(g_pTextureMine, loc3, 255); IwGxFontSetRect(fontBounds); IwGxFontDrawText("Mines take away your points"); bounds.y += 40; fontBounds.y += 40; CIwSVec2 loc4(bounds.x + (iconWidth - g_pTextureBolt->GetWidth()) / 2, bounds.y + (iconHeight - g_pTextureBolt->GetHeight()) / 2); Utils::AlphaRenderImage(g_pTextureBolt, loc4, 255); IwGxFontSetRect(fontBounds); IwGxFontDrawText("Shake your phone to stun fireflies"); */ IwGxLightingOff(); }
int main(int argc, char* argv[]) { g_pointerdown = false; FillDefaultLocalScores(); // Initialisation of Airplay Studio modules Iw2DInit(); // Initialise support for rendering with the standard SW renderer IwGxLightingOff(); IwResManagerInit(); Load(); int16 sw = (int16)Iw2DGetSurfaceWidth(); int16 sh = (int16)Iw2DGetSurfaceHeight(); PAL_InitData_t palInitData; SC_Error_t retCode = SC_Client_New(&g_client, &palInitData, SC_TEST_GAME_ID, SC_TEST_GAME_SECRET, "AIW"); if (retCode != SC_OK) s3eDebugAssertShow(S3E_MESSAGE_CONTINUE_STOP, "Failed to create SC_Client"); IwGetResManager()->LoadGroup("fonts.group"); LoadGlobalImages(); LoadMainControls(); game = new CGame(); mainmenu = new CMainMenu(); profile = new CProfile(); scores = new CScores(); mainmenu->Load(); game->Load(); profile->Load(); scores->Load(); CBaseScene *curscene = (CBaseScene *)mainmenu; g_curSceneType = stMainMenu; uint32 timer = (uint32)s3eTimerGetMs(); g_AccelerometerEnabled = (s3eAccelerometerStart() == S3E_RESULT_SUCCESS); while(curscene) { s3eDeviceYield(0); //// Check for user quit if (s3eDeviceCheckQuitRequest()) break; int delta = uint32(s3eTimerGetMs()) - timer; timer += delta; // Make sure the delta-time value is safe if (delta < 0) delta = 0; if (delta > 100) delta = 100; if (g_AccelerometerEnabled) { if (!g_waiting) { if (g_errorDialog->Get_Visible()) { if (UpdatePointer() == petDown) CloseErrorDlg(); else g_errorDialog->Update(delta); } else { switch (UpdatePointer()) { case petNone: break; case petDown: curscene->PointerDown(g_pointerx, g_pointery); break; case petUp: curscene->PointerUp(g_pointerx, g_pointery); break; case petMove: curscene->PointerMove(g_pointerx, g_pointery); break; } curscene->Update(delta); } } curscene->Render(); if (g_waiting) { Iw2DSetColour(0xeeffffff); Iw2DFillRect(CIwSVec2(0, 0), CIwSVec2(sw, sh)); Iw2DSetColour(0xff000000); Iw2DSetFont(g_font); Iw2DDrawString(g_waitcaption, CIwSVec2(0, 0), CIwSVec2(sw, sh), IW_2D_FONT_ALIGN_CENTRE, IW_2D_FONT_ALIGN_CENTRE); } if (g_errorDialog->Get_Visible()) { g_errorDialog->Render(); } } Iw2DSurfaceShow(); switch (g_curSceneType) { case stNone: curscene = 0; break; case stMainMenu: { if (curscene != (CBaseScene *)mainmenu) { curscene = (CBaseScene *)mainmenu; curscene->Show(); } } break; case stGame: { if (curscene != (CBaseScene *)game) { curscene = (CBaseScene *)game; curscene->Show(); } }break; case stProfile: { if (curscene != (CBaseScene *)profile) { curscene = (CBaseScene *)profile; curscene->Show(); } }break; case stScores: { if (curscene != (CBaseScene *)scores) { curscene = (CBaseScene *)scores; curscene->Show(); } }break; } } Save(); delete game; delete mainmenu; delete profile; delete scores; SC_Client_Release(g_client); UnloadGlobalImages(); UnloadMainControls(); if (g_AccelerometerEnabled) s3eAccelerometerStop(); // Terminate system modules IwResManagerTerminate(); Iw2DTerminate(); return 0; }