/* wait: * -1: non-blocking, always draw screen * 0: blocking wait for input and always draw screen * 1: non-blocking, draw screen only if a configured delay has passed or after keypress */ int input_handle(int wait) { int ch; struct timeval tv; nodelay(stdscr, wait?1:0); if(wait != 1) screen_draw(); else { gettimeofday(&tv, (void *)NULL); tv.tv_usec = (1000*(tv.tv_sec % 1000) + (tv.tv_usec / 1000)) / update_delay; if(lastupdate != tv.tv_usec) { screen_draw(); lastupdate = tv.tv_usec; } } while((ch = getch()) != ERR) { if(ch == KEY_RESIZE) { if(ncresize(min_rows, min_cols)) min_rows = min_cols = 0; screen_draw(); continue; } switch(pstate) { case ST_CALC: return calc_key(ch); case ST_BROWSE: return browse_key(ch); case ST_HELP: return help_key(ch); case ST_DEL: return delete_key(ch); } screen_draw(); } return 0; }
void main_menu() { /* Play a simulated game in the background */ unsigned char _; initialize(); while (1) { unsigned char key; screen_clear(screen); draw_actors(); draw_string(screen, 28, 0, "-- Pong --"); draw_string(screen, 8, 10, "Press ENTER to begin"); screen_draw(screen); update_ai(&left_paddle); update_ai(&right_paddle); update_ball(); key = app_get_key(&_); switch (key) { case KEY_ENTER: return; case KEY_MODE: exit(0); break; } ksleep(5); } }
void score(bool player) { if (player) { left_score++; } else { right_score++; } ball_motion.x = -ball_motion.x; if (ball_motion.y > 1) { ball_motion.y = 1; } else if (ball_motion.y < -1) { ball_motion.y = -1; } ball.x = DISPLAY_WIDTH / 2 - (ball_width / 2); ball.y = DISPLAY_HEIGHT / 2 - (ball_height / 2); if (game_running) { screen_clear(screen); draw_actors(); draw_score(); draw_string(screen, 40, 10, "SCORE"); screen_draw(screen); ksleep(1000); } }
void main() { SCREEN *screen; get_lcd_lock(); screen = screen_allocate(); screen_clear(screen); draw_string(screen, 0, 0, "Hello world!"); screen_draw(screen); while (1); }
/* wait: * -1: non-blocking, always draw screen * 0: blocking wait for input and always draw screen * 1: non-blocking, draw screen only if a configured delay has passed or after keypress */ int input_handle(int wait) { int ch; struct timeval tv; if(wait != 1) screen_draw(); else { gettimeofday(&tv, (void *)NULL); tv.tv_usec = (1000*(tv.tv_sec % 1000) + (tv.tv_usec / 1000)) / update_delay; if(lastupdate != tv.tv_usec) { screen_draw(); lastupdate = tv.tv_usec; } } /* No actual input handling is done if ncurses hasn't been initialized yet. */ if(!ncurses_init) return wait == 0 ? 1 : 0; nodelay(stdscr, wait?1:0); while((ch = getch()) != ERR) { if(ch == KEY_RESIZE) { if(ncresize(min_rows, min_cols)) min_rows = min_cols = 0; /* ncresize() may change nodelay state, make sure to revert it. */ nodelay(stdscr, wait?1:0); screen_draw(); continue; } switch(pstate) { case ST_CALC: return dir_key(ch); case ST_BROWSE: return browse_key(ch); case ST_HELP: return help_key(ch); case ST_DEL: return delete_key(ch); } screen_draw(); } return 0; }
/* Step the game simulation by handling events, and drawing: */ int game_step(void *input) { GameData *gd = input; ASSERT_ACTIVE(); EventType temp; /* Handle all queued events: */ while( (temp=gamelib_event_get_type()) != GAME_EVENT_NONE ) { /* Trying to resize the window? */ if(temp == GAME_EVENT_RESIZE) { Rect r = gamelib_event_resize_get_size(); screen_resize(gd->data.active.s, r.w, r.h); /* Trying to toggle fullscreen? */ } else if(temp == GAME_EVENT_TOGGLE_FULLSCREEN) { screen_set_fullscreen(gd->data.active.s, -1); /* Trying to exit? */ } else if(temp == GAME_EVENT_EXIT) { return 1; } /* Done with this event: */ gamelib_event_done(); } /* Clear everything: */ tanklist_map(gd->data.active.tl, tank_clear(t, gd->data.active.b)); plist_clear (gd->data.active.pl, gd->data.active.b); /* Charge a small bit of energy for life: */ tanklist_map(gd->data.active.tl, tank_alter_energy(t, TANK_IDLE_COST)); /* See if we need to be healed: */ tanklist_map(gd->data.active.tl, tank_try_base_heal(t)); /* Move everything: */ plist_step (gd->data.active.pl, gd->data.active.lvl, gd->data.active.tl); tanklist_map(gd->data.active.tl, tank_move(t, gd->data.active.tl)); /* Draw everything: */ plist_draw (gd->data.active.pl, gd->data.active.b); tanklist_map(gd->data.active.tl, tank_draw(t, gd->data.active.b)); screen_draw (gd->data.active.s); return 0; }
int main(void) { int i; char choice; char quit; main_init(); quit = FALSE; do { choice = title_page(); switch (choice) { case (0) : case (1) : gPlayers = choice + 1; break; case (2) : continue; default : quit = TRUE; }; if (!quit) { game_reset(); // main game loop do { key_check(); for (i = 0; i != gPlayers; ++i) { player_key_check(i); player_stack_linecheck(i); player_update(i); } screen_draw(); blit(gBuff, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H); } while (gWinner == 0); record_scores(); table_display(); } } while (!quit); table_display(); main_exit(); return 0; }
void video_update (int forced) { char *p_char, *p_attr, a; int r, c1, c2; video_update1 (&forced); if (backgrounded) return; // update every line for (r=0; r<ROWS; r++) { // set pointers to start of line p_char = scrn_cache_chars + r*COLS; p_attr = scrn_cache_attrs + r*COLS; c1 = 0; do { again: // find the start of changed area (c1) while (!forced && c1 < COLS && p_char[c1] == scrn_store_chars[r*COLS+c1] && p_attr[c1] == scrn_store_attrs[r*COLS+c1]) c1++; if (c1 == COLS) break; a = p_attr[c1]; // c2 (end of update region) is where: for (c2=c1+1; c2 < COLS; c2++) { // a) attributes are different if (p_attr[c2] != a) break; // b) attributes are the same and symbols are the same, // and next chars also have the same attributes and value if (!forced && c2+4 < COLS-1 && p_attr[c2] == scrn_store_attrs[r*COLS+c2] && p_char[c2] == scrn_store_chars[r*COLS+c2] && p_attr[c2+1] == scrn_store_attrs[r*COLS+c2+1] && p_char[c2+1] == scrn_store_chars[r*COLS+c2+1] && p_attr[c2+2] == scrn_store_attrs[r*COLS+c2+2] && p_char[c2+2] == scrn_store_chars[r*COLS+c2+2] && p_attr[c2+3] == scrn_store_attrs[r*COLS+c2+3] && p_char[c2+3] == scrn_store_chars[r*COLS+c2+3] && p_attr[c2+4] == scrn_store_attrs[r*COLS+c2+4] && p_char[c2+4] == scrn_store_chars[r*COLS+c2+4] ) break; } // update segment from c1 (inclusive) to c2 (non-inclusive) screen_draw (p_char+c1, c2-c1, r, c1, p_attr+c1); c1 = c2; if (c2 < COLS && p_attr[c2] != a) goto again; } while (c2 < COLS); } if (cursor_cache != cursor_store) { set_cursor (cursor_cache); cursor_store = cursor_cache; } // under Unix, move_cursor performs fflush(stdout) move_cursor (CURSOR_ROW, CURSOR_COL); memcpy (scrn_store_chars, scrn_cache_chars, ROWS*COLS); memcpy (scrn_store_attrs, scrn_cache_attrs, ROWS*COLS); video_flush (); }
static void viewlist_real_key_press (screen* base, gint key_num) { viewlist * self; gint _tmp0_; self = (viewlist*) base; _tmp0_ = key_num; switch (_tmp0_) { case '\n': { world_wide* _tmp1_; playlist* _tmp2_; world_wide* _tmp5_; world_wide* _tmp6_; const gchar* _tmp7_; playlist* _tmp8_; world_wide* _tmp9_; playlist* _tmp10_; gint _tmp11_; world_wide* _tmp12_; playlist* _tmp13_; gint _tmp14_; world_wide* _tmp15_; playlist* _tmp16_; gint _tmp17_; gint _tmp18_; world_wide* _tmp19_; playlist* _tmp20_; _tmp1_ = ((screen*) self)->world; _tmp2_ = _tmp1_->play_screen; if (_tmp2_ != NULL) { world_wide* _tmp3_; playlist* _tmp4_; _tmp3_ = ((screen*) self)->world; _tmp4_ = _tmp3_->play_screen; playlist_empty (_tmp4_); } _tmp5_ = ((screen*) self)->world; _tmp6_ = ((screen*) self)->world; _tmp7_ = ((playlist*) self)->m3u_path; _tmp8_ = playlist_new_play_start (_tmp6_, _tmp7_); _tmp5_->play_screen = _tmp8_; _tmp9_ = ((screen*) self)->world; _tmp10_ = _tmp9_->play_screen; _tmp11_ = ((screen*) self)->screen_pos; ((screen*) _tmp10_)->screen_pos = _tmp11_; _tmp12_ = ((screen*) self)->world; _tmp13_ = _tmp12_->play_screen; _tmp14_ = ((screen*) self)->row_pos; ((screen*) _tmp13_)->row_pos = _tmp14_; _tmp15_ = ((screen*) self)->world; _tmp16_ = _tmp15_->play_screen; _tmp17_ = ((screen*) self)->screen_pos; _tmp18_ = ((screen*) self)->row_pos; playlist_play_a_song (_tmp16_, _tmp17_ + _tmp18_); _tmp19_ = ((screen*) self)->world; _tmp20_ = _tmp19_->play_screen; screen_draw ((screen*) _tmp20_); break; } default: { gint _tmp21_; _tmp21_ = key_num; SCREEN_CLASS (viewlist_parent_class)->key_press ((screen*) PLAYLIST (self), _tmp21_); break; } } }
void main() { load_library("/lib/core"); get_lcd_lock(); get_keypad_lock(); screen = screen_allocate(); init(); while(1){ draw_sprite_xor(screen, 88, posY, player_height, &player_sprite); draw_rect_or(screen, 8, 96, 56, 0); if(!forTime){ gen=get_random()%3; forTime=2+get_random()%3; } else{ forTime--; } switch(gen){ case 1: if(height>1) height--; break; case 2: if(height<56-space) height++; break; default: break; } //Right Shift for(i=0; i<768; i++) { bit2 = screen[i] & 0x01; screen[i] >>= 1; screen[i] |= bit1 << 7; bit1 = bit2; } for(i=0;i<56;i++){reset_pixel(screen, 0, i);} for(i=0;i<height;i++){set_pixel(screen, 0, i);} for(i=height+space;i<56;i++){set_pixel(screen, 0, i);} key = app_get_key(&_); if(key==KEY_UP) {posY--;} if(key==KEY_DOWN) {posY++;} draw_sprite_xor(screen, 88, posY, player_height, &player_sprite); draw_rect_and(screen, 7, 96, 57, 0); draw_string(screen, 1, 58, "Score:"); draw_short(screen, 26, 58, score); draw_string(screen, 55, 58, "Best:"); draw_short(screen, 76, 58, bestscore); screen_draw(screen); if(getPixel(screen, 95, posY) && getPixel(screen, 95, posY+7) && getPixel(screen, 92, posY+3) && getPixel(screen, 92, posY+4)){ } else{ if(score>bestscore){ bestscore=score; } init(); } score++; if(score%1000==0 && space>12){ space--; } if(score==60000){ space=0; } } }
void draw() { screen_clear(screen); draw_actors(); draw_score(); screen_draw(screen); }
int main(int argc, char *argv[]) { char input = 0; char save_name[50]; //Prepare engine Engine *engine = prepare_game(save_name); GoF_Screen *screen = screen_create(0, 0, 30, 30, 20); Graphics g; graphics_init(&g, 800, 900, "The Game of Life!"); input = 0; while(input != 'k') { screen_draw(screen, &g, engine); input = graphics_event(&g); if(input == 1) engine_add_entity(engine, entity_create(g.last_x/screen->entity_length, g.last_y/screen->entity_length)); else if(input == 3) engine_remove_entity(engine, g.last_x/screen->entity_length, g.last_y/screen->entity_length); } //Input input = 0; int sens = 5; //Main game loop while(input != 'q') { //Draw on screen screen_draw(screen, &g, engine); //Update Engine engine_update(engine); //Process input while(graphics_check_event(&g)) { input = graphics_event(&g); switch(input) { case 'p': engine->ups++; break; case 'm': if(engine->ups > 1) engine->ups--; break; case '.': sens++; break; case ',': if(sens > 1) sens--; break; case UP_ARROW: screen->y -= sens; break; case DOWN_ARROW: screen->y += sens; break; case LEFT_ARROW: screen->x -= sens; break; case RIGHT_ARROW: screen->x += sens; break; } } //Sleep usleep((1000/engine->ups) * 1000); } //Close graphics graphics_close(&g); //Save game printf("Saving game...\n"); engine_save(engine, save_name); //Free mem engine_free(engine); screen_free(screen); return 0; }