int main(int argc, char * argv[]) { int i, j, m, n, wall_cost, num_bumper, x, y, value, cost, direction, lifetime, sum = 0; if (DEBUG) printf("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"); scanf("%d %d\n", &m, &n); struct Obstacle * surface[51][51]; scanf("%d\n", &wall_cost); /** * initiate surface */ for (i = 1; i <= m; i++) { for (j = 1; j <= n; j++) { if (i == 1 || i == m || j == 1 || j == n) { surface[i][j] = newObstacle(0, wall_cost); } else { surface[i][j] = NULL; } } } scanf("%d\n", &num_bumper); for (i = 0; i < num_bumper; i++) { scanf("%d %d %d %d\n", &x, &y, &value, &cost); surface[x][y] = newObstacle(value, cost); } while (scanf("%d %d %d %d\n", &x, &y, &direction, &lifetime) != EOF) { struct Ball *ball = newBall(x, y, direction, lifetime); int points = runBall(surface, m, n, ball); printf("%d\n", points); sum += points; } printf("%d\n", sum); return 0; }
Command Obstacle::getNewCommand() const { Command newObstacle("NewObstacle"); newObstacle.add(id); newObstacle.add(position.x); newObstacle.add(position.y); newObstacle.add(position.z); newObstacle.add(radius); return newObstacle; }
// doMove() is called from QTimer void Tron::doMove() { if (Settings::gameType() == Settings::EnumGameType::Snake) { players[0]->movePlayer(); modMoves++; if (modMoves == 20) { modMoves = 0; newObstacle(); } updatePixmap(); update(); if (!players[0]->isAlive()) { stopGame(); showWinner(); } } else { if (players[0]->isAccelerated() || players[1]->isAccelerated()) { movementHelper(true); } if (!gameEnded) { // Player 0 is never a computer nowadays... if (players[1]->isComputer()) { intelligence.think(1); } movementHelper(false); } } if (gameEnded) { //this is for waiting 1s before starting next game gameBlocked = true; QTimer::singleShot(1000, this, SLOT(unblockGame())); } }
Obstacle::Obstacle(QCanvas* canvas, int y) : QCanvasSprite(0,canvas) { newObstacle(y); }
/*notice the default arguments for main. SDL expects main to look like that, so don't change it*/ int main(int argc, char *argv[]) { // SDL_Surface *temp = NULL; int done;// the player const Uint8 *keys;// the player /* This section starts by loading the BG as a surface and converting it to a texture This will have to change if I can manage to scroll the trexture arond the player*/ SDL_CreateWindowAndRenderer(800, 600, SDL_WINDOW_RESIZABLE, &mainWindow, &renderer); SDL_SetWindowTitle(mainWindow, "Nitro Hotness"); if( TTF_Init() == -1 ) { return false; } if( Mix_OpenAudio( 22050, MIX_DEFAULT_FORMAT, 2, 4096 ) == -1 ) { return false; } InitSpriteSystem(); InitEntitySystem(entityMax); map mymap = setWorld(); ObstacleList ol = newObstacleList(); mew = newPlayer(); Obstacle Doh = newObstacle(0); Road_M Path = initRoad(); AI rival = new_AI(); GUI HUD = InitGUI(); mew.position=0; done = 0; //The music that will be played Mix_Music *music = NULL; Mix_Chunk *buzz = NULL; buzz = Mix_LoadWAV( "sfx/buzz.wav" ); readSave(&mew); showTitle(); showMain(); oldTime = 0; currentTime = 0; mytime = 0; do { oldTime = 0; currentTime = 0; mytime = 0; if( Mix_PlayingMusic() == 0 ) { //Play the music if( Mix_PlayMusic( level_music, -1 ) == -1 ) { return 1; } } SDL_Event e; SDL_PollEvent( &e ); if(&e) { //User requests quit if( e.type == SDL_QUIT ) { done = 1; } //user presses enter to go to next menu //User presses a key else if( e.type == SDL_KEYDOWN ) { //Select surfaces based on key press switch( e.key.keysym.sym ) { case SDLK_LEFT: // slog("left is down"); mew.playerX += 3; mew.accel = (mew.accel - .000001); break; case SDLK_RIGHT: // slog("right is down"); mew.playerX -= 3; mew.accel = (mew.accel - .000001); break; case SDLK_UP: // slog("up is down"); mew.accel = (mew.accel + .00007); Mix_PlayChannel( 1, buzz, 0 ); break; case SDLK_DOWN: // slog("down is down"); mew.accel = (mew.accel - .00008); break; } } else if( e.type == SDL_KEYUP ) { //Select surfaces based on key press switch( e.key.keysym.sym ) { case SDLK_RETURN : if(mew.done ==1) { Mix_HaltMusic(); if(GP == 1) { mew.done=0; lvl++; //slog("new level is %i",lvl); mew.position = 0; rival.position =0; setWorld(); Results(mew.rank,lvl); } else if (GP == 0) { mew.done=0; mew.position = 0; rival.position =0; levelSelect(); } } else { slog("too soon"); } case SDLK_LEFT: // slog("left is up"); e.type = SDLK_CLEAR; break; case SDLK_RIGHT: // slog("right is up"); e.type = SDLK_CLEAR; break; case SDLK_UP: // slog("up is up"); mew.accel = (mew.accel - .001); Mix_HaltChannel(1); e.type = SDLK_CLEAR; break; case SDLK_DOWN: // slog("down is up"); mew.accel = 0; e.type = SDLK_CLEAR; break; default: //slog("simple decel"); mew.accel = (mew.accel-0.00001); break; } } if(mew.position > rival.position) { mew.rank = 1 ; } else if( rival.position > mew.position ) { mew.rank = 2 ; } SDL_RenderClear(renderer); DrawBG(BG1,BG2); roadUpdate(Path,mymap,mew); roadDraw(Path,mymap,&mew); roadFetch(Path,mymap,&mew); checkForObstacles(ol , &mew, Doh); update_AI(&rival, &mew); UpdatePlayer(&mew); DrawGui(HUD,mew); NextFrame(); keys = SDL_GetKeyboardState(NULL); if(keys[SDL_SCANCODE_ESCAPE]) { done = 1; } } }while(!done); //Free the sound effects //Free the music Mix_FreeMusic( music ); CloseEntitySystem(); CloseSpriteSystem(); exit(0); /*technically this will end the program, but the compiler likes all functions that can return a value TO return a value*/ return 0; }