EXPORT_C void AknDialogShutter::ShutDialogsL(CEikonEnv& aEikEnv) { CEikAppUi* appUi=aEikEnv.EikAppUi(); for (TInt attempt=0; attempt<50; attempt++) // maximum of 50 attempts to close dialogs { TInt startLevel=StartLevel(); if (appUi->IsDisplayingMenuOrDialog()) { TKeyEvent key; key.iCode=EKeyEscape; key.iModifiers=0; key.iRepeats = 0; key.iScanCode = EStdKeyNull; aEikEnv.SimulateKeyEventL(key, EEventKey); } else { break; // stop if there are no more dialogs } if (StartLevel() > startLevel) break; // stop if a confirmation dialog has popped up } }
void GameEngine::Frame(float _dt) { MovingObject *currentCharacter = NULL; if (!m_levelStarted) StartLevel("biglvl"); // In the future there will be some sort of level selection so this call will be moved // Spawn enemies from pipes for (std::map<unsigned int, Pipe*>::iterator it = m_listPipes.begin(); it != m_listPipes.end(); ++it) { if (it->second->GetPipeType() == SPAWN) it->second->HandleSpawnEnemies(_dt); } for (unsigned int i = 0; i < m_characters.size(); i++) { currentCharacter = m_characters[i]; if (currentCharacter != NULL) { if (1 / _dt > 20) // No updating at all if framerate < 20 (usually the first few iterations) because it results in inacurrate updating (like Mario drops 300 pixels at beginning of level) UpdateCharacterPosition(*currentCharacter, _dt); HandleCollisions(*currentCharacter); SendCharacterPosition(i); } } DeleteAllDeadCharacters(); }
void CLevel::Enter() { CDMGame::Get()->RegisterUpdateable(this); CDMGame::Get()->RegisterRenderable(this); CDMGame::Get()->SetGameState(kGameStateInGame); StartLevel(); }
void GameBase::StartTitle(void) { m_title=true; m_level=10; m_numplayers=0; m_gameover=false; m_playing=false; StartLevel(); }
void Game::NewGame() { // Reset score, lives, etc. score = 0; lives = 3; // Start the game { ConfigFile cfile; level = cfile.get_int("level", 1); } nextnewlife = 1000; StartLevel(); }
void GameBase::RockHit(Rock *rock) { unsigned int i; unsigned int size; double radius; Rock *newrock; if(++(rock->m_size)==NUMROCKSIZES) { /* smallest size! */ rock->m_active=false; --m_numrocks; if(!m_numrocks) { ++m_level; StartLevel(); } } else { /* make this one a smaller rock */ GenerateRock(rock); /* make a few more too */ size=rock->m_size; radius=rock->m_maxradius*0.75f; for(i=0;i<MAXROCKS;++i) { newrock=&m_rock[i]; if(newrock->m_active==false) { newrock->m_active=true; newrock->m_x=rock->m_x+Rand(-radius,radius); newrock->m_y=rock->m_y+Rand(-radius,radius); newrock->m_size=size; GenerateRock(newrock); m_numrocks++; return; } } } }
void GameBase::Start(void) { unsigned int i; Ship *ship; m_title=false; m_numplayersleft=m_numplayers; m_level=0; m_gameover=false; m_playing=true; m_ufo.m_appearside=false; for(i=0;i<MAXPLAYERS;++i) { ship=&m_ship[i]; ship->m_life=m_lives; ship->m_score=0; ship->m_color=m_shipcolors[i]; ship->m_thrustsound=false; } StartLevel(); }
//called when the player has died void DoPlayerDead() { int cycle_window_vis = 1; #ifdef NETWORK if ( (Game_mode & GM_MULTI) && (Netgame.SpawnStyle == SPAWN_STYLE_PREVIEW)) { cycle_window_vis = 0; } #endif if (Game_wind && cycle_window_vis) window_set_visible(Game_wind, 0); reset_palette_add(); gr_palette_load (gr_palette); dead_player_end(); //terminate death sequence (if playing) #ifdef EDITOR if (Game_mode == GM_EDITOR) { //test mine, not real level object * player = &Objects[Players[Player_num].objnum]; //nm_messagebox( "You're Dead!", 1, "Continue", "Not a real game, though." ); if (Game_wind) window_set_visible(Game_wind, 1); load_level("gamesave.lvl"); init_player_stats_new_ship(Player_num); player->flags &= ~OF_SHOULD_BE_DEAD; StartLevel(0); return; } #endif #ifdef NETWORK if ( Game_mode&GM_MULTI ) { multi_do_death(Players[Player_num].objnum); } else #endif { //Note link to above else! Players[Player_num].lives--; if (Players[Player_num].lives == 0) { DoGameOver(); return; } } if ( Control_center_destroyed ) { int rval; //clear out stuff so no bonus Players[Player_num].hostages_on_board = 0; Players[Player_num].energy = 0; Players[Player_num].shields = 0; #ifdef NETWORK Players[Player_num].connected = CONNECT_DIED_IN_MINE; #endif do_screen_message(TXT_DIED_IN_MINE); // Give them some indication of what happened if (Current_level_num == Last_level) { #ifdef NETWORK if ((Game_mode & GM_MULTI) && !(Game_mode & GM_MULTI_COOP)) { multi_endlevel_score(); rval = AdvanceLevel(0); //if finished, go on to next level } else #endif { // Note link to above else! rval = AdvanceLevel(0); //if finished, go on to next level DoEndLevelScoreGlitz(0); } init_player_stats_new_ship(Player_num); last_drawn_cockpit = -1; } else { #ifdef NETWORK if (Game_mode & GM_MULTI) multi_endlevel_score(); else #endif DoEndLevelScoreGlitz(0); // Note above link! rval = AdvanceLevel(0); //if finished, go on to next level init_player_stats_new_ship(Player_num); last_drawn_cockpit = -1; } if (rval) { #ifndef SHAREWARE if (PLAYING_BUILTIN_MISSION) #endif scores_maybe_add_player(0); if (Game_wind) window_close(Game_wind); // Exit out of game loop } } else { init_player_stats_new_ship(Player_num); StartLevel(1); } if (Game_wind && cycle_window_vis) window_set_visible(Game_wind, 1); reset_time(); }
//called when the player is starting a new level for normal game mode and restore state void StartNewLevelSub(int level_num, int page_in_textures, int secret_flag) { /* * This flag is present for compatibility with D2X. Set it to zero * so the optimizer deletes all reference to it. */ secret_flag = 0; if (!(Game_mode & GM_MULTI)) { last_drawn_cockpit = -1; } if (Newdemo_state == ND_STATE_PAUSED) Newdemo_state = ND_STATE_RECORDING; if (Newdemo_state == ND_STATE_RECORDING) { newdemo_set_new_level(level_num); newdemo_record_start_frame(FrameTime ); } LoadLevel(level_num, page_in_textures); Assert(Current_level_num == level_num); //make sure level set right gameseq_init_network_players(); // Initialize the Players array for // this level #ifdef NETWORK if (Game_mode & GM_NETWORK) { if(multi_level_sync()) // After calling this, Player_num is set { songs_play_song( SONG_TITLE, 1 ); // level song already plays but we fail to start level... return; } } #endif HUD_clear_messages(); automap_clear_visited(); init_player_stats_level(secret_flag); gr_use_palette_table( "palette.256" ); gr_palette_load(gr_palette); #ifndef SHAREWARE #ifdef NETWORK if ((Game_mode & GM_MULTI_COOP) && Network_rejoined) { int i; for (i = 0; i < N_players; i++) Players[i].flags |= Netgame.player_flags[i]; } #endif #endif Viewer = &Objects[Players[Player_num].objnum]; #ifdef NETWORK if (Game_mode & GM_MULTI) { multi_prep_level(); // Removes robots from level if necessary } #endif gameseq_remove_unused_players(); Game_suspended = 0; Control_center_destroyed = 0; init_cockpit(); init_robots_for_level(); init_ai_objects(); init_morphs(); init_all_matcens(); reset_palette_add(); if (!(Game_mode & GM_MULTI) && !cheats.enabled) set_highest_level(Current_level_num); reset_special_effects(); #ifdef OGL ogl_cache_level_textures(); #endif #ifdef NETWORK if (Network_rejoined == 1) { Network_rejoined = 0; StartLevel(1); } else #endif StartLevel(0); // Note link to above if! copy_defaults_to_robot_all(); init_controlcen_for_level(); // Say player can use FLASH cheat to mark path to exit. Last_level_path_created = -1; // Initialise for palette_restore() if (!((Game_mode & GM_MULTI) && (Newdemo_state != ND_STATE_PLAYBACK))) palette_save(); if (!Game_wind) game(); }
//called when the player is starting a new level for normal game mode and restore state void StartNewLevelSub(int level_num, int page_in_textures) { if (!(Game_mode & GM_MULTI)) { last_drawn_cockpit = -1; } if (Newdemo_state == ND_STATE_PAUSED) Newdemo_state = ND_STATE_RECORDING; if (Newdemo_state == ND_STATE_RECORDING) { newdemo_set_new_level(level_num); newdemo_record_start_frame(FrameTime ); } if (Game_mode & GM_MULTI) Function_mode = FMODE_MENU; // Cheap fix to prevent problems with errror dialogs in loadlevel. LoadLevel(level_num); if ( page_in_textures ) { piggy_load_level_data(); } Assert(Current_level_num == level_num); //make sure level set right gameseq_init_network_players(); // Initialize the Players array for // this level #ifdef NETWORK if (Game_mode & GM_NETWORK) { if(network_level_sync()) // After calling this, Player_num is set return; } #endif Assert(Function_mode == FMODE_GAME); HUD_clear_messages(); automap_clear_visited(); #ifdef NETWORK if (Network_new_game == 1) { Network_new_game = 0; init_player_stats_new_ship(); } #endif init_player_stats_level(); #ifndef SHAREWARE #ifdef NETWORK if ((Game_mode & GM_MULTI_COOP) && Network_rejoined) { int i; for (i = 0; i < N_players; i++) Players[i].flags |= Netgame.player_flags[i]; } #endif #endif Viewer = &Objects[Players[Player_num].objnum]; #ifdef NETWORK if (Game_mode & GM_MULTI) { multi_prep_level(); // Removes robots from level if necessary } #endif gameseq_remove_unused_players(); count_powerup_start_level(); Game_suspended = 0; Fuelcen_control_center_destroyed = 0; init_cockpit(); init_robots_for_level(); init_ai_objects(); init_morphs(); init_all_matcens(); reset_palette_add(); game_flush_inputs(); // clear out the keyboard if (!(Game_mode & GM_MULTI) && !Cheats_enabled) set_highest_level(Current_level_num); reset_special_effects(); #ifdef OGL ogl_cache_level_textures(); #endif #ifdef NETWORK if (Network_rejoined == 1) { Network_rejoined = 0; StartLevel(1); } else #endif StartLevel(0); // Note link to above if! copy_defaults_to_robot_all(); init_controlcen_for_level(); // Say player can use FLASH cheat to mark path to exit. Last_level_path_created = -1; }
//called when the player has died void DoPlayerDead() { reset_palette_add(); gr_palette_load (gr_palette); dead_player_end(); //terminate death sequence (if playing) #ifdef HOSTAGE_FACES stop_all_hostage_clips(); #endif #ifdef EDITOR if (Game_mode == GM_EDITOR) { //test mine, not real level object * player = &Objects[Players[Player_num].objnum]; //nm_messagebox( "You're Dead!", 1, "Continue", "Not a real game, though." ); load_level("gamesave.lvl"); init_player_stats_new_ship(); player->flags &= ~OF_SHOULD_BE_DEAD; StartLevel(0); return; } #endif #ifdef NETWORK if ( Game_mode&GM_MULTI ) { multi_do_death(Players[Player_num].objnum); } else #endif { //Note link to above else! Players[Player_num].lives--; if (Players[Player_num].lives == 0) { DoGameOver(); return; } } if ( Fuelcen_control_center_destroyed ) { int rval; //clear out stuff so no bonus Players[Player_num].hostages_on_board = 0; Players[Player_num].energy = 0; Players[Player_num].shields = 0; Players[Player_num].connected = 3; died_in_mine_message(); // Give them some indication of what happened if (Current_level_num == Last_level) { #ifdef NETWORK if ((Game_mode & GM_MULTI) && !(Game_mode & GM_MULTI_COOP)) { multi_endlevel_score(); rval = AdvanceLevel(0); //if finished, go on to next level } else #endif { // Note link to above else! rval = AdvanceLevel(0); //if finished, go on to next level DoEndLevelScoreGlitz(0); } init_player_stats_new_ship(); last_drawn_cockpit = -1; } else { #ifdef NETWORK if (Game_mode & GM_MULTI) multi_endlevel_score(); else #endif DoEndLevelScoreGlitz(0); // Note above link! rval = AdvanceLevel(0); //if finished, go on to next level init_player_stats_new_ship(); last_drawn_cockpit = -1; } if (rval) { #ifndef SHAREWARE if (PLAYING_BUILTIN_MISSION) #endif scores_maybe_add_player(0); longjmp( LeaveGame, 1 ); // Exit out of game loop } } else { init_player_stats_new_ship(); StartLevel(1); } }
// on "init" you need to initialize your instance bool LiquidFunScene::init() { ////////////////////////////// // 1. super init first if ( !CCLayer::init() ) { return false; } CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); ///////////////////////////// // 2. add a menu item with "X" image, which is clicked to quit the program // you may modify it. // add a "close" icon to exit the progress. it's an autorelease object CCMenuItemImage *pCloseItem = CCMenuItemImage::create( "CloseNormal.png", "CloseSelected.png", this, menu_selector(LiquidFunScene::menuCloseCallback)); pCloseItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2, origin.y + pCloseItem->getContentSize().height/2)); // create menu, it's an autorelease object CCMenu* pMenu = CCMenu::create(pCloseItem, NULL); pMenu->setPosition(CCPointZero); addChild(pMenu, 1); // Add a label shows the title of the demo. CCLabelTTF* pLabel = CCLabelTTF::create("LiquidFun Demo in Cocos2Dx", "Arial", 24); // Position the label on the center of the screen. pLabel->setPosition(ccp(origin.x + visibleSize.width/2, origin.y + visibleSize.height - pLabel->getContentSize().height)); // add the label as a child to this layer addChild(pLabel, 1); // add "LiquidFunScene" splash screen" CCSprite* pSprite = CCSprite::create("HelloWorld.png"); // position the sprite on the center of the screen pSprite->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y)); // scale the background to fill the screen. const CCSize &size = pSprite->getTextureRect().size; pSprite->setScale(b2Max(visibleSize.width, visibleSize.height) / b2Max(size.width, size.height)); // add the sprite as a child to this layer addChild(pSprite, 0); // ---------------------------------- // Immediately start level 0, since we have no other interface to manage // levels LayoutLevel(0); StartLevel(); return true; }
void Game::Process() { Input& input = Input::GetInstance(); OpenGL& opengl = OpenGL::GetInstance(); // Check keys if (input.QueryAction(Input::PAUSE)) { if (state == gsPaused) { // Unpause the game state = gsInGame; } else if (state == gsInGame) { // Pause the game state = gsPaused; ship.ThrustOff(); } input.ResetAction(Input::PAUSE); } if (input.QueryResetAction(Input::SCREENSHOT)) opengl.DeferScreenShot(); // Do no more game processing in the paused state if (state == gsPaused) return; if (input.QueryAction(Input::THRUST) && !fuelmeter.OutOfFuel() && state == gsInGame) { // Thrusting ship.ThrustOn(); ship.Thrust(SHIP_SPEED); fuelmeter.BurnFuel(); } else ship.ThrustOff(); if (input.QueryAction(Input::RIGHT) && state == gsInGame) { // Turn clockwise ship.Turn(TURN_ANGLE); } else if (input.QueryAction(Input::LEFT) && state == gsInGame) { // Turn anti-clockwise ship.Turn(-TURN_ANGLE); } if (input.QueryAction(Input::SKIP) && state == gsExplode) { // The player got bored watching the explosion EnterDeathWait(lives == 0 ? DEATH_TIMEOUT : 1); } if (input.QueryAction(Input::ABORT) && state == gsInGame) { // Quit to main menu ExplodeShip(); lives = 0; } if (input.QueryAction(Input::DEBUG)) { // Toggle debug mode bDebugMode = !bDebugMode; input.ResetAction(Input::DEBUG); } // Move only if not in game over if (state == gsInGame || state == gsExplode) { ship.ApplyGravity(flGravity); // Move the ship (and exhaust and explosion) ship.Move(); } ship.ProcessEffects(state == gsPaused, state == gsExplode); // Move mines for (MineListIt it = mines.begin(); it != mines.end(); ++it) (*it).Move(); // Move or fire missiles for (MissileListIt it = missiles.begin(); it != missiles.end(); ++it) (*it).Move(ship); // Calculate view adjusts ship.CentreInViewport(); // Check for collisions with surface int padIndex; if (surface.CheckCollisions(ship, pads, &padIndex)) { bool landed = false; if (state == gsInGame) { if (padIndex != -1) { // Hit a landing pad int dAngle = ((int)ship.GetAngle()) % 360; if ((dAngle >= 330 || dAngle <= 30) && speedmeter.SafeLandingSpeed() && nKeysRemaining == 0) { // Landed safely state = gsLevelComplete; CalculateScore(padIndex); countdown_timeout = 70; landed = true; } } if (!landed) { // Crash landed ExplodeShip(); ship.Bounce(); } } else if (state == gsExplode) EnterDeathWait(); } // Check for collisions with asteroids LineSegment l1, l2; for (AsteroidListIt it = asteroids_.begin(); it != asteroids_.end(); ++it) { const Asteroid& a = *it; if (a.ObjectInScreen(&viewport)) { if (a.CheckCollision(ship)) { // Crashed if (state == gsInGame) { // Destroy the ship ExplodeShip(); ship.Bounce(); } else if (state == gsExplode) EnterDeathWait(); } } } // Check for collision with gateways for (ElectricGateListIt it = gateways.begin(); it != gateways.end(); ++it) { if ((*it).CheckCollision(ship)) { if (state == gsInGame) { // Destroy the ship ExplodeShip(); ship.Bounce(); } else if (state == gsExplode) { // Destroy the ship anyway EnterDeathWait(); } } } // Check for collisions with mines for (MineListIt it = mines.begin(); it != mines.end(); ++it) { if ((*it).CheckCollision(ship)) { if (state == gsInGame) { // Destroy the ship ExplodeShip(); ship.Bounce(); } else if (state == gsExplode) EnterDeathWait(); } } // Check for collisons with missiles for (MissileListIt it = missiles.begin(); it != missiles.end(); ++it) { if ((*it).CheckCollison(ship)) { if (state == gsInGame) { // Destroy the ship ExplodeShip(); ship.Bounce(); } else if (state == gsExplode) EnterDeathWait(); } } // See if the player collected a key for (KeyListIt it = keys.begin(); it != keys.end(); ++it) { if((*it).CheckCollision(ship)) { nKeysRemaining--; (*it).Collected(); objgrid.UnlockSpace((*it).GetX(), (*it).GetY()); collectSound.Play(); } } // Entry / exit states if (state == gsDeathWait) { if (--death_timeout == 0) { // Fade out if (lives == 0 || (lives == 1 && life_alpha < LIFE_ALPHA_BASE)) state = gsFadeToDeath; else if (lives > 0) { if (life_alpha < LIFE_ALPHA_BASE) { life_alpha = LIFE_ALPHA_BASE + 1.0f; lives--; } state = gsFadeToRestart; } fade.BeginFadeOut(); } } else if (state == gsGameOver) { if (--death_timeout == 0) { // Fade out state = gsFadeToDeath; fade.BeginFadeOut(); } } else if (state == gsFadeIn) { // Fade in if (fade.Process()) state = gsInGame; } else if (state == gsFadeToRestart) { // Fade out if (fade.Process()) { // Restart the level StartLevel(); opengl.SkipDisplay(); } } else if (state == gsFadeToDeath) { if (fade.Process()) { // Return to main menu ScreenManager& sm = ScreenManager::GetInstance(); HighScores* hs = static_cast<HighScores*>(sm.GetScreenById("HIGH SCORES")); hs->CheckScore(score); } } else if (state == gsLevelComplete) { // Decrease the displayed score if (countdown_timeout > 0) countdown_timeout--; else if (levelcomp_timeout > 0) { if (--levelcomp_timeout == 0) { level++; state = gsFadeToRestart; fade.BeginFadeOut(); } } else { int dec = level * 2; // Decrease the score newscore -= dec; score += dec; if (score > nextnewlife) { lives++; nextnewlife *= 2; } if (newscore < 0) { // Move to the next level (after a 1s pause) score -= -newscore; levelcomp_timeout = 40; } } } // Decrease level text timeout if (leveltext_timeout > 0) leveltext_timeout--; // Spin the ship if we're exploding if (state == gsExplode) ship.Turn(DEATH_SPIN_RATE); }