static SCM game_run (SCM game_smob) { Game *game = check_game (game_smob); if (scm_is_true (game->on_start)) { scm_call_0 (game->on_start); } al_start_timer (game->timer); game->last_update_time = al_get_time (); while (game->running) { game_process_event (game); if (game->redraw && al_is_event_queue_empty (game->event_queue)) { game->redraw = false; game_draw (game); } } game_destroy (game); return SCM_UNSPECIFIED; }
static void demo_end_paint(int id, float t) { game_draw(0, t); gui_paint(id); if (demo_paused) hud_paint(); }
static void demo_play_paint(int id, float t) { game_draw(0, t); if (show_hud) hud_paint(); if (time_state() < 1.f) gui_paint(id); }
void game_loop() { int64_t ascii = readKeyCode(); screen_t scr_info; screen_init(&scr_info, 0, 0, SCREEN_SIZE_X, 2); --game.timer; if(ascii) { screen_clear(NULL, 0x00); switch(ascii) { case KEY_CODE_AU: block_mov(game.player, 0, -1); break; case KEY_CODE_AD: block_mov(game.player, 0, 1); break; case KEY_CODE_AL: block_mov(game.player, -1, 0); break; case KEY_CODE_AR: block_mov(game.player, 1, 0); break; case KEY_CODE_S: block_rotate(game.player); break; case KEY_CODE_ENT: if( game.player->dealloc || field_empty(&game.field, game.player) ) { ++game.score; field_block_merge(&game.field, game.player); game_next(&game); } break; } game_draw(&game); } if(game.timer == 0) { // screen_clear(NULL, 0x00); // writef(NULL, "The application crashed...%nWhy did you abandon it? You monster!"); new_highscore_init(game.score); return; } writef(&scr_info, "Time left: %c%u%c seconds!%n" "Your current score: %c%u", 0xCF, game.timer / TICKS_PER_SEC +1, 0x07, 0x2F, game.score); }
void game_loop() { int player_input; socklen_t slen = sizeof(client_config.addr); printf("Nospiediet '%c', lai sāktu spēli!\n", 'b'); bash_set_window_size(client_config.width, client_config.height); bash_hide_cursor(); client_config.state = PLAYER_STATE_INITIAL; memset(field, DEFAULT_BLANK_CHAR, sizeof(field)); do { if ((resp_len = recvfrom(sender, msg, MAX_MESSAGE_SIZE, 0, (struct sockaddr *) &client_config.addr, &slen)) == -1) { if (errno != EAGAIN) error("Error while receving game updates"); } if (resp_len > 0) { decode_message(msg, resp_len); } if ((player_input = fgetc(stdin)) != EOF) { send_player_action(player_input); switch (player_input) { case 'Q': case 'q': client_config.state = PLAYER_STATE_LEFT; break; } } /* Draw only when in game */ if (client_config.state == PLAYER_STATE_ACTIVE) game_draw(); } while (client_config.state < PLAYER_STATE_DEAD); switch (client_config.state) { case PLAYER_STATE_DEAD: printf("Jūs nomirāt!\n"); break; case PLAYER_STATE_END: /* if (client_config.winner == client_config.id) printf("Jūs uzvarējāt!\n"); else printf("Jūs zaudējāt!\n"); */ break; } }
int main(int argc, char *argv[]) { game_t game; fe_init(); fe_clear_screen(); game_init(&game, PF_WHITE); game_draw(&game, game.starting_color); game_do(&game); return 0; }
int main() { srvInit(); aptInit(); hidInit(NULL); irrstInit(NULL); gfxInitDefault(); yeti_init( &yeti, (framebuffer_t*)gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL), (framebuffer_t*)gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL), textures, palette, lua ); gfxSet3D(true); game_init(&yeti); while(aptMainLoop()) { int i; for(i=0;i<2;i++) { yeti.viewport.front = yeti.viewport.back; yeti.viewport.back = (framebuffer_t*)gfxGetFramebuffer(GFX_TOP, leftOrRight?GFX_LEFT:GFX_RIGHT, NULL, NULL); game_draw(&yeti); leftOrRight^=1; } yetiUpdateKeyboard(&yeti); game_tick(&yeti); if(hidKeysDown()&KEY_START)break; gfxFlushBuffers(); gfxSwapBuffers(); gspWaitForEvent(GSPEVENT_VBlank0, true); } gfxExit(); irrstExit(); hidExit(); aptExit(); srvExit(); return 0; }
void on_draw_game_feedback (int fd, struct message *msg) { printf ("on_draw_game_feedback \n"); int result; char number[32]; sscanf (msg->buff, "%s %d", number, &result); if (result == 1) { /* 对方同意和棋 */ game_draw (); } else show_message_dialog (GTK_MESSAGE_ERROR, "对方拒绝您的请求"); }
void on_draw_game (int fd, struct message *msg) { printf ("on_draw_game\n"); msg->type = DRAW_GAME_FEEDBACK; if (accept_request ("对方请求和棋\n是否同意")) { sprintf (msg->buff, "%s 1", get_room_number ()); /* 同意和棋 */ game_draw (); } else { sprintf (msg->buff, "%s 0", get_room_number ()); } send_message (msg); }
void Apep::run(){ assert("You must initialize engine before run!" && back_buffer != nullptr); clean_screen(); if (!game_setup()) return; while (game_update()) { while (_kbhit()) key(_getch()); game_draw(); flush(); Sleep(10); } game_cleanup(); }
static void game_won(game_t *p_game, int val) { char *msg = "Restarting..."; fe_fill_area(FE_PHYS_WIDTH / 2 - 90, FE_PHYS_HEIGHT / 2 - 18, 84, 36); fe_clear_area(FE_PHYS_WIDTH / 2 - 88, FE_PHYS_HEIGHT / 2 - 16, 80, 32); if (val < 0) msg = "White won!"; else if (val > 0) msg = "Black won!"; fe_print_xy(FE_PHYS_WIDTH / 2 - 76, FE_PHYS_HEIGHT / 2 - 8, FE_FONT_NORMAL, msg); fe_sleep(128); game_init(p_game, p_game->computer_color); fe_clear_area(PF_WIDTH * BRICK_WIDTH + 4, 59, FE_PHYS_WIDTH - PF_WIDTH * BRICK_WIDTH - 8, 3*8 + 4); game_draw(p_game, p_game->starting_color); }
int main(void) { physics_init(LCD_WIDTH, LCD_HEIGHT); input_init(); display_init(); segment_init(); players_init(); playerA = players_get(0); playerB = players_get(1); ball = physics_create(LCD_WIDTH / 2, LCD_HEIGHT / 2, BALL_RADIUS, BALL_MASS); for (;;) { input_update(); players_update(0.01f); physics_update(0.01f); game_update(); game_draw(); } return 0; }
static void stroke_paint(int id, float t) { game_draw(0, t); hud_paint(); }
static void flyby_paint(int id, float t) { game_draw(0, t); hud_paint(); }
static void poser_paint(int id, float t) { game_draw(1, t); }
static void next_paint(int id, float t) { game_draw(0, t); hud_paint(); gui_paint(id); }
static void party_paint(int id, float t) { game_draw(0, t); gui_paint(id); }
static void course_paint(int id, float t) { game_draw(0, t); gui_paint(id); }
void GameProcess() { if (game.status == STATUS_PLAYING) { int c_shoot_restore_delay = (6 + 2*game.stage_level); int c_shoot_restore_period = (game.stage_level < 2) ? (3 + game.stage_level) : 5; // shoot if ( ( (game.shoot_keypressed) || (is_key_pressed(RS_ATTACK_KEY_MASK)) ) && (game.ammo>0) ) { game.shoot_delay ++; if (game.shoot_delay > GAME_SHOOT_PERIOD) { // if (game.ammo > 0) { game.shoot_restore_delay = 0; game.ammo--; soundbuf_play(&game.sound_shoot, 0); game_obj_add( game_obj( OBJ_BULLET, 0, 0, 0, game.player_x+5, game.player_y, 0, 0.0) ); // }; game.shoot_delay = 1; // -= GAME_SHOOT_PERIOD; game.shoot_keypressed = 0; }; } else { if (game.ammo < GAME_AMMO_MAX) { game.shoot_restore_delay++; if (game.shoot_restore_delay > c_shoot_restore_delay) { game.shoot_delay++; if (game.shoot_delay > c_shoot_restore_period) { game.ammo++; game.shoot_delay -= c_shoot_restore_period; }; }; }; }; int speed = 4; int bullet_speed = 11; int red_bullet_speed = 8; int rock_speed = 6; game.player_x += speed * ( is_key_pressed(RS_ARROW_RIGHT_MASK) - is_key_pressed(RS_ARROW_LEFT_MASK) ); game.player_y += speed * ( is_key_pressed(RS_ARROW_DOWN_MASK) - is_key_pressed(RS_ARROW_UP_MASK) ); game.player_x = rs_clamp_i(game.player_x, 15, GAME_WIDTH - 45); game.player_y = rs_clamp_i(game.player_y, 15, GAME_HEIGHT - 45); game.tz += 1; int c_rocktimer_const = (game.stage_level < 4) ? (9 - 2*game.stage_level) : 4; int c_rocktimer_var = (game.stage_level < 6) ? (16 - 2*game.stage_level) : 6; game.stage_timer++; if (game.stage == 0) { // level start next_stage_after_sec(3); } else if (game.stage == 1) { // game.stage = 4; // rocks next_rock_timer--; if (next_rock_timer < 1) { next_rock_timer = c_rocktimer_const + rs_rand()%c_rocktimer_var; //game_obj_add( game_obj( ((rs_rand() % 512) > 256) ? OBJ_ROCK : OBJ_MINIROCK, 0, rs_rand() % ROCKS_COUNT , 32, GAME_WIDTH + 100, 30 + rs_rand()%(GAME_HEIGHT-60), 0, 0.0 ) ); int flagsin = 0; if ( game.stage_level > 4 ) { if ( rs_rand()%1024 < (16*game.stage_level) ) { flagsin = OBJ_FLAG_SIN; }; }; game_obj_add( game_obj( OBJ_ROCK, OBJ_FLAG_ENEMY | flagsin, rs_rand() % ROCKS_COUNT , game.tex_rocks[0].w/2, GAME_WIDTH + 50, 30 + rs_rand()%(GAME_HEIGHT-90), 0, 0.0 ) ); }; next_stage_after_sec(12); } if (game.stage == 2) { BIT_SET (game.flags, GAME_FLAG_INSTRUCTIONS_PASSED); next_stage_after_sec(4); } else if (game.stage == 3) { // rocks next_rock_timer--; if (next_rock_timer < 1) { next_rock_timer = c_rocktimer_const + 1 + rs_rand()%c_rocktimer_var; //game_obj_add( game_obj( ((rs_rand() % 512) > 256) ? OBJ_ROCK : OBJ_MINIROCK, 0, rs_rand() % ROCKS_COUNT , 32, GAME_WIDTH + 100, 30 + rs_rand()%(GAME_HEIGHT-60), 0, 0.0 ) ); int flagsin = 0; if ( game.stage_level > 2 ) { if ( rs_rand()%1024 < (16*game.stage_level) ) { flagsin = OBJ_FLAG_SIN; }; }; game_obj_add( game_obj( OBJ_MINIROCK, OBJ_FLAG_ENEMY|flagsin, rs_rand() % ROCKS_COUNT , game.tex_minirocks[0].w/2, GAME_WIDTH + 50, 30 + rs_rand()%(GAME_HEIGHT-90), 0, 0.0 ) ); }; next_stage_after_sec(16); } else if (game.stage == 4) { next_stage_after_sec(4); } else if (game.stage == 5) { // rocks next_rock_timer--; if (next_rock_timer < 1) { next_rock_timer = 5; //game_obj_add( game_obj( ((rs_rand() % 512) > 256) ? OBJ_ROCK : OBJ_MINIROCK, 0, rs_rand() % ROCKS_COUNT , 32, GAME_WIDTH + 100, 30 + rs_rand()%(GAME_HEIGHT-60), 0, 0.0 ) ); game_obj_add( game_obj( OBJ_MINIROCK, OBJ_FLAG_ENEMY | OBJ_FLAG_SIN, rs_rand() % ROCKS_COUNT , game.tex_minirocks[0].w/2, GAME_WIDTH + 50, GAME_HEIGHT/8, 0, 0.0 ) ); }; next_stage_after_sec(6); } else if (game.stage == 6) { // mix rocks next_rock_timer--; if (next_rock_timer < 1) { next_rock_timer = c_rocktimer_const + rs_rand()%(c_rocktimer_var-3); int flagsin = 0; if ( game.stage_level > 3 ) { if ( rs_rand()%1024 < (16*game.stage_level) ) { flagsin = OBJ_FLAG_SIN; }; }; //game_obj_add( game_obj( ((rs_rand() % 512) > 256) ? OBJ_ROCK : OBJ_MINIROCK, 0, rs_rand() % ROCKS_COUNT , 32, GAME_WIDTH + 100, 30 + rs_rand()%(GAME_HEIGHT-60), 0, 0.0 ) ); game_obj_add( game_obj( rs_rand()%1024 < 768 ? OBJ_MINIROCK : OBJ_ROCK, OBJ_FLAG_ENEMY | flagsin, rs_rand() % ROCKS_COUNT , rs_rand()%1024 < 768 ? game.tex_minirocks[0].w/2 : game.tex_rocks[0].w/2, GAME_WIDTH + 100, 30 + rs_rand()%(GAME_HEIGHT-90), 0, 0.0 ) ); }; next_stage_after_sec(10); } else if (game.stage == 7) { if (game.stage_timer > 3*25) { next_stage_now(); BIT_CLEAR(game.flags, GAME_FLAG_BOSS_DESTROYED); game_obj_add( game_obj( OBJ_TURRET, OBJ_FLAG_ENEMY | OBJ_FLAG_BOSS, 60, game.tex_rocks[0].w/2, GAME_WIDTH+60, GAME_HEIGHT/2, 0, 0.0 ) ); }; } else if (game.stage == 8) { if ( IS_BIT_SET(game.flags, GAME_FLAG_BOSS_DESTROYED) ) { next_stage_now(); }; } else if (game.stage == 9) { next_stage_after_sec(2); } else if (game.stage == 10) { /* game.status = STATUS_MENU; menu_open( MENU_LEVEL_PASSED ); level_passed_score_str[1] = '0' + (game.score / 100) % 10; level_passed_score_str[2] = '0' + (game.score / 10) % 10; level_passed_score_str[3] = '0' + (game.score / 1) % 10; */ game.stage_level++; game.stage = 0; game.stage_timer = 0; }; int i, j; game_obj_t *obj; for (i = 0; i < game.objs_count; i++) { obj = &(game.objs[i]); if (obj->obj_type == OBJ_BULLET) { obj->x += bullet_speed; if (obj->x > GAME_WIDTH) { // destroy object game_obj_remove(i); i--; continue; }; for (j = 0; j < game.objs_count; j++) { if (IS_BIT_SET(game.objs[j].flags, OBJ_FLAG_ENEMY)) { if (check_collision(i, j)) { if (IS_BIT_SET( game.objs[j].flags, OBJ_FLAG_BOSS)) { game.objs[j].tag--; if (game.objs[j].tag < 1) { BIT_SET( game.objs[j].flags, OBJ_FLAG_DESTROYED ); BIT_SET( game.flags, GAME_FLAG_BOSS_DESTROYED ); game.score += 50; }; } else { BIT_SET( game.objs[j].flags, OBJ_FLAG_DESTROYED ); game.score += game.objs[j].obj_type == OBJ_ROCK ? 2 : 3; }; game_obj_remove(i); i--; break; // continue parent loop }; }; }; } else if (obj->obj_type == OBJ_RED_BULLET) { obj->x -= red_bullet_speed; if (obj->x < 4) { // destroy object game_obj_remove(i); i--; continue; }; if (check_collision_with_player(i)) { player_hit(); game_obj_remove(i); i--; continue; }; } else if (obj->obj_type == OBJ_EXPLOSION) { obj->t++; if (obj->t >= EXPLOSIONS_COUNT) { game_obj_remove(i); i--; continue; }; } else if (obj->obj_type == OBJ_HUGE_EXPLOSION) { obj->t++; if (obj->t >= HUGE_EXPLOSIONS_COUNT) { game_obj_remove(i); i--; continue; }; } else if ( (obj->obj_type == OBJ_ROCK) || (obj->obj_type == OBJ_MINIROCK) ) { obj->x -= rock_speed; if (obj->x < - obj->radius * 2) { game_obj_remove(i); i--; continue; }; if ( IS_BIT_SET(obj->flags, OBJ_FLAG_SIN) ) { obj->f += 0.2; obj->y += 7.0 * sin(obj->f); }; if ( check_collision_with_player(i) ) { player_hit(); game_obj_remove(i); i--; continue; }; } else if ( obj->obj_type == OBJ_TURRET ) { if (obj->x > GAME_WIDTH*3/4) { obj->x -= 2; } else { obj->f += 0.03; obj->y = GAME_HEIGHT * ( 0.5 + 0.3*sin(obj->f) ); }; if ( obj->x < GAME_WIDTH*4/5 ) { // turret shoot obj->t--; if (obj->t < 1) { soundbuf_play(&game.sound_turret_shoot, 0); game_obj_add( game_obj( OBJ_RED_BULLET, 0, 0, 3, obj->x - 5, obj->y, 0, 0) ); int c_const = (game.stage_level < 4) ? (10 - 2*game.stage_level) : 3; int c_var = (game.stage_level < 6) ? (20 - 3*game.stage_level) : 3; obj->t = c_const + rs_rand() % c_var; if ( (rs_rand()%1024) < 80 ) { obj->t += 18; }; }; }; }; }; for (i = 0; i < game.objs_count; i++) { if ( IS_BIT_SET( game.objs[i].flags, OBJ_FLAG_DESTROYED ) ) { if (game.objs[i].obj_type == OBJ_TURRET) { soundbuf_play( &game.sound_huge_explosion, 0 ); game_obj_add( game_obj( OBJ_HUGE_EXPLOSION, 0, 0, HUGE_EXPLOSION_RADIUS, game.objs[i].x, game.objs[i].y, 0, 0.0 ) ); } else { soundbuf_play( &game.sound_explosions[ rs_rand() % SOUND_EXPLOSIONS_COUNT ], 0 ); game_obj_add( game_obj( OBJ_EXPLOSION, 0, 0, EXPLOSION_RADIUS, game.objs[i].x, game.objs[i].y, 0, 0.0 ) ); }; game_obj_remove(i); i--; }; }; }; game_draw(); if ( (game.status == STATUS_MENU) && (game.menu_index != MENU_PAUSE) ) { soundbuf_loop_check( &game.sound_music ); }; }
static void over_paint(int id, float t) { game_draw(0, t); gui_paint(id); }
// entry point void _main(void) { // some variables for the main loop unsigned int lasttick = 0; void *keyqueue = kbd_queue(); unsigned short key; // initiate all the stuff init(); // start at the menu switchgs(GS_MENU); // main loop while (gs != GS_NONE) { // run at 20 fps if (FiftyMsecTick != lasttick) { // Check for keypresses if (!OSdequeue(&key, keyqueue)) { if (key == KEY_ON) off(); else if (key == KEY_QUIT) switchgs(GS_NONE); else { switch (gs) { case GS_MENU: if (key == KEY_ENTER) switchgs(GS_GAME); else if (key == KEY_ESC) switchgs(GS_NONE); break; case GS_GAME: if (key == KEY_ENTER) game_flap(); else if (key == KEY_ESC) switchgs(GS_MENU); break; case GS_GAMEOVER: if (key == KEY_ENTER) switchgs(GS_GAME); else if (key == KEY_ESC) switchgs(GS_MENU); break; default: break; } } } // draw to the buffers GrayClearScreen2B(lightbuffer, darkbuffer); switch (gs) { case GS_MENU: menu_update(); menu_draw(); break; case GS_GAME: game_update(); game_draw(); break; case GS_GAMEOVER: gameover_update(); game_draw(); gameover_draw(); break; default: break; } // flip the buffers FastCopyScreen(darkbuffer, darkplane); FastCopyScreen(lightbuffer, lightplane); lasttick = FiftyMsecTick; framecounter++; } } // important! deinit(); }
void game_client_draw(int pose, float t) { game_lerp_apply(&gl, &gd); game_draw(&gd, pose, t); }
static void help_paint(int id, float st) { game_draw(0, st); config_pop_matrix(); gui_paint(id); }
static void roll_paint(int id, float t) { game_draw(0, t); hud_paint(); }
static void title_paint(int id, float t) { game_draw(0, t); gui_paint(id); }
void pause_draw(void) { game_draw(); status_print(); }
void game_loop(void) { game_update(); game_draw(); if (stat == STAT_PLAYING) game_step(); }