short outputscore() { short ret; #if UNIX while( creat( LOCKFILE) < 0); /* lock the score file */ #endif if( (ret = readscore()) == 0) showscore(); #if UNIX unlink( LOCKFILE); #endif return( (ret == 0) ? E_ENDGAME : ret); }
/* this is the plugin entry point */ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) { struct pong pong; int game = 1; /* init the struct with some silly values to start with */ pong.ballx = 20*RES; pong.bally = 20*RES; pong.e_pad[0] = 0; pong.w_pad[0] = 7; pong.e_pad[1] = 0; pong.w_pad[1] = 40; pong.ballspeedx = SPEEDX; pong.ballspeedy = SPEEDY; pong.score[0] = pong.score[1] = 0; /* lets start at 0 - 0 ;-) */ /* if you don't use the parameter, you can do like this to avoid the compiler warning about it */ (void)parameter; TEST_PLUGIN_API(api); rb = api; /* use the "standard" rb pointer */ /* Clear screen */ rb->lcd_clear_display(); /* go go go */ while(game > 0) { showscore(&pong); pad(&pong, 0); /* draw left pad */ pad(&pong, 1); /* draw right pad */ ball(&pong); /* move and draw ball */ rb->lcd_update(); game = keys(&pong); /* deal with keys */ } return (game == 0) ? PLUGIN_OK : PLUGIN_USB_CONNECTED; }
/* this is the plugin entry point */ enum plugin_status plugin_start(const void* parameter) { struct pong pong; int game = 1; int blink_timer = 0; int blink_rate = 20; bool blink = true; /* init the struct with some silly values to start with */ pong.ball.x = 20*RES; pong.ball.y = 20*RES; pong.ball.speedx = SPEEDX; pong.ball.speedy = SPEEDY; pong.player[0].xpos = 0; pong.player[0].e_pad = 0; pong.player[0].w_pad = 7; pong.player[1].xpos = LCD_WIDTH-PAD_WIDTH; pong.player[1].e_pad = 0; pong.player[1].w_pad = 40; /* start every game in demo mode */ pong.player[0].iscpu = pong.player[1].iscpu = true; pong.player[0].score = pong.player[1].score = 0; /* lets start at 0 - 0 ;-) */ /* if you don't use the parameter, you can do like this to avoid the compiler warning about it */ (void)parameter; /* Turn off backlight timeout */ backlight_ignore_timeout(); /* Clear screen */ rb->lcd_clear_display(); /* go go go */ while(game > 0) { if (game == 2) { /* Game Paused */ rb->splash(0, "PAUSED"); while(game == 2) game = keys(&pong); /* short circuit */ rb->lcd_clear_display(); } if( pong.player[0].iscpu && pong.player[1].iscpu ) { if(blink_timer<blink_rate) { ++blink_timer; } else { blink_timer=0; blink = !blink; } if(blink==true) { blink_demo(); } else { rb->lcd_clear_display(); } } showscore(&pong); pad(&pong, 0); /* draw left pad */ pad(&pong, 1); /* draw right pad */ ball(&pong); /* move and draw ball */ rb->lcd_update(); game = keys(&pong); /* deal with keys */ } /* Turn on backlight timeout (revert to settings) */ backlight_use_settings(); return (game == 0) ? PLUGIN_OK : PLUGIN_USB_CONNECTED; }
void time_update(void) { extern struct tm *time_ptr; extern char qsonrstr[]; extern int bandinx; extern int this_second; extern int system_secs; extern int miniterm; char time_buf[11]; int currentterm = 0; static int s = 0; static int m = 0; static int oldsecs = -1; /* trigger immediate update */ get_time(); this_second = time_ptr->tm_sec; /* seconds */ system_secs = time_ptr->tm_min * 60 + time_ptr->tm_sec; if (this_second != oldsecs) { /* do it every second */ oldsecs = this_second; if (wpx == 1) { if (minute_timer > 0) minute_timer--; } s = (s + 1) % 2; if (s > 0) { /* every 2 seconds */ strftime(time_buf, 10, "%H:%M:%S", time_ptr); time_buf[5] = '\0'; if ((time_buf[6] == '1') && (m >= 30)) { m = 0; getwwv(); } else { m++; } currentterm = miniterm; miniterm = 0; broadcast_lan(); update_line(time_buf); show_freq(); clusterinfo(); /* update cluster info (2 seconds) */ attron(COLOR_PAIR(C_LOG) | A_STANDOUT); mvprintw(7, 0, logline0); mvprintw(8, 0, logline1); mvprintw(9, 0, logline2); mvprintw(10, 0, logline3); mvprintw(11, 0, logline4); mvprintw(13, 0, " "); attron(COLOR_PAIR(C_WINDOW)); mvprintw(12, 23, qsonrstr); printcall(); showscore(); /* update score window every 2 seconds */ show_zones(bandinx); miniterm = currentterm; } } }
int main( int argc, char* args[] ) { quit = 0; Tile *tiles[ TOTAL_TILES ]; Timer fps; levelwon = 0; //Initialize if( init() == false ) { return 1; } if( TTF_Init() == -1 ) { return false; } //Initialize SDL_mixer if( Mix_OpenAudio( 22050, MIX_DEFAULT_FORMAT, 2, 4096 ) == -1 ) { return false; } //Load the files if( load_files() == false ) { return 1; } //Clip the tile sheeti if( Mix_PlayMusic( music, -1 ) == -1 ) { return 1; } clip_tiles(); if(!welcome)return 1; SDL_BlitSurface(welcome, NULL, screen, NULL ); SDL_Flip( screen ); SDL_Delay(6000); robin robinp; while(quit ==false) { if(level!= 1) { SDL_BlitSurface( prepare, NULL, screen, NULL ); SDL_Flip(screen); SDL_Delay(3000); } robinp.reset(); //Set the tiles if( set_tiles( tiles ) == false ) { return 1; } // SDL_Delay(3000); first=1; ///////////////////////////////////////////////////////////////////////////////////// while( quit == false && levelwon == 0)/////////////////////////////////// { //Start the frame timer fps.start(); //While there's events to handle while( SDL_PollEvent( &event ) ) { robinp.handle_events(); //If the user has Xed out the window if( event.type == SDL_QUIT ) { //Quit the program quit = true; } } SDL_BlitSurface( background, NULL, screen, NULL ); robinp.move(tiles); robinp.set_camera(); for( int t = 0; t < TOTAL_TILES; t++ ) { tiles[ t ]->show(); } for(int i=0;i< en_num;i++) { enemys[en_num]->show(); //robinp.reset(); } robinp.show(); showscore(); //Update the screen if( SDL_Flip( screen ) == -1 ) { return 1; } //Cap the frame rate if( fps.get_ticks() < 1000 / FRAMES_PER_SECOND ) { SDL_Delay( ( 1000 / FRAMES_PER_SECOND ) - fps.get_ticks() ); } } clean_up(tiles); level++; levelwon = 0; ///////////////////////////////////////////////////////////////////////////////////// //cout<<"out of level"; } SDL_FreeSurface( background ); SDL_FreeSurface( gameover ); SDL_FreeSurface( tileSheet ); //Free the music Mix_FreeMusic( music ); Mix_FreeChunk( jumpsou ); Mix_FreeChunk( coinsou ); Mix_FreeChunk( hitsou ); Mix_FreeChunk( diamoundsou ); //Close the font TTF_CloseFont( font ); //Quit SDL_mixer Mix_CloseAudio(); SDL_Quit(); //Quit SDL_ttf TTF_Quit(); return 0; }