bool updateGame(void) { /* In cas of pausing */ if (state == STATE_PAUSE) { if (arduboy.buttonDown(A_BUTTON | B_BUTTON)) { state = STATE_GAME; ignoreCnt = 30; // 1/2 sec toDraw = true; dprintln("Resume"); } return false; } /* Move objects */ int scrollX = -playerX / 4; int scrollY = -playerY / 4; playerX += scrollX; playerY += scrollY; playerRotate += playerTorque; if (playerJump > -64) { if (--playerJump == 0) { pFloorBlur = NULL; if (state == STATE_CLEAR) { initLevel(false); } } } if (state != STATE_OVER) { moveFloors(scrollX, scrollY, playerJump); } moveChips(scrollX, scrollY, playerJump); /* Player interaction */ if (state == STATE_GAME || state == STATE_OVER) { movePlayer(); if (state == STATE_GAME) { gameFrames++; if (floorAry[floorIdxFirst].z < 0) { state = STATE_OVER; isHiscore = (setLastScore(score, gameFrames) == 0); counter = 480; // 8 secs arduboy.playScore2(soundOver, 1); dprint("Game Over: score="); dprintln(score); } else if (ignoreCnt == 0 && arduboy.buttonDown(A_BUTTON | B_BUTTON)) { state = STATE_PAUSE; dprintln("Pause"); } } else { counter--; if (ignoreCnt == 0 && arduboy.buttonDown(A_BUTTON | B_BUTTON)) { initLevel(true); } } } if (ignoreCnt > 0) ignoreCnt--; toDraw = true; return (state == STATE_OVER && counter == 0); }
void LevelOneScreen::onEntry(){ //Initialize SpriteFont _spriteFont.init("Fonts/shangri-la.ttf", 32); //Initialize spriteBatch _spriteBatch.init(); //Initialize the shader initShader(); //Initialize GUI initUI(); //Initialize audio engine _audioEngine.init(); loadMusic(); //Initialize Level initLevel(); _screenSize = glm::vec2(_window->getScreenWidth(), _window->getScreenHeight()); //initialize camera _camera.init(_window->getScreenWidth(), _window->getScreenHeight()); //For Debuging _camera.setScale(1.3); }
World::World(CL_DisplayWindow &display_window) : window(display_window), quit(false) { CL_Slot slot_quit = window.sig_window_close().connect(this, &World::on_window_close); gc = window.get_gc(); // Setup resources resources = CL_ResourceManager("resources.xml"); background = CL_Texture("background", &resources, gc); // Receive mouse clicks slotKeyDown = window.get_ic().get_keyboard().sig_key_down().connect(this, &World::onKeyDown); slotMouseDown = window.get_ic().get_mouse().sig_key_down().connect(this, &World::onMouseDown); slotMouseUp = window.get_ic().get_mouse().sig_key_up().connect(this, &World::onMouseUp); slotMouseMove = window.get_ic().get_mouse().sig_pointer_move().connect(this, &World::onMouseMove); dragging = mouseDown = false; // Add some tanks initLevel(); // Run the main loop run(); }
void Game::update(sf::Time deltaTime) { if(not Configuration::isGameOver()) { _world.update(deltaTime); if(Configuration::player == nullptr) { Configuration::player = new Player(_world); Configuration::player->setPosition(_world.getX()/2,_world.getY()/2); _world.add(Configuration::player); } _next_saucer -= deltaTime; if(_next_saucer < sf::Time::Zero) { Saucer::newSaucer(_world); _next_saucer = sf::seconds(book::random(5.f,60.f - Configuration::level*2)); } if(_world.size() <= 1) { ++Configuration::level; initLevel(); } } }
bool GravityJamRoot::nextLevel(void) { gj_level++; // we should check the level against a max, but I don't know how to determine that yet. // for now, we'll let that fail happen in Level::initLevel() return initLevel(gj_level); }
void MainGame::run() { initSystems(); initLevel(); gameLoop(); }
void Game::reset() { _next_saucer = sf::seconds(book::random(5.f,6.f - Configuration::level*2)); _world.clear(); Configuration::player = nullptr; Configuration::reset(); initLevel(); }
Game::Game() : running(true), currentStep(0), currentCutScene(CutScene::NONE), cutSceneFrame(0), god(false), currentLevel(Level::getNext()) { std::vector<std::string> resources; // add texture images resources.push_back(_RES_TEX_BRICK); resources.push_back(_RES_TEX_PRIZE); resources.push_back(_RES_TEX_CROSSHAIR); // add fonts resources.push_back(_RES_FONT); // add sound files resources.push_back(_RES_SFX_CLONG); // init engine std::shared_ptr<GameEngine> engine; try { engine = GameEngine::getInstance(); ResourceManager::loadResources(resources); dummy = MD3Object::load("res/upper.md3"); // TODO: remove after tests; dummy->setCenter(Point3f(-80, 0, 0)); dummy->rotate(-60.0f, -30.0f, 60.0f); } catch (EngineException & e) { std::cout << "Game::Game()" << e.what() << std::endl; // note that when EngineException is constructed it prints trace anyway throw -1; // but still nice to have what() } // engine ready, get subsystems gfx = engine->getGraphicsEngine(); sfx = engine->getAudioEngine(); eventSystem = engine->getEventEngine(); physics = engine->getPhysicsEngine(); camera = gfx->getCamera(); // adjust settings std::string title = "Tetris3D v" + std::to_string(_TETRIS_VERSION_MAJOR) + "." + std::to_string(_TETRIS_VERSION_MINOR) + " by " + _TETRIS_AUTHOR; gfx->setWindowTitle(title); gfx->setWindowSize(GAME_W, GAME_H); gfx->useFont(ResourceManager::getFont(_RES_FONT)); eventSystem->setMouseRelative(true); // trap mouse for FPS physics->setGravity(-1.0f, GAME_FPS_DELAY_SEC); // init world // atm we don't care where we place them, nextLevel() takes care of everything prize = std::make_shared<GameObject>(Point3f(0, 0, 0), 2.0f, ResourceManager::getTextureID(_RES_TEX_PRIZE)); player = std::make_shared<Player>(Point3f(0, 0, 0)); player->setSensitivity(0.15f); crosshair = std::make_shared<GameObject>(Point3f(0, 0, 1), 0.05f, SDL_COLOR_GREEN); camera->follow(player); dummyCameraObject = std::make_shared<GameObject>(Point3f(0, 0.0f, 0.0f), 2.0f, 0); bullet = std::make_shared<GameObject>(Point3f(0, 0, 0), 0.5f, 0); initLevel(); }
void Game::nextLevel() { if (MAX_LEVELS == currentLevel->number) { currentCutScene = CutScene::GAME_WIN; return; } currentLevel = Level::getNext(); initLevel(); }
void GameScene::on_menuGameStart() { menu->activate(false); gameProfile->setGameStarted(true); gameProfile->setGamePaused(false); gameProfile->currentPlayer()->currentLevelPackInfo()->init(); if (!initLevel(1)) exitToMainMenu(); }
/**Constructors*/ LevelObject::LevelObject() { LevelSettings s; s.width = MathsStuff::ceiling(800 / 32); s.height = MathsStuff::ceiling(600 / 32); lvlsettings = s; initLevel(); }
void GameScene::on_menuContinue() { if (gameProfile->currentPlayer()->currentLevelPackInfo()->level > max_level) return; menu->activate(false); gameProfile->setGameStarted(true); gameProfile->setGamePaused(false); if (!initLevel(gameProfile->currentPlayer()->currentLevelPackInfo()->level)) exitToMainMenu(); }
void MainGame::run() { initSystems(); initLevel(); Adina::Music music = m_audioEngine.loadMusic("Sound/XYZ.ogg"); music.play(-1); gameLoop(); }
//入口 void MainGame::run(){ initSystems(); initLevel(); NeroEngine::Music bgMusic = _audioEngine.loadMusic("Sound/background.mp3"); bgMusic.play(-1); gameLoop(); }
Level::Level() { room1_size = 32.0; room2_size = 16.0; room3_size = 64.0; room1_Origin = VECTOR3D(0.0, 0.0, 0.0); room2_Origin = VECTOR3D(-(room1_size/2.0+room2_size/2.0), 0.0, 0.0); room3_Origin = VECTOR3D((room1_size/2.0+room3_size/2.0), 0.0, 0.0); initLevel(); }
int main() { SetupCallbacks(); initLanguage(); initLevel(); initGame(); initDisp(); sceKernelSleepThread(); return 0; }
void GameScene::on_menuRestartLevel() { menu->hide(); if (dconfirm->exec(tr("Current level progress will be lost.\nAre you sure you want to restart?"))) { if (!initLevel(gameProfile->currentPlayer()->currentLevelPackInfo()->level)) exitToMainMenu(); on_menuPauseBack(); return; } menu->showNormal(); }
void initGame(void) { ignoreCnt = 0; playerX = 0; playerY = 0; playerJump = 0; playerTorque = 0; playerRotate = 196; pFloorBlur = NULL; isBlink = false; initLevel(true); initChips(); }
GameWidget::GameWidget(QWidget *parent) :QLabel(parent), m_gunX(32), m_shipXHeading(1), m_soser(250, 65) { srand(QDateTime::currentDateTime().toTime_t()); m_shipTimeInt = 200.0; m_shottimer = new QTimer(this); connect(m_shottimer, SIGNAL(timeout()), this, SLOT(shotTimeout())); m_shottimer->start(30); m_shiptimer = new QTimer(this); connect(m_shiptimer, SIGNAL(timeout()), this, SLOT(shipTimeout())); m_shiptimer->start((int)m_shipTimeInt); m_soserShowTimer = new QTimer(this); connect(m_soserShowTimer, SIGNAL(timeout()), this, SLOT(soserShowTimeout())); m_soserShowTimer->setSingleShot(false); int tm = (((rand() % 6) + 5) * 1000); m_soserShowTimer->start(tm); m_soserMoveTimer = new QTimer(this); connect(m_soserMoveTimer, SIGNAL(timeout()), this, SLOT(soserMoveTimeout())); m_levelFinTimer = new QTimer(this); connect(m_levelFinTimer, SIGNAL(timeout()), this, SLOT(levelFinTimeout())); setMouseTracking(true); // draw soser pixmap m_soser.fill(Qt::transparent); QPainter p(&m_soser); QPixmap a = PicBucket::instance().getPic(4, 0).pixmap; QPixmap b = PicBucket::instance().getPic(4, 3).pixmap; p.drawPixmap(0, 0, a); p.drawPixmap(51, 0, b.transformed(QMatrix().rotate(270), Qt::SmoothTransformation).transformed( QMatrix(QMatrix(1, 0, 0, -1, 0, 0)), Qt::SmoothTransformation)); // flip it, looks better p.drawPixmap(102, 0, b); p.drawPixmap(153, 0, a.transformed(QMatrix(-1, 0, 0, 1, 0, 0), Qt::SmoothTransformation)); p.end(); m_soser = m_soser.scaled(QSize(170, 43), Qt::KeepAspectRatio, Qt::SmoothTransformation); m_soserMask = QRegion(m_soser.mask()); m_score = 0; m_level = 1; m_lives = 3; m_soserX = 0; sizeY = 9999; loadScores(); initLevel(m_level); }
void newLevel() { u8 str[6]; initLevel(); sprintf(str, "%2u", level); cpct_memset(SCR_VMEM, 0, 0x4000); cpct_drawStringM0 ("LEVEL", getScreenPosition(7, 11), 15, 0); cpct_drawStringM0 (str, getScreenPosition(13, 11), 15, 0); cpct_drawStringM0 ("Press Space", getScreenPosition(4, 23), 15, 0); cpct_drawStringM0 ("to go next level", getScreenPosition(2, 24), 15, 0); cpct_scanKeyboard_f (); while (!cpct_isKeyPressed(Key_Space)) { cpct_scanKeyboard_f (); } levelMode(); }
void PlayState::init() { // Set up the shaders loadShaders(); // Initialize our sprite batch m_spriteBatch.init(); // Set up the camera m_camera.init(1024, 768); // Zoom out the camera by 2x const float CAMERA_SCALE = 1.0f; m_camera.setScale(CAMERA_SCALE); initLevel(); }
void GameWidget::die() { --m_lives; emit livesChanged(m_lives); if (m_lives == 0) { m_bInteract = false; m_shottimer->stop(); m_shiptimer->stop(); m_soserMoveTimer->stop(); m_soserShowTimer->stop(); m_shotspreg += QRegion(0, 0, sizeX, sizeY); // invalidate the whole screen update(); // invalidate all endGame(); } else { initLevel(m_level); } }
void GameWidget::levelFinTimeout() { if (!m_shots.isEmpty()) // wait for all the shots to clear return; if (m_bShowSoser) // wait for the soser to pass return; m_bInteract = false; m_bSoserEnabled = false; if (m_gunY > -65) { m_shotspreg += QRegion(m_gunX - 32, m_gunY - 10, 65, 65 + 10); m_gunY -= 10; return; } else { m_levelFinTimer->stop(); initLevel(++m_level); } }
static void newLevel() { fprintf(stderr, "creating new level: (%d, %d)\n", sgLevel.size.x, sgLevel.size.y); sgLevel.start.x = 0; sgLevel.start.y = 0; sgLevel.finish.x = sgLevel.size.x - 1; sgLevel.finish.y = sgLevel.size.y - 1; initLevel(); for (int x = 0; x < sgLevel.size.x; x++) { for (int y = 0; y < sgLevel.size.y; y++) { KdCell::Range& range = sgLevel.kdLevelTree->get(x, y); { Block b; b.x = x; b.y = y; b.z = 0; b.dzx = 0; b.dzy = 0; b.dirty = true; range.start = sgLevel.blocks.insert(b); } range.end = range.start + 1; } } initCommon(); updateLightMap(); }
static void initLevelsFromString( const char* string ) { struct { int r, c; } startLevel; // These helpers return appropriate level string/character const int STRING_ROW_SIZE = CELL_COUNT * LEVEL_XCOUNT; const int STRING_ROW_WIDTH = COLUMN_COUNT * LEVEL_XCOUNT; #define GET_LEVEL_STRING(string, r, c) ((string) + STRING_ROW_SIZE * (r) + COLUMN_COUNT * (c)) #define GET_LEVEL_CHAR(levelString, r, c) (levelString)[(r) * STRING_ROW_WIDTH + (c)] // Iterate over levels for (int lr = 0; lr < LEVEL_YCOUNT; ++ lr) { for (int lc = 0; lc < LEVEL_XCOUNT; ++ lc) { const char* levelString = GET_LEVEL_STRING(string, lr, lc); Level* level = &levels[lr][lc]; initLevel(level); level->r = lr; level->c = lc; // Iterate over cells within the level and create objects for (int r = 0; r < ROW_COUNT; ++ r) { for (int c = 0; c < COLUMN_COUNT; ++ c) { const char s = GET_LEVEL_CHAR(levelString, r, c); // Wall and ground if (s == '*' || s == 'x') { const int type = s == '*' ? TYPE_WALL : TYPE_GROUND; const int type_top = s == '*' ? TYPE_WALL_TOP : TYPE_GROUND_TOP; const char st = GET_LEVEL_CHAR(levelString, r - 1, c); if (r == 0 || st == '*' || st == 'x') { createObjectInMap(level, type, r, c); } else { createObjectInMap(level, type_top, r, c); } // Water } else if (s == '~') { const char st = GET_LEVEL_CHAR(levelString, r - 1, c); if (r == 0 || st == '~' || st == 'x' || st == '*') { createObjectInMap(level, TYPE_WATER, r, c); } else { createObject(level, TYPE_WATER_TOP, r, c); } // Pillar } else if (s == '|') { const char st = GET_LEVEL_CHAR(levelString, r - 1, c); const char sb = GET_LEVEL_CHAR(levelString, r + 1, c); if (r == 0 || st == '*' || st == 'x') { createObjectInMap(level, TYPE_PILLAR_TOP, r, c); } else if (r == ROW_COUNT - 1 || sb == '*' || sb == 'x') { createObjectInMap(level, TYPE_PILLAR_BOTTOM, r, c); } else { createObjectInMap(level, TYPE_PILLAR, r, c); } // Spike } else if (s == '^') { const char st = GET_LEVEL_CHAR(levelString, r - 1, c); if (st == '*' || st == 'x') { createObjectInMap(level, TYPE_SPIKE_TOP, r, c); } else { createObjectInMap(level, TYPE_SPIKE_BOTTOM, r, c); } // Other objects } else if (s == '-') { createObjectInMap(level, TYPE_WALL_STAIR, r, c); } else if (s == ',') { createObjectInMap(level, (c + 1) % 3 ? TYPE_GRASS : TYPE_GRASS_BIG, r, c); } else if (s == '.') { createObjectInMap(level, TYPE_MUSHROOM1 + c % 3, r, c); } else if (s == ';') { createObjectInMap(level, c % 2 ? TYPE_TREE1 : TYPE_TREE2, r, c); } else if (s == '@') { createObjectInMap(level, TYPE_ROCK, r, c); } else if (s == '=') { createObjectInMap(level, TYPE_LADDER, r, c); } else if (s == 'd') { createObjectInMap(level, TYPE_DOOR, r, c); } else if (s == 'o') { createObject(level, TYPE_COIN, r, c); } else if (s == 'O') { createObject(level, TYPE_GEM, r, c); } else if (s == 'k') { createObject(level, TYPE_KEY, r, c); } else if (s == 'h') { createObject(level, TYPE_HEART, r, c); } else if (s == 'a') { createObject(level, TYPE_APPLE, r, c); } else if (s == 'i') { createObject(level, TYPE_PEAR, r, c); } else if (s == 'S') { createObject(level, TYPE_STATUARY, r, c); } else if (s == 'g') { createObject(level, TYPE_GHOST, r, c); } else if (s == 's') { createObject(level, TYPE_SCORPION, r, c); } else if (s == 'p') { createObject(level, TYPE_SPIDER, r, c); } else if (s == 'r') { createObject(level, TYPE_RAT, r, c); } else if (s == 'b') { createObject(level, TYPE_BAT, r, c); } else if (s == 'q') { createObject(level, TYPE_BLOB, r, c); } else if (s == 'f') { createObject(level, TYPE_FIREBALL, r, c); } else if (s == 'e') { createObject(level, TYPE_SKELETON, r, c); } else if (s == '`') { createObject(level, TYPE_DROP, r, c); } else if (s == '_') { createObject(level, TYPE_PLATFORM, r, c); } else if (s == '/') { createObject(level, TYPE_SPRING, r, c); } else if (s == 'X') { createObject(level, TYPE_FAN, r, c); } else if (s == '<') { createObjectInMap(level, TYPE_ARROW_LEFT, r, c); } else if (s == '>') { createObjectInMap(level, TYPE_ARROW_RIGHT, r, c); } else if (s == '&') { createObject(level, TYPE_CLOUD1, r, c); } else if (s == '!') { createObject(level, TYPE_TORCH, r, c); } else if (s >= '1' && s <= '9') { Object* action = createObject(level, TYPE_ACTION, r, c); action->state = s; } else if (s == 'P') { startLevel.r = lr; startLevel.c = lc; player.y = CELL_SIZE * r; player.x = CELL_SIZE * c; } } } ObjectArray_sortByDepth(&level->objects); } } #undef GET_LEVEL_CHAR #undef GET_LEVEL_STRING // Set start level setLevel(startLevel.r, startLevel.c); }
PlayState::PlayState(GSM& gsmn/*, level to load*/) : State(gsmn) { initLevel(); }
int main(int argc, char **argv) { unsigned int frameLimit = SDL_GetTicks() + MIN_TICK_DELAY; int i, active_colors; char *filename = (char *)malloc(100); char *graph_title = (char *)malloc(100); char temp[100]; int step = 0; int max_no_of_dots = 0, winner_no_of_dots; unsigned int seconds_of_gameplay = 0; FILE *game_scores; char **gnuplot_commands; FILE *gnuplotPipe; init_level_names(); if(argc < 2) { give_user_info(); return 0; } sprintf(graph_title, "Game Results: "); filename = get_timestamp(); strcat(filename, "Auralux.dat"); game_scores = fopen(filename, "w"); if(!game_scores) { perror("game_scores pointer"); } /* Start up SDL */ init("Auralux 1"); /* Call the cleanup function when the program exits */ atexit(cleanup); clearInput(); initLevel(argv[1]); while (1) { active_colors = 0; for(i = 0; i < NO_OF_COLORS / 2; i++) { if(active_sun_colors[i]) { active_colors++; } } if(active_colors == 1 || !active_sun_colors[BLUE / 2]) { break; } /* Get the input */ getInput(); /* Update player and entities */ doEntities(step); doPlayer(); /* CPU opponents decide strategy */ if(step % (1000 / MIN_TICK_DELAY) == 0) { cpuThink(); /* add data to game scores */ fprintf(game_scores, "%d\t", seconds_of_gameplay++); for(i = 0; i < NO_OF_COLORS / 2; i++) { fprintf(game_scores, "%d\t", no_of_dots[i]); if(no_of_dots[i] > max_no_of_dots) { max_no_of_dots = no_of_dots[i]; } } fprintf(game_scores, "\n"); } /* Draw everything */ draw(); /* Sleep briefly to stop sucking up all the CPU time */ delay(frameLimit); frameLimit = SDL_GetTicks() + MIN_TICK_DELAY; step--; } fclose(game_scores); game_scores = fopen(filename, "r"); if(!game_scores) { perror("game_scores pointer"); } fscanf(game_scores, "%d", &step); /* time column value skipped */ if(active_sun_colors[BLUE / 2]) { strcat(graph_title, "You won!"); } else { strcat(graph_title, "You lost!"); } /* gnuplot commands begin here */ gnuplot_commands = (char **)malloc(10 * sizeof(char *)); for(i = 0; i < 10; i++) { /* assuming that 10 gnuplot commands are required */ gnuplot_commands[i] = (char *)malloc(1000); } /* set title of the graph */ strcpy(gnuplot_commands[0], "set title font \", 20\" \""); strcat(gnuplot_commands[0], graph_title); strcat(gnuplot_commands[0], "\""); /* set xrange*/ strcpy(gnuplot_commands[1], "set xrange[0:"); sprintf(temp, "%d", seconds_of_gameplay); strcat(gnuplot_commands[1], temp); strcat(gnuplot_commands[1], "]"); /* set yrange */ strcpy(gnuplot_commands[2], "set yrange[0:"); sprintf(temp, "%d", (int)(1.3 * max_no_of_dots)); /* extra space at the top of the graph */ strcat(gnuplot_commands[2], temp); strcat(gnuplot_commands[2], "]"); /* set xlabel */ strcpy(gnuplot_commands[3], "set xlabel 'time (in seconds)'"); /* set ylabel */ strcpy(gnuplot_commands[4], "set ylabel 'dot population'"); /* set line styles */ strcpy(gnuplot_commands[5], "set style line 1 lt 1 lw 2 pt 3 lc rgb \"blue\""); strcpy(gnuplot_commands[6], "set style line 2 lt 1 lw 2 pt 3 lc rgb \"orange\""); strcpy(gnuplot_commands[7], "set style line 3 lt 1 lw 2 pt 3 lc rgb \"green\""); strcpy(gnuplot_commands[8], "set style line 4 lt 1 lw 2 pt 3 lc rgb \"purple\""); /* decide which colors to plot on graph */ strcpy(gnuplot_commands[9], "plot "); for(i = 0; i < NO_OF_COLORS / 2; i++) { fscanf(game_scores, "%d", &winner_no_of_dots); /* time column value skipped */ if(!winner_no_of_dots) { continue; } strcat(gnuplot_commands[9], "'"); strcat(gnuplot_commands[9], filename); strcat(gnuplot_commands[9], "'"); strcat(gnuplot_commands[9], " using 1:"); sprintf(temp, "%d ", 2 + i); /* dot counts are from column 2 onwards */ strcat(gnuplot_commands[9], temp); strcat(gnuplot_commands[9], "title \""); switch(i * 2 + 1) { case BLUE: strcpy(temp, "You"); break; case ORANGE: strcpy(temp, "CPU1"); break; case GREEN: strcpy(temp, "CPU2"); break; case PURPLE: strcpy(temp, "CPU3"); break; } strcat(gnuplot_commands[9], temp); strcat(gnuplot_commands[9], "\" "); strcat(gnuplot_commands[9], "smooth cspline "); strcat(gnuplot_commands[9], "w l ls "); sprintf(temp, "%d, ", 1 + i); /* line styles are from 1 onwards */ strcat(gnuplot_commands[9], temp); } gnuplotPipe = popen("gnuplot -persistent", "w"); if(!gnuplotPipe) { perror("gnuplotPipe pointer"); } for (i = 0; i < 10; i++) { printf("%s\n", gnuplot_commands[i]); fprintf(gnuplotPipe, "%s\n", gnuplot_commands[i]); /* send commands to gnuplot one by one */ } /* Exit the program */ exit(0); }
LevelObject::LevelObject(LevelSettings __settings) { lvlsettings = __settings; initLevel(); }
bool loadLevelFromFile(const char* filename) { FILE* file = fopen(filename, "rt"); unsigned int version; unsigned int crc32; sgLevel.filename = filename; if (!file) { if (between(sgLevel.size.x, 1, MAX_LEVEL_SIZE) && between(sgLevel.size.y, 1, MAX_LEVEL_SIZE)) { newLevel(); return true; } else { fprintf(stderr, "can not open file: %s\n", filename); return false; } } /* version number */ if (fscanf(file, "v%u", &version) != 1 || version > THIS_CGM_VERSION) { fprintf(stderr, "incompatible version number: %u\n", version); fclose(file); return false; } resetCRC32(); /* read attributes */ readFieldCoord(file, sgLevel.start); readFieldCoord(file, sgLevel.finish); readFieldCoord(file, sgLevel.size); if (version >= 4) { readString(file, sgLevel.author); } initLevel(); /* reading data */ if (version >= 4) { int countBlocks = readInt(file); for (int i = 0; i < countBlocks; ++i) { KdCell::Range range; int x; int y; { Block b; readFieldBlock(file, b); b.dirty = true; x = b.x; y = b.y; range.start = sgLevel.blocks.insert(b); } range.end = range.start + 1; sgLevel.kdLevelTree->get(x, y) = range; } } else { for (int x = 0; x < sgLevel.size.x; x++) { for (int y = 0; y < sgLevel.size.y; y++) { KdCell::Range& range = sgLevel.kdLevelTree->get(x, y); { Block b; b.x = x; b.y = y; readFieldBlockV3(file, b); b.dirty = true; range.start = sgLevel.blocks.insert(b); } range.end = range.start + 1; } } } sgLevel.crc32 = getCRC32(); initCommon(); if (version >= 2) { if (fscanf(file, "%x\n", &crc32) != 1 || crc32 != getCRC32()) { fprintf(stderr, "1st checksum mismatch: %s\n", filename); fclose(file); return false; } { int cntSubLightMaps = sgAtlas->getCntAllocatedSubLightMaps(); int index = 0; if (version >= 3) { while (index < cntSubLightMaps) { int dataInt[SIZEOF_LIGHT_MAP]; readRLE(file, dataInt); toLightMap(index, false, dataInt); index++; } } else { importLightmapV2(file); } if (fscanf(file, "%x\n", &crc32) != 1 || crc32 != getCRC32()) { fprintf(stderr, "2st checksum mismatch: %s\n", filename); fclose(file); return false; } } } else { updateLightMap(); } fclose(file); if (!loadHighscoreFromFile()) { sgLevel.cntScoreCols = 0; } sgLevel.saved = true; return true; }
int main() { sdcard_Init(); initVGA(); initAnonProfile(); brickmap = malloc(sizeof(BrickMap)); currentLevel->paddle = malloc(sizeof(Paddle)); currentLevel->buff=malloc(sizeof(Buff)); int i,j; for(i=0;i<maxBalls;i++) currentLevel->ball[i] = malloc(sizeof(Ball)); for(i=0;i<maxRows;i++) for(j=0;j<bricksPerRow;j++) currentLevel->bricks[i][j]=malloc(sizeof(Brick)); level=1; //pre load the root menu getMenu(¤tMenu,rootMenu, 1); //allocate memory for level farm //set the game to playing prevState=currentState=Playing; //look up the level from level farm and load it into currentLevel levelLookUp(brickmap,level); initLevel(*brickmap); drawStart(currentLevel); //this is optional here swapBuffers(); drawStart(currentLevel); runCountDown(); //count down from three initInterrupt(); //start the game (we dont need to right off the bat (probably shouldnt) int counter=0; //so were not doing direct IO reads on EVERY iteration (we could timer this buttttt no) while(1) { //input to state machine counter++; if(counter>22000) { counter=0; if(getMenuPB()) { while(getMenuPB() != 0); if(currentState == Playing) changeState(MenuShow); } } //flicker changes if(prevState != currentState) { if(currentState == Playing) { clearScreen(); drawStart(currentLevel); //this is optional here swapBuffers(); drawStart(currentLevel); runCountDown(); initInterrupt(); }else { stopInterrupt(); getMenu(¤tMenu,rootMenu, 1); clearScreen(); drawStart(currentLevel); //this is optional here swapBuffers(); drawStart(currentLevel); drawMenu(currentMenu); } prevState = currentState; } //state machine if(currentState == MenuShow) { menuLoop(); }else //while were playing we will have to check for other things (all balls gone etc.) { if(currentLevel->brickCount<=0) { printf("starting new level \n"); stopInterrupt(); level++; levelLookUp(brickmap,level); initLevel(*brickmap); prevState= currentState - 1; currentState = Playing; printf("finished starting new level \n"); } } } return 0; }