void bullet_flying() { bullet.time++; bullet.x += bullet.xspeed; bullet.yspeed = bullet.strenth * sin(bullet.angle) - GRAV * bullet.time; bullet.y += bullet.yspeed; if (!map[bullet.x][bullet.y]) { shooting = 0; exploding = 1; bullet_explode(); } else { draw_bullet(); } }
void init_video(void) { char * datas = ((char*) PROGRAM_BASE_ADDR); datas += 100000; datas -= 512; assets = (Game_Assets*)datas; //color_screen(0x3f); // write_string_position(5, "wowowow", 5, 5); // write_string_position(5, hu, 5, 15); // write_string_position(5, katana, 5, 25); draw_bullet(6, 11, 15, 5); draw_player(15, 35); draw_enemy(0, 15, 55); draw_enemy(1, 15, 70); /* TODO: Do any video display initialization you might want to do, such * as clearing the screen, initializing static variable state, etc. */ // Clear Screen - not yet debugged. // clearScreen(); #if 0 //TEST~nico~~ #if 0 write_string_offset(RED, string, 10); #endif // TEST 2~~nico~~~~ color_pixel(RED, 50); color_pixel(BLUE, 52); color_pixel(YELLOW, 54); color_pixel(WHITE, 210); color_pixel(GREEN, 212); color_pixel(CYAN, 214); #endif }
int main(int argc, char const *argv[]) { const int FPS = 60; const int MAX_BULLETS = 10; const int MAX_ASTEROIDS = 10; const int MAX_EXPLOSIONS = 10; srand(time(NULL)); int done = 0; int redraw = 1; if(!al_init()) { al_show_native_message_box(NULL, "Error", "Error", "Could not initialize Allegro 5.", 0, ALLEGRO_MESSAGEBOX_ERROR); return -1; } ALLEGRO_DISPLAY *display = al_create_display(screen_width, screen_height); if(!display) { al_show_native_message_box(NULL, "Error", "Error", "Could not create display.", 0, ALLEGRO_MESSAGEBOX_ERROR); return -1; } ALLEGRO_EVENT_QUEUE *event_queue = al_create_event_queue(); if(!event_queue) { al_show_native_message_box(display, "Error", "Error", "Could not create event queue.", 0, ALLEGRO_MESSAGEBOX_ERROR); return -1; } ALLEGRO_TIMER *timer = al_create_timer(1.0/FPS); if(!timer) { al_show_native_message_box(display, "Error", "Error", "Could not create timer.", 0, ALLEGRO_MESSAGEBOX_ERROR); return -1; } if(!al_install_keyboard()) { al_show_native_message_box(display, "Error", "Error", "Could not install keyboard.", 0, ALLEGRO_MESSAGEBOX_ERROR); return -1; } if(!al_install_mouse()) { al_show_native_message_box(display, "Error", "Error", "Could not install mouse.", 0, ALLEGRO_MESSAGEBOX_ERROR); return -1; } if(!al_init_image_addon()) { al_show_native_message_box(display, "Error", "Error", "Could not initialize image addon.", 0, ALLEGRO_MESSAGEBOX_ERROR); return -1; } if(!al_init_primitives_addon()) { al_show_native_message_box(display, "Error", "Error", "Could not initialize primitives addon.", 0, ALLEGRO_MESSAGEBOX_ERROR); } al_init_font_addon(); // for whatever reason this function is void returning if(!al_init_ttf_addon()) { al_show_native_message_box(display, "Error", "Error", "Could not initialize ttf addon.", 0, ALLEGRO_MESSAGEBOX_ERROR); } al_hide_mouse_cursor(display); al_register_event_source(event_queue, al_get_mouse_event_source()); al_register_event_source(event_queue, al_get_keyboard_event_source()); al_register_event_source(event_queue, al_get_display_event_source(display)); al_register_event_source(event_queue, al_get_timer_event_source(timer)); ALLEGRO_FONT *font18 = al_load_font("Arial.ttf", 18, 0); int prev_x = screen_width, prev_y = screen_height; int fps_counter = 0; int fps_counter2 = 0; int i, j, k; struct spaceship ship; init_ship(&ship); struct bullet bullets[MAX_BULLETS]; for(i = 0; i < MAX_BULLETS; i++) { init_bullet(&bullets[i]); } struct asteroid asteroids[MAX_ASTEROIDS]; for(i = 0; i < MAX_ASTEROIDS; i++) { init_asteroid(&asteroids[i]); } struct explosion explosions[MAX_EXPLOSIONS]; for(i = 0; i < MAX_EXPLOSIONS; i++) { init_explosion(&explosions[i]); } al_start_timer(timer); while(!done) { ALLEGRO_EVENT event; al_wait_for_event(event_queue, &event); if(event.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { done = 1; } if(event.type == ALLEGRO_EVENT_KEY_DOWN) { switch(event.keyboard.keycode) { case ALLEGRO_KEY_Q: done = 1; break; case ALLEGRO_KEY_ESCAPE: done = 1; break; } } if(event.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN) { if(event.mouse.button & 1) { for(i = 0; i < MAX_BULLETS; i++) { if(!bullets[i].live) { fire_bullet(&bullets[i], ship); break; } } } } if(event.type == ALLEGRO_EVENT_MOUSE_AXES || event.type == ALLEGRO_EVENT_MOUSE_ENTER_DISPLAY) { set_ship_coordinates(&ship, event.mouse.x, event.mouse.y); } if(event.type == ALLEGRO_EVENT_TIMER) { if(ship.x > prev_x) { ship.sprite.dir_horizontal = RIGHT; } else if(ship.x == prev_x) { ship.sprite.dir_horizontal = CENTER; } else if(ship.x < prev_x) { ship.sprite.dir_horizontal = LEFT; } if(ship.y > prev_y) { ship.sprite.dir_vertical = BACK; } else if(ship.y == prev_y) { ship.sprite.dir_vertical = NEUTRAL; } else if(ship.y < prev_y) { ship.sprite.dir_vertical = FORWARD; } if(++fps_counter >= FPS / 5) { fps_counter = 0; prev_x = ship.x; prev_y = ship.y; } if(++fps_counter2 >= 2 * FPS) { for(i = 0; i < MAX_ASTEROIDS; i++) { if(!asteroids[i].live) { start_asteroid(&asteroids[i]); break; } } fps_counter2 = 0; } for(i = 0; i < MAX_BULLETS; i++) { if(bullets[i].live) { update_bullet(&bullets[i]); } } for(i = 0; i < MAX_ASTEROIDS; i++) { if(asteroids[i].live) { update_asteroid(&asteroids[i], &ship); } } for(i = 0; i < MAX_EXPLOSIONS; i++) { if(explosions[i].live) { update_explosion(&explosions[i]); } } update_ship_boundaries(&ship); for(i = 0; i < MAX_BULLETS; i++) { if(bullets[i].live) { for(j = 0; j < MAX_ASTEROIDS; j++) { if(asteroids[j].live) { if(bullet_and_asteroid_collision(bullets[i], asteroids[j])) { bullets[i].live = 0; asteroids[j].live = 0; ship.score += 20; for(k = 0; k < MAX_EXPLOSIONS; k++) { if(!explosions[k].live) { start_explosion(&explosions[k], bullets[i].x, bullets[i].y); break; } } } } } } } for(i = 0; i < MAX_ASTEROIDS; i++) { if(asteroids[i].live) { if(ship_and_asteroid_collision(ship, asteroids[i])) { asteroids[i].live = 0; for(k = 0; k < MAX_EXPLOSIONS; k++) { if(!explosions[k].live) { start_explosion(&explosions[k], ship.x, ship.y); break; } } ship.lives--; } } } if(!ship.lives) { done = true; } redraw = 1; } if(redraw) { redraw = 0; draw_ship_sprite(ship.sprite, ship.x, ship.y); for(i = 0; i < MAX_BULLETS; i++) { if(bullets[i].live) { draw_bullet(bullets[i]); } } for(i = 0; i < MAX_ASTEROIDS; i++) { if(asteroids[i].live) { draw_asteroid(asteroids[i]); } } for(i = 0; i < MAX_EXPLOSIONS; i++) { if(explosions[i].live) { draw_explosion(explosions[i]); } } al_draw_textf(font18, al_map_rgb(255, 255, 255), 50, 5, 0, "Score: %d ", ship.score); // I have no idea why it doesn't print the S... al_draw_textf(font18, al_map_rgb(255, 255, 255), 50, 25, 0, "Lives: %d", ship.lives); al_flip_display(); al_clear_to_color(al_map_rgb(0, 0, 0)); } } for(i = 0; i < MAX_ASTEROIDS; i++) { destroy_asteroid(&asteroids[i]); } for(i = 0; i < MAX_EXPLOSIONS; i++) { destroy_explosion(&explosions[i]); } destroy_sprite(&ship.sprite); al_destroy_display(display); al_destroy_event_queue(event_queue); al_destroy_timer(timer); al_destroy_font(font18); return 0; }
void render_shot(struct shot *shot, int s_id) { struct player *shoot_pl = dyn_arr_get(&Players, s_id); center_camera(shoot_pl->pos); clear(); render_map(); render_tanks(); debug_d(1, "RenderShotX", shoot_pl->pos.x); debug_d(1, "RenderShotY", shoot_pl->pos.y); debug_d(1, "RenderShot Angle", shot->angle); debug_d(1, "RenderShot Power", shot->power); int input_ch; struct f_pair init_v = initial_v(shot); struct f_pair acc = acceleration(); /* position (x,y) must be either double or float */ struct f_pair init_pos = map_pos_to_float(shoot_pl->pos); timeout(SHOOT_TIMEOUT); float t=1; /* this part is duplicated, because it's initial */ struct f_pair b_pos = shot_pos(init_pos, init_v, acc, t); struct map_position map_pos = round_to_map_pos(b_pos); draw_bullet(dx, dy, map_pos.x, map_pos.y); refresh(); /* end */ input_ch = getch(); if (input_ch != ERR) quit_key(input_ch); while (loc_player->state) { /* remove drew bullet */ draw_blank_bullet(dx, dy, map_pos.x, map_pos.y); debug_d(1, "BulletX", map_pos.x); debug_d(1, "BulletY", map_pos.y); t+=(float)SHOOT_TIMEOUT/100; b_pos = shot_pos(init_pos, init_v, acc, t); map_pos = round_to_map_pos(b_pos); /* draw a new one */ switch (draw_bullet(dx, dy, map_pos.x, map_pos.y)) { case SCR_OK: break; case SCR_UP: case SCR_DOWN: case SCR_LEFT: case SCR_RIGHT: center_camera(map_pos); clear(); render_map(); render_tanks(); draw_bullet(dx, dy, map_pos.x, map_pos.y); break; default: debug_s(5, "ScreenMove(shot)", "Wrong ScrMove value"); } refresh(); if (map_pos.x > map_data->length || map_pos.x < 0) break; if (t > g_impact_t) { b_pos = shot_pos(init_pos, init_v, acc, g_impact_t); map_pos = round_to_map_pos(b_pos); center_camera(map_pos); clear(); render_map(); render_tanks(); draw_bullet_explosion(dx, dy, map_pos.x, map_pos.y); refresh(); break; } /* let player see the change */ input_ch = getch(); if (input_ch != ERR) quit_key(input_ch); } input_ch = getch(); // let players input_ch = getch(); // see the explosion struct player *c_player = dyn_arr_get(&Players, camera_focus); center_camera(c_player->pos); /* SCR_ALL is already in screen update queue by center_camera*/ timeout(DEFAULT_TIMEOUT); //back to original }
int main(void) { bool done =false; bool redraw = true; ALLEGRO_DISPLAY *display = NULL; ALLEGRO_TIMER *timer =NULL; ALLEGRO_EVENT_QUEUE *event_queue = NULL; SpaceShip ship; Bullet bullet[num_bullets]; Commet commet[num_commets]; if(!al_init()) { fprintf(stderr,"allegro is not intialized"); return -1; } display = al_create_display(SCREEN_W,SCREEN_H); if(!display) { fprintf(stderr,"failed to intialize the display"); return -1; } timer = al_create_timer(1.0/FPS); if(!timer) { fprintf(stderr,"failed to intialize timer"); al_destroy_display(display); return -1; } event_queue = al_create_event_queue(); if(!event_queue) { fprintf(stderr,"failed to create event queue"); al_destroy_display(display); al_destroy_timer(timer); return -1; } al_install_keyboard(); al_register_event_source(event_queue,al_get_timer_event_source(timer)); al_register_event_source(event_queue,al_get_keyboard_event_source()); al_register_event_source(event_queue,al_get_display_event_source(display)); init_ship(&ship); init_bullet(&bullet); init_commet(&commet); al_start_timer(timer); while(!done) { ALLEGRO_EVENT ev; al_wait_for_event(event_queue,&ev); if(ev.type == ALLEGRO_EVENT_TIMER) { if(keys[KEY_UP]) { move_ship_up(&ship); } if(keys[KEY_DOWN]) { move_ship_down(&ship); }if(keys[KEY_LEFT]) { move_ship_left(&ship); } if(keys[KEY_RIGHT]) { move_ship_right(&ship); } if(keys[KEY_SPACEBAR]) { fire_bullet(&bullet,&ship); } if(!GameOver) { update_bullet(&bullet); update_commet(&commet); bullet_collision(&bullet,&commet); } redraw = true; } else if(ev.type==ALLEGRO_EVENT_DISPLAY_CLOSE) { done = true; } else if(ev.type == ALLEGRO_EVENT_KEY_DOWN) { switch(ev.keyboard.keycode) { case ALLEGRO_KEY_UP: { keys[KEY_UP]=true; break; } case ALLEGRO_KEY_DOWN: { keys[KEY_DOWN]=true; break; } case ALLEGRO_KEY_LEFT: { keys[KEY_LEFT]=true; break; } case ALLEGRO_KEY_RIGHT : { keys[KEY_RIGHT]=true; break; } case ALLEGRO_KEY_SPACE: { keys[KEY_SPACEBAR] = true; break; } } } else if(ev.type == ALLEGRO_EVENT_KEY_UP) { switch(ev.keyboard.keycode) { case ALLEGRO_KEY_UP: { keys[KEY_UP]=false; break; } case ALLEGRO_KEY_DOWN: { keys[KEY_DOWN]=false; break; } case ALLEGRO_KEY_LEFT: { keys[KEY_LEFT]=false; break; } case ALLEGRO_KEY_RIGHT : { keys[KEY_RIGHT]=false; break; } case ALLEGRO_KEY_SPACE: { keys[KEY_SPACEBAR]=false; break; } } } if(redraw && al_event_queue_is_empty(event_queue)) { redraw = false ; al_clear_to_color(al_map_rgb(255,100,100)); draw_ship(&ship); draw_bullet(bullet); draw_commet(commet); al_flip_display(); al_clear_to_color(al_map_rgb(255,100,100)); } } al_destroy_display(display); al_destroy_timer(timer); al_destroy_event_queue(event_queue); return 0; }
int main(int argc, char *argv[]) { //Network vars int udpSd, tcpSd; char buffer[5]; int myId; //SDL vars SDL_Event event; //Screen SDL_Surface* screen = NULL; //Tanks SDL_Surface* blueTank = NULL; SDL_Surface* blueCannon = NULL; SDL_Surface* redTank = NULL; SDL_Surface* redCannon = NULL; //Bullet SDL_Surface* bullet = NULL; //WorldMap SDL_Surface* worldMap = NULL; //rotation Images //SDL_Surface* rotatedTank[6] = {NULL,NULL,NULL,NULL,NULL,NULL}; //SDL_Surface* rotatedCannon[6] = {NULL,NULL,NULL,NULL,NULL,NULL}; SDL_Surface* rotatedBullet[6] = {NULL,NULL,NULL,NULL,NULL,NULL}; //SDL_Rect Tankoffset[6] = {400,300,0,0}; //SDL_Rect Cannonoffset[6] = {400,300,0,0}; //UserInterface vars SDL_Surface* UIhealth; SDL_Surface* UIreload; SDL_Surface* UIredPoints; SDL_Surface* UIbluePoints; TTF_Font *font = NULL; TTF_Font *reloadFont = NULL; SDL_Color textColor = { 255, 255, 255 }; char textBuffer[32]; char reload[32] = "FIRE: "; //Thread vars pthread_t reciveUdpData; //Game vars int run; struct playerInfo player[6]; struct timerInfo fps; struct cameraInfo camera; int bulletAngle[6]; //int oldCannonAngle[6]; //int oldTankAngle[6]; //Other vars int i; //Inits the player struct for (i = 0; i < MAX_PLAYERS; i++) { player[i].slot = -1; player[i].connected = 0; } //inits Sdl and opens the screen screen = init_sdl(); if(screen == 0) { printf("Error initializing SDL\n"); return 0; } //Makes the connection to the server if(!(init_udp_tcp(&udpSd, &tcpSd, argv[1], argv[2]))) { printf("Error making connection\n"); return 0; } //load the images (Function maybe) blueTank = load_image( "./images/blueTank.bmp" ); blueCannon = load_image( "./images/blueCannon.bmp" ); redTank = load_image( "./images/redTank.bmp" ); redCannon = load_image( "./images/redCannon.bmp" ); worldMap = load_image( "./images/worldMap.bmp" ); bullet = load_image( "./images/bullet.bmp" ); //Load the fonts font = TTF_OpenFont( "./fonts/Army.ttf", 24 ); reloadFont = TTF_OpenFont( "./fonts/Armyfat.ttf", 24 ); //Moves udp info to global var udpInfo.udpSd = udpSd; strcpy(udpInfo.serverIp, argv[1]); //Recives the first information from the server recv(tcpSd, buffer, sizeof(buffer), 0); myId = atoi(buffer); //Starts the Recive data thread pthread_create( &reciveUdpData, NULL, recive_udp_data, &(player)); while (run) { //Start the timer timer_start(&fps); while( SDL_PollEvent( &event ) ) { if( event.type == SDL_QUIT || event.key.keysym.sym == SDLK_ESCAPE) { run = FALSE; } handel_input(&event, tcpSd ); } camera.xCord = -player[myId].xCord; camera.yCord = -player[myId].yCord; //From here we draw stuff on the screen SDL_FillRect(screen,NULL, 0x000000); //Draws WorldMAps draw_map(player[myId].xCord,player[myId].yCord, worldMap, screen); //DISPLAYES YOUR TANK+++++++++++++++++++++++++++++ if (player[myId].team == 1) { draw_tank_self(player[myId].tankAngle, blueTank, screen); draw_cannon_self(player[myId].cannonAngle, blueCannon, screen); } else { draw_tank_self(player[myId].tankAngle, redTank, screen); draw_cannon_self(player[myId].cannonAngle, redCannon, screen); } //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //DISPLAYES OTHER TANKS+++++++++++++++++++++++++++++ for (i = 0; i < MAX_PLAYERS; i++) { if (player[i].slot == myId) { continue; } if (player[i].slot > -1 && player[i].connected == 1) { if (player[i].team == 1) { draw_tank_other(player[i].xCord,player[i].yCord,camera.xCord,camera.yCord,player[i].tankAngle,blueTank,screen); if (player[i].dead == 0) draw_cannon_other(player[i].xCord,player[i].yCord,camera.xCord,camera.yCord,player[i].cannonAngle,blueCannon,screen); } else { draw_tank_other(player[i].xCord,player[i].yCord,camera.xCord,camera.yCord,player[i].tankAngle,redTank,screen); if (player[i].dead == 0) draw_cannon_other(player[i].xCord,player[i].yCord,camera.xCord,camera.yCord,player[i].cannonAngle,redCannon,screen); } } } //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //DRAWS ALL THE BULLETS ON THE SCREEEN+++++++++++++++++++++++++++ for (i = 0; i < MAX_PLAYERS; i++) { if (player[i].slot > -1 && player[i].connected == 1) { if (player[i].fire > 0) { if (bulletAngle[i] == 0) { SDL_FreeSurface( rotatedBullet[i] ); rotatedBullet[i] = rotozoomSurface(bullet,player[i].cannonAngle,1.0,0); playSound(soundShoot); } draw_bullet(&player[i], &camera, rotatedBullet[i], screen ); bulletAngle[i] = 1; } if (player[i].fire == 0) { bulletAngle[i]=0; } } } //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //DRAWS THE USER INTERFACE ON SCREEN+++++++++++++++++++++++++++++ textColor.r=0; textColor.g=0; textColor.b=255; sprintf(textBuffer, "BLUE POINTS: %d", bluePoints); UIbluePoints = TTF_RenderText_Solid( font, textBuffer, textColor ); draw_UI( 10, 10, UIbluePoints, screen); textColor.r=255; textColor.g=0; textColor.b=0; sprintf(textBuffer, "RED POINTS: %d", redPoints); UIredPoints = TTF_RenderText_Solid( font, textBuffer, textColor ); draw_UI( 600, 10, UIredPoints, screen); textColor.r=255; textColor.g=0; textColor.b=0; sprintf(textBuffer, "HP: %d", player[myId].healthPoints); UIhealth = TTF_RenderText_Solid( font, textBuffer, textColor ); draw_UI( 20, 570, UIhealth, screen); textColor.r=255; textColor.g=0; textColor.b=0; if (player[myId].fire == 0) { strcpy(reload, "FIRE: READY"); UIreload = TTF_RenderText_Solid( font, reload, textColor ); } else { strcpy(reload, "FIRE: RELOADING"); UIreload = TTF_RenderText_Solid( font, reload, textColor ); } draw_UI( 580, 570, UIreload, screen); //Update Screen SDL_Flip( screen ); //Cap the frame rate if( timer_get_ticks(&fps) < 1000 / FPS ) { SDL_Delay( ( 1000 / FPS ) - timer_get_ticks(&fps) ); } } pthread_cancel(reciveUdpData); return 0; }
int run() { /* Initialize the random number generator */ srand(time(NULL)); bool quit = false; printf("running\n"); if(!init_game()) { exit(2); } head: if(!load_data()) { printf("data load error\n"); exit(2); } init_common_num(); apply_background(); init_player(); draw_player(); SDL_Color textColor = { 255, 255, 255 }; //Update the screen if( SDL_Flip( screen ) == -1 ) { return 1; } //While the user hasn't quit while( quit == false ) { // printf("%d\n" , rand()%2); wait_frame(); //While there's an event to handle while( SDL_PollEvent( &event ) ) { //If the user has Xed out the window if( event.type == SDL_QUIT ) { quit = true; } if( apear_enemy > ENEMY_NUM) { complete_level(event); } else { if( player.alive == 1) { player_input(event); } } } if(enemy.alive == 0) { init_enemy(); } if(enemy.alive == 1) { enemy_move(); } if(bullet.alive == 1) { bullet_move(); } if(knock(bullet , enemy)) { enemy.image = load_image("data/boom.gif", 1); bullet.image = load_image("data/boom.gif", 1); // draw_enemy(); // draw_bullet(); enemy.alive = 0; bullet.alive = 0; bullet.x = -1000; bullet.y = -1000; score ++; final_score ++; } if(knock(player , enemy)) { enemy.image = load_image("data/boom.gif", 1); player.image = load_image("data/boom.gif", 1); // draw_enemy(); // draw_bullet(); player.alive = 0; enemy.alive = 0; quit = true; } player_move(); apply_background(); draw_enemy(); if(bullet.alive == 1) { draw_bullet(); } draw_player(); if(apear_enemy > ENEMY_NUM) { char text0[256] = ""; sprintf(text0, " LEVEL %d", GAME_LEVEL); message = TTF_RenderText_Solid( font, text0, textColor ); apply_surface( 20 , 50 , message , screen); char text1[256] = "PRESS \"n\" TO NEXT LEVEL"; message = TTF_RenderText_Solid( font, text1, textColor ); apply_surface( 20 , 150 , message , screen); char text2[256] = ""; sprintf(text2, " SCORE:%d", score); message = TTF_RenderText_Solid( font, text2, textColor ); apply_surface( 20 , 250 , message , screen); char text3[256] = ""; if(score ==0 || shoot_time == 0) { sprintf(text3, " ACCURATE:%d" , 0); } else { sprintf(text3, " ACCURATE:%.2lf%%",(double)score/shoot_time*100); } message = TTF_RenderText_Solid( font, text3, textColor ); apply_surface( 20 , 350 , message , screen); } if( SDL_Flip( screen ) == -1 ) { return 1; } if(player.alive == 0) { quit = true; } if(enemy.alive == 0) { init_enemy(); } } char text1[256] = " GAME OVER "; message = TTF_RenderText_Solid( font, text1, textColor ); apply_surface( 20 , 50 , message , screen); char text2[256] = ""; sprintf(text2, " FINAL_SCORE:%d", final_score); message = TTF_RenderText_Solid( font, text2, textColor ); apply_surface( 20 , 150 , message , screen); char text3[256] = " PRESS \"r\" TO RESTART"; message = TTF_RenderText_Solid( font, text3, textColor ); apply_surface( 20 , 250 , message , screen); char text4[256] = " PRESS \"q\" TO EXIT"; message = TTF_RenderText_Solid( font, text4, textColor ); apply_surface( 20 , 350 , message , screen); if( SDL_Flip( screen ) == -1 ) { return 1; } quit = false; while( quit == false ) { // printf("%d\n" , rand()%2); // wait_frame(); //While there's an event to handle while( SDL_PollEvent( &event ) ) { //If the user has Xed out the window if( event.type == SDL_QUIT ) { quit = true; } if( event.type == SDL_KEYDOWN ) { //Adjust the velocity switch( event.key.keysym.sym ) { case SDLK_r: goto head; break; case SDLK_q: quit = true; break; } } } } //Close the font that was used TTF_CloseFont( font ); //Quit SDL_ttf TTF_Quit(); //Quit SDL SDL_Quit(); }