void SecretBoxArea::Init(GameCondition gameCondition) { secretboxes.clear(); boxSize = getBoxSize(gameCondition.resolution, 8, 12); bool xy[8][16]; for(int i = 0; i < 8; i++) for(int j = 0; j < 12; j++) xy[i][j] = false; while(secretboxes.size() < 8 * 12) { BoxType randomBoxType = (BoxType)IwRandMinMax(1, 4); for(int i = 0; i < 2; i++) { int32 x, y; do { x = IwRandMinMax(0, 8); y = IwRandMinMax(0, 12); } while (xy[x][y]); xy[x][y] = true; SecretBox *s = new SecretBox(randomBoxType); s->position = new CIwSVec2(y * boxSize->x + PADDING * (y + 1), x * boxSize->y + PADDING * (x + 1)); s->size = boxSize; secretboxes.push_back(s); } } }
void FindTheSpotGameEngine::Prepare() { if (g_pTile) { delete g_pTile; g_pTile = NULL; } g_distance = 0; Utils::GetLocation(&g_startLocation); IwRandSeed(s3eTimerGetMs()); IGameHandler* pHandler = (IGameHandler*)g_pGameHandler; Region* pRegion = pHandler->GetBoundingRegion(); // Calculate a random location within a given radius int tryCount = 20; do { double angle = PI / 180.0 * IwRandMinMax(-180, 180); // 360 degree range int32 radius = IwRandMinMax(25, 50); // 50 meters LiveMaps::CalculateLatLongInDirection(&g_startLocation, radius, angle, &g_randLocation); if (pRegion->Contains(g_randLocation)) { break; } } while (tryCount-- > 0); int acx = LiveMaps::LongitudeToXAtZoom(g_randLocation.m_Longitude, LiveMaps::MaxZoom); int acy = LiveMaps::LatitudeToYAtZoom(g_randLocation.m_Latitude, LiveMaps::MaxZoom); int tx = acx / 256; int ty = acy / 256; int x = tx * 256; int y = ty * 256; g_tileLoc.x = (acx - x); g_tileLoc.y = (acy - y); char szQuad[20]; int server = 0; LiveMaps::TileToQuadKey(szQuad, tx, ty, LiveMaps::MaxZoom); char szImageUrl[256]; sprintf(szImageUrl, "http://r%i.ortho.tiles.virtualearth.net/tiles/%s%s.%s?g=22", server, "h", szQuad, "jpg"); g_topLeft.m_Longitude = LiveMaps::XToLongitudeAtZoom(x, LiveMaps::MaxZoom); g_topLeft.m_Latitude = LiveMaps::YToLatitudeAtZoom(y, LiveMaps::MaxZoom); g_botRight.m_Longitude = LiveMaps::XToLongitudeAtZoom(x+256, LiveMaps::MaxZoom); g_botRight.m_Latitude = LiveMaps::YToLatitudeAtZoom(y+256, LiveMaps::MaxZoom); Utils::DownloadMapTile(&g_pTile, szImageUrl); }
Scythe::Scythe(CIwSVec2 i2Position): LethalUnit() { IW_CALLSTACK("Scythe::Scythe"); this->tTextureList.push_back(ImageManager::getImage("scythe")); this->tTextureList.push_back(ImageManager::getImage("bloodyscythe")); this->sSoundList.push_back(SoundManager::getSound("scythe_kill")); this->sSoundList.push_back(SoundManager::getSound("swoosh3")); this->iSoundIndex = 5; this->i2Position = i2Position; this->sName="scythe"; this->brBoundingBox = BoundingRectangle(this->i2Position, this->i2Size, CIwSVec2((int)(this->i2Size.x * 0.7f), (int)(this->i2Size.y * 0.7f))); this->bUpdate = false; this->bIsMoving = true; this->bDrawn = false; this->mRot = CIwMat2D(); this->iLength = 0; this->fAngularAcceleration = 0; this->fAngularVel = 0; this->fAngle = 0; this->iCapDeathCount = 1000; this->DarkGreen.Set(46, 139, 87, 255); this->LightGreen.Set(0, 255, 127, 255); this->green = IwRandMinMax(0 , 255); this->up = true; ClassTracker::addUnit(this); }
void Mouse::update(uint64 time) { IW_CALLSTACK("Mouse::update"); if(GameState::getState() != GameState::PLAY) { return; } this->iTime = time; this->iTimePassed += time; this->brBoundingBox.setPosition(this->getPosition(), true); if(this->bDead == false) { if(this->bUpdate == true) { this->iSoundIndex = IwRandMinMax(0, 4); this->bDead = true; this->bDrawn = true; this->bUpdate = false; this->setNotShiny(); for(int i = 0; i < (int)uAffectList.size(); ++i) { dynamic_cast<ShinyUnit*>(this->uAffectList[i])->setNotShiny(); dynamic_cast<Food*>(this->uAffectList[i])->bEmpty = true; } } } ShinyUnit::update(); }
void Leader::update() { if (framesUntilUpdate == 0) { curFrame = IwRandMinMax(0, numFrames-1); framesUntilUpdate = 24; } else { --framesUntilUpdate; } }
// Purchase fluidtest.100coins bool OnButton3Click(void* data, CButton* button) { ExampleUI *ui = (ExampleUI*)data; ui->Log("Attempting to purchase fluidtest.100coins"); string randomPayload = string_format("TestPayload%d",IwRandMinMax(1,10000)); // let's be clear this is a test - in your code either don't set it or use something sensible you can check later on a different device s3eAndroidGooglePlayBillingRequestPurchase(inAppSkus[0],true,randomPayload.c_str()); //s3eAndroidGooglePlayBillingRequestPurchase(subSkus[1],false,randomPayload.c_str()); return true; }
void LethalUnit::deathSound() { IW_CALLSTACK("LethalUnit::deathSound"); if(this->iSoundIndex >= 0) { SoundManager::playSound(this->sSoundList[this->iSoundIndex]); } SoundManager::playSound(this->sSoundList[IwRandMinMax(0, 4)]); }
bool Mouse::scaredMove(Box* bCurr, Box* bNext) { IW_CALLSTACK("Mouse::scaredMove"); CIwFVec2 ftemp = this->f2AbsPosition; if(bCurr->i2Position == uTarget->i2Position) { this->bDead = true; this->bUpdate = false; this->bDrawn = true; this->fShininess = -1; return true; } else if(bCurr->getUnit("bucket") != NULL) { bCurr->getUnit("bucket")->bUpdate = true; bCurr->getUnit("bucket")->bAffectUpdate = true; this->bDead = true; this->bUpdate = false; this->bDrawn = true; this->fShininess = -1; return true; } else { this->iSoundIndex = IwRandMinMax(0, 4); SoundManager::playSound(this->sSoundList[this->iSoundIndex]); if(this->bMoveLeft == true) { this->f2AbsPosition.x -= this->f2Velocity.x * this->iTime * Screen::getMOVEMULTIPLIER().x; this->i2Position.x = (int)this->f2AbsPosition.x; } else { this->f2AbsPosition.x += this->f2Velocity.x * this->iTime * Screen::getMOVEMULTIPLIER().x; this->i2Position.x = (int)this->f2AbsPosition.x; } } if((bNext == NULL || bCurr->bIsFilled == true || bNext->bIsFilled == true || bCurr->bIsWalkable == false || bNext->bIsWalkable == false)) { if(this->bMoveLeft == true) { this->f2AbsPosition = ftemp; //this->f2AbsPosition.x -= this->f2Velocity.x * this->iTime * Screen::getMOVEMULTIPLIER().x; this->i2Position.x = (int)this->f2AbsPosition.x; } else { this->f2AbsPosition = ftemp; //this->f2AbsPosition.x += this->f2Velocity.x * this->iTime * Screen::getMOVEMULTIPLIER().x; this->i2Position.x = (int)this->f2AbsPosition.x; } } return false; }
void CatEvent::update(uint64 time) { IW_CALLSTACK("CatEventt::update"); this->iTime = time; this->iTimePassed += time; ShinyUnit::update(); this->brBoundingBox.setPosition(this->i2Position, true); if(CatState::getState() == CatState::TRANSITIONING) { //cout << "cat event: TRANNY " << endl; this->fShininess = (float)IwRandMinMax(0, 1000); if(this->fShininess != 999) { this->fShininess = (float)IwRandMinMax(-4, 4); } this->setEvent(); //cout << "Cat event base shininess " << this->fShininess << endl; } }
GhostAttack::GhostAttack(Player* player, GhostType ghostType) { if (IwRandMinMax(0, 11) == 11) { // Critical hit hit = 50; } else { hit = ((double)IwRandMinMax(PLAYER_MAX_MANA*27, PLAYER_MAX_MANA*40))/PLAYER_MAX_MANA; } this->player = player; float strength; if (getGameState()->getIntroState() == INTRO_ATTACK) { strength = 0.2f; } else { strength = ghostType.getStrength(); } hit = hit*strength; lastTime = clock(); interval = 3000; over = false; }
void Food::update(uint64 time) { IW_CALLSTACK("Food::update"); this->iTime = time; this->iTimePassed += time; if(this->bAffectUpdate == true) { if(this->iTextureIndex == 0) this->bEmpty = false; if(this->bEmpty == false) this->setShiny(); this->bAffectUpdate = false; } if(this->bUpdate == true) { if(this->bEmpty == false) { this->bEmpty = true; this->iSoundIndex = IwRandMinMax(0, 5); this->changeTexture(1); this->bUpdate = false; this->setNotShiny(); for(int i = 0; i <(int)uAffectList.size(); ++i) { this->uAffectList[i]->bAffectUpdate = true; } for( int i = 0; i < (int)this->uAttatchedToList.size(); ++i) { int x = this->uAttatchedToList.size(); if(dynamic_cast<Food*>(uAttatchedToList[i])->bEmpty == false) { dynamic_cast<Food*>(this->uAttatchedToList[i])->setNotShiny(); dynamic_cast<Food*>(this->uAttatchedToList[i])->bEmpty = true; } } } ShinyUnit::update(); this->bUpdate = false; } }
void LitterBox::update(uint64 time) { IW_CALLSTACK("LitterBox::update"); if (GameState::getState() != GameState::PLAY) { return; } this->iTime = time; this->iTimePassed += time; if(this->bAffectUpdate == true) { if(this->iTextureIndex == 0) this->bFull = false; if(this->bFull == false) this->setShiny(); this->bAffectUpdate = false; } if(this->bUpdate == true) { if(this->bFull == false) { this->iSoundIndex = IwRandMinMax(0, 4); this->bFull = true; this->changeTexture(1); for( int i = 0; i <(int) this->uAffectList.size(); ++i) { this->uAffectList[i]->bAffectUpdate = true; } for(int i = 0; i <(int)this->uAttatchedToList.size(); ++i) { dynamic_cast<ShinyUnit*>( this->uAttatchedToList[i])->setNotShiny(); dynamic_cast<LitterBox*>(this->uAttatchedToList[i])->bFull = true; } } ShinyUnit::update(); this->bUpdate = false; } }
void CatEvent::setEvent() { IW_CALLSTACK("CatEventt::setEvent"); int iRandomNum = IwRandMinMax(7, 10); switch(iRandomNum) { case 7: // cout << "LICK" << endl; this->csPlayWith = CatState::LICKINGSELF; break; case 8: //cout << "SCRATCH" << endl; this->csPlayWith = CatState::SCRATCHINGSELF; break; case 9: //cout << "STRETCH" << endl; this->csPlayWith = CatState::STRETCHING; break; default: IwAssertMsg(MYAPP, false, ("Invalid CatState")); this->csPlayWith = CatState::IDLING; } }
Icing::Icing(const CIwFVec2 position, Game* game, Player* owner) : owner(owner), scale(0.02f), finalScale(.12f), WorldObject(position, game) { angle = TO_RADIANS(IwRandMinMax(0, 360)); texture_names.push_back(IwHashString("icing")); }
void BackgroundManager::loadBackground(string backgroundName, CIwArray<string> extras) { IW_CALLSTACK("BackgroundManager::loadBackground"); this->units.clear(); if ( extras.size() != 0) { for ( int x = 0; x < (int)extras.size(); ++x) { if (extras[x].compare("cloud") == 0) { IwRandSeed ( time(NULL) ); int num = IwRandMinMax(1, 6); // how many clouds should be made for ( int i = 0; i < num ; ++i) { CIwSVec2 pos = CIwSVec2( IwRandMinMax(-Screen::getBOXSIZE().x, Screen::getSCREENSIZE().x), IwRandMinMax(0, (int)(Screen::getSCREENSIZE().y * 0.33f))); float velocity = (float) IwRandMinMax(500 ,2000) / 1000.0f; int type = IwRandMinMax(1, 10); // the number of cloud pictures we have Cloud * cloud = new Cloud(pos, velocity, type); this->units.push_back(cloud); } } else if (extras[x].compare("bird") == 0 ) { CIwSVec2 pos = CIwSVec2(IwRandMinMax(0, Screen::getSCREENSIZE().x), IwRandMinMax(0, (int)(Screen::getSCREENSIZE().y * 0.4f))); float velocity = IwRandMinMax(1000, 4000)/100.0f; Bird * bird = new Bird(pos, velocity); this->units.push_back(bird); } else if (extras[x].compare("gear") == 0 ) { CIwSVec2 pos = CIwSVec2((int)(Screen::getSCREENSIZE().x * 0.3f), (int)(Screen::getSCREENSIZE().y * 0.4f)); float velocity = (float)IwRandMinMax(1, 1000) / 10.0f; Gear * gear = new Gear(0); Gear * gear1 = new Gear(1); Gear * gear2 = new Gear(2); this->units.push_back(gear); this->units.push_back(gear1); this->units.push_back(gear2); } else if (extras[x].compare("spiral") == 0) { this->units.push_back(new Spiral(CIwSVec2(Screen::getSCREENSIZE().x * 0.5 - 268/2, Screen::getSCREENSIZE().y * 0.5 - 268/2))); //this->units.push_back(new Spiral(CIwSVec2(Screen::getSCREENSIZE().x * 0.75 - 268/4, Screen::getSCREENSIZE().y * 0.5 - 272/4))); } } } this->backgroundSegments.clear(); //if background is undefined no background is shown if ( backgroundName.compare("") == 0) { return; } // format has to follow backgroundName + "piece number" this->backgroundSegments.push_back(ImageManager::getImage( (backgroundName+"0").c_str() )); this->backgroundSegments.push_back(ImageManager::getImage( (backgroundName+"1").c_str() )); this->backgroundSegments.push_back(ImageManager::getImage( (backgroundName+"2").c_str() )); this->backgroundSegments.push_back(ImageManager::getImage( (backgroundName+"3").c_str() )); }
void CaptureGameEngine::Start() { Utils::GetLocation(&g_startLocation); IwRandSeed(s3eTimerGetMs()); // get the 9 tiles around our location int acx = LiveMaps::LongitudeToXAtZoom(g_startLocation.m_Longitude, LiveMaps::MaxZoom); int acy = LiveMaps::LatitudeToYAtZoom(g_startLocation.m_Latitude, LiveMaps::MaxZoom); int tx = acx / 256; int ty = acy / 256; int x = tx * 256; int y = ty * 256; g_tileLoc.x = (acx - x); g_tileLoc.y = (acy - y); char szQuad[20]; char szImageUrl[256]; g_topLeft.x = x;// + 128; g_topLeft.y = y;// + 128; for (int ttx = tx - 1; ttx <= tx + 1; ++ttx) { for (int tty = ty - 1; tty <= ty + 1; ++tty) { int server = 0; LiveMaps::TileToQuadKey(szQuad, ttx, tty, LiveMaps::MaxZoom); sprintf(szImageUrl, "http://r%i.ortho.tiles.virtualearth.net/tiles/%s%s.%s?g=22", server, "h", szQuad, "jpg"); g_pTiles[1 + (ttx-tx)][1 + (tty-ty)] = 0; Utils::DownloadMapTile(&g_pTiles[1 + (ttx-tx)][1 + (tty-ty)], szImageUrl); } } s3eLocation bottomRight, topLeft, topRight, bottomLeft, center; bottomRight.m_Latitude = LiveMaps::YToLatitudeAtZoom(y+512, LiveMaps::MaxZoom); bottomRight.m_Longitude = LiveMaps::XToLongitudeAtZoom(x+512, LiveMaps::MaxZoom); topLeft.m_Latitude = LiveMaps::YToLatitudeAtZoom(y-256, LiveMaps::MaxZoom); topLeft.m_Longitude = LiveMaps::XToLongitudeAtZoom(x-256, LiveMaps::MaxZoom); if (topLeft.m_Longitude > bottomRight.m_Longitude) { float longitude = bottomRight.m_Longitude; bottomRight.m_Longitude = topLeft.m_Longitude; topLeft.m_Longitude = longitude; } if (topLeft.m_Latitude > bottomRight.m_Latitude) { float latitude = bottomRight.m_Latitude; bottomRight.m_Latitude = topLeft.m_Latitude; topLeft.m_Latitude = latitude; } topRight.m_Longitude = topLeft.m_Longitude; topRight.m_Latitude = bottomRight.m_Latitude; center.m_Latitude = (bottomRight.m_Latitude + topLeft.m_Latitude) / 2; center.m_Longitude = (bottomRight.m_Longitude + topLeft.m_Longitude) / 2; float maxDir = LiveMaps::CalculateDistance(topLeft, topRight) / 2.1; IGameHandler* pHandler = (IGameHandler*)g_pGameHandler; Region* pRegion = pHandler->GetBoundingRegion(); for (int i = 0; i < 15; ++i) { s3eLocation* randLoc = new s3eLocation; // Calculate a random location within a given radius int tryCount = 20; do { double angle = PI / 180.0 * IwRandMinMax(-180, 180); // 360 degree range int32 radius = IwRandMinMax(5, maxDir); // 50 meters LiveMaps::CalculateLatLongInDirection(¢er, radius, angle, randLoc); s3eLocation testLoc = *randLoc; if (pRegion->Contains(testLoc) && (testLoc.m_Latitude >= topLeft.m_Latitude) && (testLoc.m_Latitude <= bottomRight.m_Latitude) && (testLoc.m_Longitude >= topLeft.m_Longitude) && (testLoc.m_Longitude <= bottomRight.m_Longitude)) { break; } } while (tryCount-- > 0); g_pCaptures.push_back(randLoc); } g_caughtAllTime = 0; }
void CameraDefend::reinit() { float width = (float)IwGxGetScreenWidth()*0.15f; //width = width > 120 ? 120 : width; float height = width; float padding = (float)IwGxGetScreenWidth()*0.05f; int mid = IwGxGetScreenHeight()/2; int heightSqrt = sqrt(IwGxGetScreenHeight()/2); bool leftAboveMid; float locPadding = (float)IwGxGetScreenHeight()*0.10f; { // The dot prefers corners int positionFromMid = IwRandMinMax(0, heightSqrt) * IwRandMinMax(0, heightSqrt); positionFromMid = IwGxGetScreenHeight()/2 - positionFromMid; leftAboveMid = IwRandMinMax(0, 9) < 5; int leftSpotY = leftAboveMid ? mid - positionFromMid + locPadding : mid + positionFromMid - locPadding - height; dotVertsTopLeftLeft = CIwFVec2(padding, leftSpotY); dotVertsSizeLeft = CIwFVec2(width, height); animVertsLeft[0] = CIwFVec2(dotVertsTopLeftLeft.x - width, dotVertsTopLeftLeft.y - height); animVertsLeft[1] = CIwFVec2(dotVertsTopLeftLeft.x - width, dotVertsTopLeftLeft.y + height*2); animVertsLeft[2] = CIwFVec2(dotVertsTopLeftLeft.x + width*2, dotVertsTopLeftLeft.y + height*2); animVertsLeft[3] = CIwFVec2(dotVertsTopLeftLeft.x + width*2, dotVertsTopLeftLeft.y - height); animVertsLeftSuccess[0] = animVertsLeft[0]; animVertsLeftSuccess[1] = animVertsLeft[1]; animVertsLeftSuccess[2] = animVertsLeft[2]; animVertsLeftSuccess[3] = animVertsLeft[3]; } { int positionFromMid = IwRandMinMax(0, heightSqrt) * IwRandMinMax(0, heightSqrt); positionFromMid = IwGxGetScreenHeight()/2 - positionFromMid; // The dot prefers the opposite corner bool rightAboveMid = leftAboveMid ? IwRandMinMax(0, 9) < 2 : IwRandMinMax(0, 9) >= 2; int rightSpotY = rightAboveMid ? mid - positionFromMid + locPadding : mid + positionFromMid - locPadding - height; int screenW = IwGxGetScreenWidth(); dotVertsTopLeftRight = CIwFVec2(screenW-padding-width, rightSpotY); dotVertsSizeRight = CIwFVec2(width, height); animVertsRight[0] = CIwFVec2(dotVertsTopLeftRight.x - width, dotVertsTopLeftRight.y - height); animVertsRight[1] = CIwFVec2(dotVertsTopLeftRight.x - width, dotVertsTopLeftRight.y + height*2); animVertsRight[2] = CIwFVec2(dotVertsTopLeftRight.x + width*2, dotVertsTopLeftRight.y + height*2); animVertsRight[3] = CIwFVec2(dotVertsTopLeftRight.x + width*2, dotVertsTopLeftRight.y - height); animVertsRightSuccess[0] = animVertsRight[0]; animVertsRightSuccess[1] = animVertsRight[1]; animVertsRightSuccess[2] = animVertsRight[2]; animVertsRightSuccess[3] = animVertsRight[3]; } for (int i = 0; i < DEFEND_TOUCHES_MAX; i++) { touch[i]->drawing = false; } }
void PatteRunGameEngine::Activate() { /* g_pBall->Reset(); g_pCompPaddle->Reset(); g_pUserPaddle->Reset(); */ int width = Iw2DGetSurfaceWidth(); int height = Iw2DGetSurfaceHeight(); CIwFVec2 accuracy = g_pGameHandler->GetAccuracy(); double widthMeter = g_pGameHandler->GetScaler()->GetMetersPerPixelX() * width; double heightMeter = g_pGameHandler->GetScaler()->GetMetersPerPixelY() * height; float maxAccuracy = MIN(accuracy.x, accuracy.y); double xWidth = widthMeter / maxAccuracy; double yWidth = heightMeter / maxAccuracy; int iRows = MAX(3, ceil(yWidth)); int iCols = MAX(3, ceil(xWidth)); int tileWidth = ceil((double)width / iCols); int tileHeight = ceil((double)height / iRows); std::list<CGridTile*>::iterator iter = g_pTiles.begin(); while (iter != g_pTiles.end()) { delete *iter; iter++; } g_pTiles.clear(); for (int i = 0; i < iCols; ++i) { for (int j = 0; j < iRows; ++j) { bool isDark = ((i + j) % 2) == 0; CIwRect bounds(i * tileWidth, j * tileHeight, tileWidth, tileHeight); CGridTile* pTile = new CGridTile(g_pGameHandler, bounds, isDark); g_pTiles.push_back(pTile); } } int lastX = -1; int lastY = -1; for (int i = 0; i < 20; ++i) { int xRand, yRand; do { xRand = IwRandMinMax(0, iCols); yRand = IwRandMinMax(0, iRows); } while (xRand == lastX && yRand == lastY); g_pCoords[i] = xRand + iCols * yRand; lastX = xRand; lastY = yRand; } g_iLevel = 0; g_iCounter = -1; g_iGameCounter = 0; g_iScore = g_iDisplayedScore = 0; g_handler.Start(1500, 3, 1000); }