void MapBackground::RenderElement(CIwUIGraphics& parentGraphics) { // Render tiles for the background std::list<MapTile*>::iterator iter = gVectorImageUrls.begin(); int i = 0; while (iter != gVectorImageUrls.end()) { MapTile* pTile = *iter; if (pTile->pTexture) { //Calculate the top left of the map image CIwSVec2 topLeft, bottomRight; topLeft.x = pTile->location.x; topLeft.y = pTile->location.y; CIwUIRect rect(CIwVec2(topLeft.x, topLeft.y), CIwVec2(pTile->pTexture->GetWidth(), pTile->pTexture->GetHeight())); CIwUIColour c(0xff,0xff,0xff,0xff); CIwColour* wtf = IW_GX_ALLOC(CIwColour, 4); CIwMaterial* pMat = IW_GX_ALLOC_MATERIAL(); pMat->SetModulateMode(CIwMaterial::MODULATE_NONE); pMat->SetTexture(pTile->pTexture); parentGraphics.DrawImage(pTile->pTexture, pMat, rect, CIwSVec2(0,0), CIwSVec2(4096, 4096), c, false); } iter++; } }
TextSprite::TextSprite(GameManager *gameManager, const char *_text) : Sprite(gameManager) { text = _text; textFont = null; horizontalAlignment = IW_2D_FONT_ALIGN_LEFT; textColorSource = null; backgroundColorSource = null; borderColorSource = null; borderXSource = null; borderYSource = null; marginXSource = null; marginYSource = null; paddingXSource = null; paddingYSource = null; margin = CIwVec2(0, 0); padding = CIwVec2(0, 0); borderThickness = CIwVec2(0, 0); textColor.Set(0, 0, 0); borderColor.Set(0, 0, 0, 0); backgroundColor.Set(0, 0, 0, 0); RecalculateTextData(); }
void TextSprite::RenderImage(uint32 gameTime) { if(textColorSource != null) textColor = textColorSource->GetColor(gameTime); if(borderColorSource != null) borderColor = borderColorSource->GetColor(gameTime); if(backgroundColorSource != null) backgroundColor = backgroundColorSource->GetColor(gameTime); if(marginXSource != null) margin = SCREEN_TO_SUBPIXEL(CIwVec2(marginXSource->GetInt(gameTime), marginYSource->GetInt(gameTime))); if(paddingXSource != null) padding = SCREEN_TO_SUBPIXEL(CIwVec2(paddingXSource->GetInt(gameTime), paddingYSource->GetInt(gameTime))); if(borderXSource != null) borderThickness = SCREEN_TO_SUBPIXEL(CIwVec2(borderXSource->GetInt(gameTime), borderYSource->GetInt(gameTime))); if(marginXSource != null || paddingXSource != null || borderXSource != null) { UpdatePositionData(); } CIw2DFont *prevFont = null; CIwColour prevColor = Iw2DGetColour(); if(textFont != null) { prevFont = Iw2DGetFont(); Iw2DSetFont(textFont); } if(backgroundColor.a > 0) { Iw2DSetColour(backgroundColor); Iw2DFillRect(CIwSVec2(backgroundPosition), CIwSVec2(backgroundSize)); } if(borderColor.a > 0) { Iw2DSetColour(borderColor); Iw2DFillRect(CIwSVec2(borderPosition), CIwSVec2(borderSize)); Iw2DSetColour(backgroundColor); Iw2DFillRect(CIwSVec2(innerBorderPosition), CIwSVec2(innerBorderSize)); } Iw2DSetColour(textColor); const char *textPtr = text.c_str(); Iw2DDrawString(textPtr, CIwSVec2(textPosition), CIwSVec2(textSize), horizontalAlignment, IW_2D_FONT_ALIGN_TOP); Iw2DSetColour(prevColor); if(prevFont != null) { Iw2DSetFont(prevFont); } }
void WallLevel::EnterWallLevel(EventCallback *eventData) { mgr->RemoveAllGameObjects(); selectedBrick = null; selectedTarget = null; StateVariable zeroVar; zeroVar.intValue = 0; mgr->GetStateManager()->SetVar(VAR_POINTS, zeroVar); mgr->GetStateManager()->SetVar(VAR_CURRENT_THINGY_COUNT, zeroVar); mgr->GetStateManager()->SetVar(VAR_CURRENT_CORRECT_THINGY_COUNT, zeroVar); Sprite *sprite = new Sprite(mgr); sprite->SetImage(mgr->GetResourceManager()->GetImage(IMAGE_WALL_BACKGROUND)); sprite->SetBaseLocation(CIwVec2(0, 0)); sprite->SetZIndex(-999); mgr->RegisterGameObject(sprite); strcpy(sprite->debugId, "WallLevelBackground"); PointsManager *pointsManager = new PointsManager(mgr, STATE_WALL_SUMMARY); pointsManager->ClearTransformations(); pointsManager->AddTransformation(new AnchorTransformation(AnchorPosTopLeft)); pointsManager->SetBaseLocation(CIwVec2(20, 20)); for(int y = 0; y < NUM_COURSES; y++) { new Brick(mgr, this, -1, y); new Brick(mgr, this, NUM_POSITIONS, y); } // for(int y=0; y < NUM_COURSES; y++) // { // for(int x = 0; x < NUM_POSITIONS; x++) // { // brickTargets[x] = new BrickTarget(mgr, this, x, y); // } // } //return; for(int x = 0; x < NUM_POSITIONS; x++) { brickCourses[x] = -1; brickTargets[x] = new BrickTarget(mgr, this, x, 0); bricks[x] = new Brick(mgr, this, x); } }
void MakeBezierSprite(GameManager *mgr, uint32 marker_handle, int x, int y, int dx, int dy, float scale) { PathFollowingSprite *path = new PathFollowingSprite(mgr); path->SetImage(mgr->GetResourceManager()->GetImage(marker_handle)); path->SetBaseLocation(CIwVec2(x, y)); path->AddTransformation(new AnchorTransformation()); path->AddTransformation(new ScaleTransformation(scale)); mgr->RegisterGameObject(path); path->SetTotalPathTimeMillis(10000); path->AddSegment(new PathSegmentBezier(CIwVec2(x, y), CIwVec2(x, y + dy), CIwVec2(x + dx, y + dy), CIwVec2(x + dx, y))); path->AddSegment(new PathSegmentLine(CIwVec2(x + dx, y), CIwVec2(x + dx, y + dy))); path->AddSegment(new PathSegmentBezier(CIwVec2(x + dx, y + dy), CIwVec2(x - dx, y), CIwVec2(x + dx * 2, y), CIwVec2(x, y + dy))); path->AddSegment(new PathSegmentLine(CIwVec2(x, y + dy), CIwVec2(x, y))); }
void MakeSquareSprite(GameManager *mgr, uint32 marker_handle, int x, int y, int dx, int dy) { PathFollowingSprite *path = new PathFollowingSprite(mgr); path->SetImage(mgr->GetResourceManager()->GetImage(marker_handle)); path->SetBaseLocation(CIwVec2(x, y)); path->AddTransformation(new AnchorTransformation()); path->AddTransformation(new ScaleTransformation(0.25)); mgr->RegisterGameObject(path); path->SetPathSpeedPixelsPerSecond(500); path->AddSegment(new PathSegmentLine(CIwVec2(dx, 0))); path->AddSegment(new PathSegmentLine(CIwVec2(0, dy))); path->AddSegment(new PathSegmentLine(CIwVec2(-dx, 0))); path->AddSegment(new PathSegmentLine(CIwVec2(0, -dy))); }
int32 ResetSprite(void *systemData, void *userData) { GameManager *mgr; if(systemData != NULL) { Sprite *spritePtr = (Sprite *)systemData; mgr = spritePtr->GetManager(); mgr->RemoveGameObject(spritePtr); delete spritePtr; } else { mgr = (GameManager*)userData; } Sprite *tmp = new Sprite(mgr); tmp->SetImage(mgr->GetResourceManager()->GetImage(ARROW_HANDLE)); tmp->SetBaseLocation(CIwVec2(mgr->GetSurfaceWidth() / 2, mgr->GetSurfaceHeight() / 2)); tmp->AddTransformation(new AnchorTransformation()); OrbitTransformation *orbiter = new OrbitTransformation(150, 5000, 0, Clockwise); tmp->AddTransformation(orbiter); mgr->RegisterGameObject(tmp); tmp->SetLifespan(++resetCount * 500); tmp->SetCompletionCallback(ResetSprite, NULL); return 0; }
void Iw2DSprite::Render(CIwSVec2 pPosition) { if(m_Angle > 0 || m_Angle < 0) { CIwMat2D RotationMatrix; RotationMatrix.SetRot(m_Angle, CIwVec2(pPosition.x + m_Center.x , pPosition.y + m_Center.y) ); Iw2DSetTransformMatrix(RotationMatrix); } if( m_Flip.x > 0 && m_Flip.y > 0) Iw2DSetImageTransform(IW_2D_IMAGE_TRANSFORM_ROT180); else if( m_Flip.x > 0 && m_Flip.y <= 0) Iw2DSetImageTransform(IW_2D_IMAGE_TRANSFORM_FLIP_X); else if( m_Flip.y > 0 && m_Flip.x <= 0) Iw2DSetImageTransform(IW_2D_IMAGE_TRANSFORM_FLIP_Y); Iw2DDrawImageRegion(m_SpriteSheet, pPosition, m_FrameSize, m_DrawRect, m_FrameSize); if(m_Angle > 0 || m_Angle < 0) Iw2DSetTransformMatrix(CIwMat2D::g_Identity); if( m_Flip.x > 0 || m_Flip.y > 0) Iw2DSetImageTransform(IW_2D_IMAGE_TRANSFORM_NONE); }
BrickTarget::BrickTarget(GameManager *mgr, WallLevel *_parent, int _xPos, int _yPos) : Sprite(mgr) { DEBUG_TRACER(BrickTarget::BrickTarget); prefix = wordBuilder->GetNextPrefix(); isSelected = false; parent = _parent; staticTarget = false; sprintf(debugId, "BrTg - %d(%s) [%d, %d]", brickTargetCount, prefix.c_str(), _xPos, _yPos); SetImage(mgr->GetResourceManager()->GetImage(IMAGE_BRICK_TARGET)); xPos = _xPos; yPos = _yPos; int brickLocX = 85 + (yPos % 2) * 70 + xPos * 140; int brickLocY = 330 - 73 * yPos; SetBaseLocation(CIwVec2(brickLocX, brickLocY)); AddTransformation(new AnchorTransformation()); mgr->RegisterGameObject(this); //char buffer[50]; //sprintf(buffer, "%d, %d", xPos, yPos); //prefixSprite = new TextSprite(mgr, buffer); prefixSprite = new TextSprite(mgr, prefix.c_str()); prefixSprite->SetParent(this); prefixSprite->AddTransformation(new AnchorTransformation()); prefixSprite->AddTransformation(new RotationTransformation(0, Clockwise)); prefixSprite->SetFont(mgr->GetResourceManager()->GetFont(FONT_COOPER_18)); prefixSprite->SetBackgroundColor(g_IwGxColours[IW_GX_COLOUR_WHITE]); prefixSprite->SetBorderColor(g_IwGxColours[IW_GX_COLOUR_BLACK]); prefixSprite->SetBorderThickness(CIwVec2(2, 2)); prefixSprite->SetPadding(CIwVec2(3, 3)); prefixSprite->SetZIndex(10); mgr->RegisterGameObject(prefixSprite); sprintf(prefixSprite->debugId, "Brick Target Prefix - %d(%s)", brickTargetCount, prefix.c_str()); brickTargetCount++; }
void AnimationTest(GameManager *mgr, uint32 marker_handle, uint32 width, uint32 height) { FlipbookSprite *tmp = new FlipbookSprite(mgr); tmp->SetAnimationParams(mgr->GetResourceManager()->GetImage(FIRE_HANDLE), 64, 48, 20, 20); tmp->SetBaseLocation(CIwVec2(mgr->GetSurfaceWidth() / 2, mgr->GetSurfaceHeight() / 2)); tmp->AddTransformation(new AnchorTransformation()); OrbitTransformation *orbiter = new OrbitTransformation(150, 5000, 0, Clockwise); tmp->AddTransformation(orbiter); mgr->RegisterGameObject(tmp); }
CIwVec2 GetLocation(uint32 gameTime) { if(gameTime > nextChangeTime) { nextChangeTime = gameTime + SHAKER_FRAME_TIME_MILLIS; deltaX = rand() % 11 - 5; deltaY = rand() % 11 - 5; } return CIwVec2(deltaX, deltaY); }
void TextSprite::UpdatePositionData() { textPosition = margin + borderThickness + padding; innerBorderPosition = margin + borderThickness; innerBorderSize = textSize + padding + padding; borderPosition = margin; borderSize = textSize + padding + padding + borderThickness + borderThickness; backgroundPosition = CIwVec2(0, 0); backgroundSize = textSize + padding + padding + margin + margin + borderThickness + borderThickness; }
void WallLevel::SummarizeWallLevel(EventCallback *eventData) { StateVariable finalPoints = mgr->GetStateManager()->GetVar(VAR_POINTS); char stateSummary[1024]; sprintf(stateSummary, "You got %d points.\nHave some stars!\nTouch to continue.", finalPoints.intValue); mgr->RemoveAllGameObjects(); Sprite *sprite = new Sprite(mgr); sprite->SetImage(mgr->GetResourceManager()->GetImage(IMAGE_WALL_BACKGROUND)); sprite->SetBaseLocation(CIwVec2(0, 0)); sprite->SetZIndex(-999); mgr->RegisterGameObject(sprite); strcpy(sprite->debugId, "WallLevelBackground"); sprite->SetTouchEndCallback(this, (EventCallbackPtr)&WallLevel::GoToLevelSelect, (void*)(mgr->GetCurrentClockTime() + 2000)); for(int y = 0; y < NUM_COURSES; y++) { for(int x = -1; x<= NUM_POSITIONS; x++) { new Brick(mgr, this, x, y); } } TextSprite *summary = new TextSprite(mgr, stateSummary); summary->SetAlign(IW_2D_FONT_ALIGN_CENTRE); summary->SetBackgroundColor(g_IwGxColours[IW_GX_COLOUR_WHITE]); summary->SetFont(mgr->GetResourceManager()->GetFont(FONT_COOPER_24)); summary->SetBorderColor(g_IwGxColours[IW_GX_COLOUR_BLACK]); summary->SetBorderThickness(CIwVec2(4, 4)); summary->SetPadding(CIwVec2(7, 7)); summary->AddTransformation(new AnchorTransformation()); summary->SetBaseLocation(CIwVec2(mgr->GetSurfaceWidth() / 2, mgr->GetSurfaceHeight() / 2)); summary->SetZIndex(999); mgr->RegisterGameObject(summary); }
void LabeledSprite(GameManager *mgr, uint32 marker_handle, uint32 width, uint32 height) { Sprite *image = new Sprite(mgr); image->SetImage(mgr->GetResourceManager()->GetImage(ARROW_HANDLE)); image->AddTransformation(new AnchorTransformation()); image->SetBaseLocation(CIwVec2(mgr->GetSurfaceWidth() / 2, mgr->GetSurfaceHeight() / 2)); OrbitTransformation *orbiter = new OrbitTransformation(150, 5000, 0, CounterClockwise); image->AddTransformation(orbiter); mgr->RegisterGameObject(image); TextSprite *text = new TextSprite(mgr, (char *)"Normal"); text->AddTransformation(new AnchorTransformation()); text->AddTransformation(new AnchorToTransformation(image, image, (float)(text->GetHeight() / 2 + image->GetHeight() / 2 + 10), 0, RelativeToNormal)); text->AddTransformation(new OrientToTransformation((IDirectional*)image, OrientAlongOrientation)); mgr->RegisterGameObject(text); }
void myIwGxDrawStar(int x, int y, CIwSVec2 texpos, int iscale, iwangle rotval, int alphaf) { CIwMat2D transformMatrix; int i; // if (ssend_vertices + 4 > (MX_VERTICES)) { myIwGxDoneBonus(); ssend_vertices = 0; } transformMatrix = CIwMat2D::g_Identity; transformMatrix.SetRot(rotval, CIwVec2(x, y)); // // 0 = top-left // 1 = bottom-left // 2 = bottom-right // 3 = top-right // svertices[ssend_vertices + 0].x = x - iscale; svertices[ssend_vertices + 0].y = y - iscale; svertices[ssend_vertices + 1].x = x - iscale; svertices[ssend_vertices + 1].y = y + iscale; svertices[ssend_vertices + 2].x = x + iscale; svertices[ssend_vertices + 2].y = y + iscale; svertices[ssend_vertices + 3].x = x + iscale; svertices[ssend_vertices + 3].y = y - iscale; // suvdata[ssend_vertices + 0].x = (texpos.x) << 3; suvdata[ssend_vertices + 0].y = (texpos.y) << 3; suvdata[ssend_vertices + 1].x = (texpos.x) << 3; suvdata[ssend_vertices + 1].y = (texpos.y + 32) << 3; suvdata[ssend_vertices + 2].x = (texpos.x + 32) << 3; suvdata[ssend_vertices + 2].y = (texpos.y + 32) << 3; suvdata[ssend_vertices + 3].x = (texpos.x + 32) << 3; suvdata[ssend_vertices + 3].y = (texpos.y) << 3; // scolors[ssend_vertices + 0].Set(0xFF, 0xFF, 0xFF, (uint8)(alphaf)); scolors[ssend_vertices + 1].Set(0xFF, 0xFF, 0xFF, (uint8)(alphaf)); scolors[ssend_vertices + 2].Set(0xFF, 0xFF, 0xFF, (uint8)(alphaf)); scolors[ssend_vertices + 3].Set(0xFF, 0xFF, 0xFF, (uint8)(alphaf)); // for (i = 0; i < 4; i++) svertices[ssend_vertices + i] = transformMatrix.TransformVec(svertices[ssend_vertices + i]); ssend_vertices += 4; // }
//----------------------------------------------------------------------------- void ExampleRender() { static const CIwSVec2 imageSize(g_Image->GetWidth() >> 3, g_Image->GetHeight() >> 3); static const CIwSVec2 halfImageSize = imageSize >> 1; const CIwSVec2 screenCentre = CIwSVec2((int16)Iw2DGetSurfaceWidth() >> 1, (int16)Iw2DGetSurfaceHeight() >> 1); const b2Transform t = g_body->GetTransform(); const CIwSVec2 pos = screenCentre + (CIwSVec2(int16(t.p.x*8), -int16(t.p.y*8))); const float angle = -t.q.GetAngle() * (180.0f/3.14159f); // reverse angle as our screen-Y coord is reversed CIwMat2D rot; rot.SetRot(iwangle(angle * 1024 / 90), CIwVec2(pos) << 3); Iw2DSetTransformMatrixSubPixel(rot); Iw2DDrawImage(g_Image, pos - halfImageSize, imageSize); // Iw2DSetTransformMatrix(CIwMat2D::g_Identity); Iw2DSurfaceShow(); }
void TileSet::Render(int index,CIwSVec2 topLeft,int rotation) { int ind=index-m_firstGid; if(ind<0) return; int index_X=ind%_tilesPerRow; int index_Y=ind/_tilesPerRow; CIwSVec2 pos = CIwSVec2(index_X * _tilewidth,index_Y * _tileheight); if(rotation!=0) { iwangle angle =90*rotation;//90 degrees CIwSVec2 centre=CIwSVec2(iwsfixed(topLeft.x+(float)_tilewidth/2.0f),iwsfixed(topLeft.y+(float)_tileheight/2.0f)); CIwMat2D rot; rot.SetRot(IW_ANGLE_FROM_DEGREES(angle), CIwVec2(centre)); Iw2DSetTransformMatrix(rot); } Iw2DDrawImageRegion(_image, topLeft, pos, _tileSize); Iw2DSetTransformMatrix(CIwMat2D::g_Identity); }
void MakeOrbiters(GameManager *mgr, int x, int y, uint32 marker_handle) { Sprite *bug1 = new Sprite(mgr); bug1->SetImage(mgr->GetResourceManager()->GetImage(marker_handle)); bug1->SetBaseLocation(CIwVec2(x, y)); bug1->AddTransformation(new AnchorTransformation()); OrbitTransformation *orbiter = new OrbitTransformation(200, 15000); bug1->AddTransformation(orbiter); orbiter = new OrbitTransformation(70, 7000); bug1->AddTransformation(orbiter); mgr->RegisterGameObject(bug1); Sprite *anchorBug = bug1; ILocationSource *locBug = bug1; bug1 = new Sprite(mgr); bug1->SetImage(mgr->GetResourceManager()->GetImage(marker_handle)); bug1->AddTransformation(new AnchorTransformation()); bug1->AddTransformation(new AnchorToTransformation(anchorBug, CIwVec2(-56, 56))); bug1->AddTransformation(new ScaleTransformation(0.3f)); orbiter = new OrbitTransformation(40, 2000); bug1->AddTransformation(orbiter); mgr->RegisterGameObject(bug1); bug1 = new Sprite(mgr); bug1->SetImage(mgr->GetResourceManager()->GetImage(marker_handle)); bug1->AddTransformation(new AnchorTransformation()); bug1->AddTransformation(new AnchorToTransformation(anchorBug, CIwVec2(-56, -56))); bug1->AddTransformation(new ScaleTransformation(0.3f)); orbiter = new OrbitTransformation(40, 2000); bug1->AddTransformation(orbiter); mgr->RegisterGameObject(bug1); bug1 = new Sprite(mgr); bug1->SetImage(mgr->GetResourceManager()->GetImage(marker_handle)); bug1->AddTransformation(new AnchorTransformation()); bug1->AddTransformation(new AnchorToTransformation(anchorBug, CIwVec2(80, 0))); bug1->AddTransformation(new ScaleTransformation(0.3f)); orbiter = new OrbitTransformation(40, 2000, 180); bug1->AddTransformation(orbiter); mgr->RegisterGameObject(bug1); bug1 = new Sprite(mgr); bug1->SetImage(mgr->GetResourceManager()->GetImage(marker_handle)); bug1->SetBaseLocation(CIwVec2(x, y)); bug1->AddTransformation(new AnchorTransformation()); bug1->AddTransformation(new OrientToTransformation(locBug, OrientToward)); mgr->RegisterGameObject(bug1); bug1 = new Sprite(mgr); bug1->SetImage(mgr->GetResourceManager()->GetImage(marker_handle)); bug1->SetBaseLocation(CIwVec2(x / 2, y)); bug1->AddTransformation(new AnchorTransformation()); bug1->AddTransformation(new OrientToTransformation(locBug, OrientToward)); mgr->RegisterGameObject(bug1); bug1 = new Sprite(mgr); bug1->SetImage(mgr->GetResourceManager()->GetImage(marker_handle)); bug1->SetBaseLocation(CIwVec2(x, y/2)); bug1->AddTransformation(new AnchorTransformation()); bug1->AddTransformation(new OrientToTransformation(locBug, OrientToward)); mgr->RegisterGameObject(bug1); bug1 = new Sprite(mgr); bug1->SetImage(mgr->GetResourceManager()->GetImage(marker_handle)); bug1->SetBaseLocation(CIwVec2(x, y * 3 / 2)); bug1->AddTransformation(new AnchorTransformation()); bug1->AddTransformation(new OrientToTransformation(locBug, OrientToward)); mgr->RegisterGameObject(bug1); bug1 = new Sprite(mgr); bug1->SetImage(mgr->GetResourceManager()->GetImage(marker_handle)); bug1->SetBaseLocation(CIwVec2(x * 3 / 2, y)); bug1->AddTransformation(new AnchorTransformation()); bug1->AddTransformation(new OrientToTransformation(locBug, OrientToward)); mgr->RegisterGameObject(bug1); }
void MakeNormalShip(GameManager *mgr, int marker_handle, int x, int y) { Sprite *bug1 = new Sprite(mgr); bug1->SetImage(mgr->GetResourceManager()->GetImage(marker_handle)); bug1->SetBaseLocation(CIwVec2(x, y)); bug1->AddTransformation(new AnchorTransformation()); OrbitTransformation *orbiter = new OrbitTransformation(0, 5000, 0, Clockwise); bug1->AddTransformation(orbiter); mgr->RegisterGameObject(bug1); Sprite *anchorBug = bug1; bug1 = new Sprite(mgr); bug1->SetImage(mgr->GetResourceManager()->GetImage(marker_handle)); bug1->AddTransformation(new AnchorTransformation()); bug1->AddTransformation(new AnchorToTransformation(anchorBug, anchorBug, 70, 60)); bug1->AddTransformation(new ScaleTransformation(0.3f)); orbiter = new OrbitTransformation(20, 2000, 0); bug1->AddTransformation(orbiter); bug1->AddTransformation(new OrientToTransformation(orbiter, OrientAlongNormal)); mgr->RegisterGameObject(bug1); bug1 = new Sprite(mgr); bug1->SetImage(mgr->GetResourceManager()->GetImage(marker_handle)); bug1->AddTransformation(new AnchorTransformation()); bug1->AddTransformation(new AnchorToTransformation(anchorBug, anchorBug, 70, 60)); bug1->AddTransformation(new ScaleTransformation(0.3f)); orbiter = new OrbitTransformation(20, 2000, 120); bug1->AddTransformation(orbiter); bug1->AddTransformation(new OrientToTransformation(orbiter, OrientAlongNormal)); mgr->RegisterGameObject(bug1); bug1 = new Sprite(mgr); bug1->SetImage(mgr->GetResourceManager()->GetImage(marker_handle)); bug1->AddTransformation(new AnchorTransformation()); bug1->AddTransformation(new AnchorToTransformation(anchorBug, anchorBug, 70, 60)); bug1->AddTransformation(new ScaleTransformation(0.3f)); orbiter = new OrbitTransformation(20, 2000, -120); bug1->AddTransformation(orbiter); bug1->AddTransformation(new OrientToTransformation(orbiter, OrientAlongNormal)); mgr->RegisterGameObject(bug1); bug1 = new Sprite(mgr); bug1->SetImage(mgr->GetResourceManager()->GetImage(marker_handle)); bug1->AddTransformation(new AnchorTransformation()); bug1->AddTransformation(new AnchorToTransformation(anchorBug, anchorBug, 70, -60)); bug1->AddTransformation(new ScaleTransformation(0.3f)); orbiter = new OrbitTransformation(20, 2000, 0); bug1->AddTransformation(orbiter); bug1->AddTransformation(new OrientToTransformation(orbiter, OrientAlongNormal)); mgr->RegisterGameObject(bug1); bug1 = new Sprite(mgr); bug1->SetImage(mgr->GetResourceManager()->GetImage(marker_handle)); bug1->AddTransformation(new AnchorTransformation()); bug1->AddTransformation(new AnchorToTransformation(anchorBug, anchorBug, 70, -60)); bug1->AddTransformation(new ScaleTransformation(0.3f)); orbiter = new OrbitTransformation(20, 2000, 120); bug1->AddTransformation(orbiter); bug1->AddTransformation(new OrientToTransformation(orbiter, OrientAlongNormal)); mgr->RegisterGameObject(bug1); bug1 = new Sprite(mgr); bug1->SetImage(mgr->GetResourceManager()->GetImage(marker_handle)); bug1->AddTransformation(new AnchorTransformation()); bug1->AddTransformation(new AnchorToTransformation(anchorBug, anchorBug, 70, -60)); bug1->AddTransformation(new ScaleTransformation(0.3f)); orbiter = new OrbitTransformation(20, 2000, -120); bug1->AddTransformation(orbiter); bug1->AddTransformation(new OrientToTransformation(orbiter, OrientAlongNormal)); mgr->RegisterGameObject(bug1); }
S3E_MAIN_DECL void IwMain() { srand(time(NULL)); GameManager *mgr; mgr = new GameManager(); mgr->SetRequestedFPS(100); mgr->GetResourceManager()->RegisterResourceGroup("images.group"); BUG_HANDLE = mgr->GetResourceManager()->RegisterImage("bug"); SPLAT_HANDLE = mgr->GetResourceManager()->RegisterImage("splat"); LEAVES_HANDLE = mgr->GetResourceManager()->RegisterImage("leaves"); ARROW_HANDLE = mgr->GetResourceManager()->RegisterImage("right_arrow"); FIRE_HANDLE = mgr->GetResourceManager()->RegisterImage("FireBlast"); TREB_FONT_HANDLE = mgr->GetResourceManager()->RegisterFont("trebuchet16pt"); COOPER_FONT_HANDLE = mgr->GetResourceManager()->RegisterFont("cooper_24pt"); GameManager::SetDebugFont(mgr->GetResourceManager()->GetFont(TREB_FONT_HANDLE)); Iw2DSetFont(mgr->GetResourceManager()->GetFont(TREB_FONT_HANDLE)); Sprite *background = new Sprite(mgr); background->SetImage(mgr->GetResourceManager()->GetImage(LEAVES_HANDLE)); background->SetBaseLocation(CIwVec2(0, 0)); background->SetZIndex(-999); mgr->RegisterGameObject(background); int width = mgr->GetSurfaceWidth(); int height = mgr->GetSurfaceHeight(); #define SIMPLE_TEST 0 #define MANY_SHIP_TEST 1 #define ORBITER_TEST 2 #define ANIMATION_TEST 3 #define LABELED_SPRITE 4 #define PATH_TEST 5 int test_selection = SIMPLE_TEST; switch(test_selection) { case SIMPLE_TEST: DoSimpleTest(mgr, ARROW_HANDLE, width, height); break; case MANY_SHIP_TEST: DoManyShipTest(mgr, 10, 10, width, height, ARROW_HANDLE); break; case ORBITER_TEST: MakeOrbiters(mgr, width / 2, height / 2, ARROW_HANDLE); break; case ANIMATION_TEST: AnimationTest(mgr, 0, width, height); break; case LABELED_SPRITE: LabeledSprite(mgr, 0, width, height); break; case PATH_TEST: PathTest(mgr, ARROW_HANDLE, width, height); break; } mgr->MainLoop(); delete mgr; }
CIwVec2 MapBackground::MeasureElement(const CIwVec2& availableSize) const { return CIwVec2(availableSize.x, availableSize.y); }
void DoSimpleTest(GameManager *mgr, uint32 marker_handle, uint32 width, uint32 height) { StateManager *state = mgr->GetStateManager(); StateVariable tmpVar; tmpVar.intValue = 21; INT_VAR_HANDLE = state->RegisterStateVariable("IntVar", tmpVar); tmpVar.floatValue = 3.1415f; FLOAT_VAR_HANDLE = state->RegisterStateVariable("FloatVar", tmpVar); tmpVar.stringValue = "Hello World!"; STRING_VAR_HANDLE = state->RegisterStateVariable("StringVar", tmpVar); PathFollowingSprite *intPath = new PathFollowingSprite(mgr); intPath->AddSegment(new PathSegmentBezier(CIwVec2(100,100), CIwVec2(200, 900), CIwVec2(700, -50), CIwVec2(800,600))); intPath->SetTotalPathTimeMillis(5000); mgr->RegisterGameObject(intPath); CIwColour transparent; transparent.Set(0, 0, 0, 0); char buffer[1024]; sprintf(buffer, "Int: %d", state->GetStateVar(INT_VAR_HANDLE).intValue); intSprite = new TextSprite(mgr, buffer); intSprite->SetBackgroundColor(g_IwGxColours[IW_GX_COLOUR_WHITE]); intSprite->SetBorderColor(g_IwGxColours[IW_GX_COLOUR_BLUE]); intSprite->SetBorderThickness(CIwVec2(3, 3)); intSprite->SetPadding(CIwVec2(3, 3)); intSprite->SetBaseLocation(CIwVec2(300, 100)); //intSprite->AddTransformation(new AnchorToTransformation(intPath, CIwVec2(0,0))); //intSprite->AddTransformation(new OrbitTransformation(0, 5000)); mgr->RegisterGameObject(intSprite); sprintf(buffer, "Float: %f", state->GetStateVar(FLOAT_VAR_HANDLE).floatValue); floatSprite = new TextSprite(mgr, buffer); floatSprite->SetBackgroundColor(g_IwGxColours[IW_GX_COLOUR_WHITE]); floatSprite->SetBorderColor(g_IwGxColours[IW_GX_COLOUR_GREEN]); floatSprite->SetBorderThickness(CIwVec2(3, 3)); floatSprite->SetPadding(CIwVec2(3, 3)); floatSprite->SetBaseLocation(CIwVec2(300, 200)); mgr->RegisterGameObject(floatSprite); sprintf(buffer, "String: %s", state->GetStateVar(STRING_VAR_HANDLE).stringValue); stringSprite = new TextSprite(mgr, buffer); stringSprite->SetBackgroundColor(g_IwGxColours[IW_GX_COLOUR_WHITE]); stringSprite->SetBorderColor(g_IwGxColours[IW_GX_COLOUR_CYAN]); stringSprite->SetBorderThickness(CIwVec2(5, 5)); stringSprite->SetPadding(CIwVec2(2, 2)); stringSprite->SetBaseLocation(CIwVec2(300, 300)); mgr->RegisterGameObject(stringSprite); sprintf(buffer, "Next string"); stringSprite = new TextSprite(mgr, buffer); stringSprite->SetBackgroundColor(g_IwGxColours[IW_GX_COLOUR_WHITE]); stringSprite->SetBorderColor(g_IwGxColours[IW_GX_COLOUR_BLACK]); stringSprite->SetMargin(CIwVec2(4, 4)); stringSprite->SetBorderThickness(CIwVec2(4, 4)); stringSprite->SetPadding(CIwVec2(4, 4)); stringSprite->SetBaseLocation(CIwVec2(400, 400)); mgr->RegisterGameObject(stringSprite); state->SubscribeStateVarChange(INT_VAR_HANDLE, stateVarChanged, intSprite); state->SubscribeStateVarChange(FLOAT_VAR_HANDLE, stateVarChanged, floatSprite); state->SubscribeEvent("FloatChange", changeVarValue, NULL); state->PostFutureEvent("FloatChange", NULL, mgr->GetCurrentClockTime() + 3000); }