//New Game void GameWorld::NewGame() { //Clear the background of any decals SDL_BlitSurface(gConMgr.GetSurface("sprites/grid.fif"), 0, m_surf_background, &renderarea); //Check if player is still on the map (wont be if you died) bool onmap=0; for(int y = 0; y < 11; y++) { for(int x = 0; x < 17; x++) { if(m_gamegrid[x][y].ent != NULL) { if(m_gamegrid[x][y].ent == &m_players[0]){onmap=1;} } } } //If your not on the map let's add you back to it if(onmap == 0) { int rx=qRand(0, 17),ry=qRand(0, 11); while(m_gamegrid[rx][ry].ent != NULL) { rx = qRand(0, 17); ry = qRand(0, 11); } m_gamegrid[rx][ry].ent = &m_players[0]; m_players[0].SetPos(rx, ry); } //Reset game and player m_level = 0; m_bonustype = 0; m_players[0].InitPlayer("Spaceman"); m_gamemode = 0; hat_regulator = GetTicks(); well_regulator = GetTicks(); memset(&m_description, 0x00, sizeof(m_description)); memset(&line1, 0x00, 34); memset(&line2, 0x00, 34); memset(&line3, 0x00, 34); memset(&line4, 0x00, 34); memset(&line5, 0x00, 34); GenerateRandomLevel(); }
//Moves game onto the next level void GameWorld::NextLevel() { if(m_gamemode == 0){GenerateRandomLevel();} if(m_gamemode == 1){m_level++; LoadLevel();} }
//Load the new level organization void Fleet::LoadLevel(short unsigned level) { space_definition.x = ((WIDTH / 2) - ((FLEET_COLUMNS * INVADER_SPRITE_DIMENSION) / 2) - ((INVADERS_SEPARATION * FLEET_COLUMNS) / 2)); space_definition.y = TOP_LIMIT; if(level == 1) { total_invaders = 40; horizontal_speed = 3; vertical_speed = 10; for(short row = 0, column = 0; row != FLEET_ROWS; column++) { //Reset the columns when reached the limit of the matrix if(column == FLEET_COLUMNS) { column = -1; row++; } else { //Revive the Invader (fleet_matrix->Get(row, column))->Revive(); //Load the type if(row == 0 || row == 4) { (fleet_matrix->Get(row, column))->SetType(INVADER_MEDIUM); } else { (fleet_matrix->Get(row, column))->SetType(INVADER_LOW); } } } } else if(level == 2) { total_invaders = 40; horizontal_speed = 5; vertical_speed = 13; GenerateRandomLevel(); } else if(level == 3) { total_invaders = 40; horizontal_speed = 7; vertical_speed = 16; GenerateRandomLevel(); } else if(level == 4) { total_invaders = 40; horizontal_speed = 9; vertical_speed = 19; GenerateRandomLevel(); } else if(level == 5) { total_invaders = 40; horizontal_speed = 11; vertical_speed = 22; GenerateRandomLevel(); } else { total_invaders = 40; horizontal_speed = 13; vertical_speed = 25; for(short row = 0, column = 0; row != FLEET_ROWS; column++) { //Reset the columns when reached the limit of the matrix if(column == FLEET_COLUMNS) { column = -1; row++; } else { //Revive the Invader (fleet_matrix->Get(row, column))->Revive(); //Load the type (fleet_matrix->Get(row, column))->SetType(INVADER_HIGH); } } } }