static void game_draw(context *ctx) { struct game_context *game = (struct game_context *)ctx; struct config_info *conf = get_config(); struct world *mzx_world = ctx->world; // No game state change has happened (yet) mzx_world->change_game_state = CHANGE_STATE_NONE; if(game->is_title && game->fade_in) { // Focus on center int x, y; set_screen_coords(640/2, 350/2, &x, &y); focus_pixel(x, y); } if(!mzx_world->active) { // There is no MZX_SPEED to derive a framerate from, so use the UI rate. set_context_framerate_mode(ctx, FRAMERATE_UI); if(!conf->standalone_mode) draw_intro_mesg(mzx_world); m_show(); return; } set_context_framerate_mode(ctx, FRAMERATE_MZX_SPEED); update_world(ctx, game->is_title); draw_world(ctx, game->is_title); }
void draw(){ clear(); draw_base(); draw_world(); draw_block(); refresh(); }
int main(int argc, char** argv) { uint32_t last_frame_time = 0; uint32_t width = 640; uint32_t height = 480; bool quit = false; SDL_Window* window = NULL; SDL_Renderer* ren = NULL; SDL_Texture* texture = NULL; static uint32_t* pxbuf = NULL; static uint8_t* bug_data = NULL; //Initialize game pxbuf = new uint32_t[width*height]; bug_data = new uint8_t[width*height]; memset(pxbuf, 0x00, width*height); memset(bug_data, 0x00, width*height); if(init_sdl(width, height, &window, &ren, &texture)) { return 1; } printf("SDL successfully initialized.\n"); while (!quit) { last_frame_time = SDL_GetTicks(); if (process_events() == -1) { quit = true; } update_bugs(width, height, bug_data); update_world(width, height, pxbuf, bug_data, texture); draw_world(width, height, texture, ren); printf("FPS: %f \r", 1000./(SDL_GetTicks()-last_frame_time)); } SDL_Quit(); return 0; }
void run_life(world *w, WINDOW *win){ draw_world(w, win); nodelay(win, 1); curs_set(0); struct timeval tv1,tv2; while(1){ double interupt = float_sleep(wait_time); step_world(w); draw_world(w, win); if(wgetch(win) != ERR){ break; } } nodelay(win, 0); curs_set(1); return; }
void draw_game(void) { switch(state) { case GAME_STATE_WORLD : draw_world(game_world); draw_player(game_player, game_world); break; case GAME_STATE_MENU : draw_menu(10, 10); break; case GAME_STATE_MAP : draw_scanner(game_scanner, game_world, 10, 10, game_player->x, game_player->y); break; case GAME_STATE_STATUS : draw_actor_status(10, 10, game_player->h); break; case GAME_STATE_BATTLE : draw_world(game_world); draw_battle(game_battle); break; default : break; } }
int main(){ players.push_back(player(3,6,0,1)); players.push_back(player(4,0,1,-1)); players.push_back(player(3,0,0,1)); players.push_back(player(0,6,0,-1)); while (true){ build_world(); draw_world(); sleep(1); } return 0; }
/* Pointless Idea, it'd be cool to run a '###' across the grid, in such a way that it moved one block at a time, or something. */ int main(int argc, char **argv){ srandom(time(NULL)); //add options later ncurses_init(); atexit((void(*)(void))endwin); sigaction(SIGTERM, &interupt_act, NULL); world *w = init_world(term_rows, term_cols); randomize_grid(w); draw_world(w, stdscr); while(1){ wmove(stdscr, 0, 0); setup_initial_conditons(w, stdscr); run_life(w, stdscr); } }
int medlisp_update_screen() { int vn; if (!render_3d_in_big_window) for (vn=0;vn<N_views;vn++) if (Views[vn]->ev_changed || (Update_flags & (UF_WORLD_CHANGED|UF_VIEWPOINT_MOVED|UF_ED_STATE_CHANGED))) { draw_world(Views[vn]->ev_canv,Views[vn],Cursegp,Big_depth); Views[vn]->ev_changed = 0; } if (Update_flags & (UF_WORLD_CHANGED|UF_GAME_VIEW_CHANGED|UF_ED_STATE_CHANGED)) { grs_canvas temp_canvas; grs_canvas *render_canv,*show_canv; if (render_3d_in_big_window) { gr_init_sub_canvas(&temp_canvas,canv_offscreen,0,0, LargeView.ev_canv->cv_bitmap.bm_w,LargeView.ev_canv->cv_bitmap.bm_h); render_canv = &temp_canvas; show_canv = LargeView.ev_canv; } else { render_canv = VR_offscreen_buffer; show_canv = Canv_editor_game; } gr_set_current_canvas(render_canv); render_frame(0); Assert(render_canv->cv_bitmap.bm_w == show_canv->cv_bitmap.bm_w && render_canv->cv_bitmap.bm_h == show_canv->cv_bitmap.bm_h); ui_mouse_hide(); gr_bm_ubitblt(show_canv->cv_bitmap.bm_w,show_canv->cv_bitmap.bm_h, 0,0,0,0,&render_canv->cv_bitmap,&show_canv->cv_bitmap); ui_mouse_show(); } Update_flags=UF_NONE; //clear flags return 1; }
/* This is the entry-point for the game! */ void c_start(void) { // Initialize video, interrupt, timer, and keyboard subsystems init_video(); init_interrupts(); init_timer(); init_keyboard(); // Initialize game state init_player(); init_guns(); win = 0; draw_world(); draw_player(); enable_interrupts(); mainloop(); }
int main(){ //person population[STARTSIZE]; person* population=(person*)malloc(2*sizeof(person*)); int populationsize; int populationsize_old;//to compare value before and after time_passes int continue_variable; int i,j;//incides for loop int time=0; populationsize=STARTSIZE; continue_variable=0; creation(population,&populationsize); printf("%s and %s were just created\n",population[0].name,population[1].name); //time passes while(time<20){ populationsize_old=populationsize; draw_world(population,populationsize); time_passes(population,&populationsize); if(populationsize_old>populationsize){//if someone dies for(i=populationsize_old;i>0;i--){ if( population[i].gender == 0 && ( i != populationsize )){ //so if someone is dead and not the last person in the population-array for(j=i;j<populationsize;j++){ population[j]=population[j+1]; } } population= (person*) malloc(populationsize*sizeof(person)); //dynamically allocates memory to fit the size of the population } } printf("populationsize is \d", populationsize); sleep(1); time++; } free(population); return 0; }
void frame(laxion::appwindow::input_batch *input, float deltatime) { if (!s_terrain) { s_terrain = terrain::create(s_terrain_config); } int x0, y0, x1, y1; laxion::appwindow::get_client_rect(window, &x0, &y0, &x1, &y1); kosmos::render::begin(x1-x0, y1-x0, true, true, 0xff00ff); float out[16]; gtime += 0.1f * deltatime; camera_pos[0] = sinf(0.3f * gtime) * 100; camera_pos[2] = -80.0f * gtime + cosf(0.05f * gtime) * 100; camera_pos[1] = terrain::get_terrain_height(s_terrain, camera_pos[0], camera_pos[2]) + 1.0f; camera_matrix(out); glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); draw_world(out); kosmos::render::end(); if (liveupdate) { if (!putki::liveupdate::connected(liveupdate)) { putki::liveupdate::disconnect(liveupdate); liveupdate = 0; } else { putki::liveupdate::update(liveupdate); } } }
int medlisp_update_screen() { int vn; #if 1 //def OGL Update_flags = UF_ALL; #endif if (!render_3d_in_big_window) for (vn=0;vn<N_views;vn++) if (Views[vn]->ev_changed || (Update_flags & (UF_WORLD_CHANGED|UF_VIEWPOINT_MOVED|UF_ED_STATE_CHANGED))) { draw_world(Views[vn]->ev_canv,Views[vn],Cursegp,Big_depth); Views[vn]->ev_changed = 0; } if (Update_flags & (UF_WORLD_CHANGED|UF_GAME_VIEW_CHANGED|UF_ED_STATE_CHANGED)) { grs_canvas *render_canv,*show_canv; if (render_3d_in_big_window) { render_canv = LargeView.ev_canv; show_canv = LargeView.ev_canv; } else { render_canv = Canv_editor_game; show_canv = Canv_editor_game; } gr_set_current_canvas(render_canv); render_frame(0, 0); Assert(render_canv->cv_bitmap.bm_w == show_canv->cv_bitmap.bm_w && render_canv->cv_bitmap.bm_h == show_canv->cv_bitmap.bm_h); } Update_flags=UF_NONE; //clear flags return 1; }
//interactively read initial conditons from the user void setup_initial_conditons(world *w, WINDOW *win){ keypad(win, 1); int c,y,x,ymax,xmax; getyx(win, y ,x); getmaxyx(win, ymax, xmax); wmove(win, 0, 0); while(c = wgetch(win)){ switch(c){ case KEY_UP: // case KEY_SUP: y = y > 0 ? y-1 : ymax; break; case KEY_DOWN: // case KEY_SDOWN: y = y < ymax ? y+1 : 0; break; case KEY_LEFT: // case KEY_SLEFT: x = x > 0 ? x-1 : xmax; break; case KEY_RIGHT: // case KEY_SRIGHT: x = x < xmax ? x+1 : 0; break; case KEY_BACKSPACE: reset_grid(w); draw_world(w, win); x = y = 0; break; case '+': wait_time += 0.05; break; case '-': wait_time -= 0.05; break; case 'q': exit(0); case 'r': randomize_grid(w); draw_world(w, win); x = y = 0; break; case 's': step_world(w); draw_world(w, win); break; case '\r': case '\n': waddch(win, '#'); w->grid[y*w->cols + x] = 1; break; case ' ': return; } wmove(win, y ,x); // if(c == KEY_SUP || c == KEY_SDOWN | c == KEY_SLEFT || c = KEY_SRIGHT){ // waddch(win, '#'); // wmove(win, y ,x); // } } }
void light_transport(int value) { draw_world(); glutTimerFunc(update_timer,light_transport,0); }
void draw_scene(void) { draw_world(); }
void draw_world_from_game(void) { if (ModeFlag == 2) draw_world(Views[0]->ev_canv,Views[0],Cursegp,Big_depth); }
/* Main method runs initialize() and update() */ int main(int argc, char **argv) { /* get num bodies from the command line */ int num_bodies; num_bodies = (argc == 2) ? atoi(argv[1]) : DEF_NUM_BODIES; printf("Universe has %d bodies.\n", num_bodies); /* set up the universe */ time_t cur_time; time(&cur_time); srand48((long)cur_time); // seed the RNG used in create_world struct world *world = create_world(num_bodies); /* set up graphics using Xlib */ Display *disp = XOpenDisplay(NULL); int scr = DefaultScreen(disp); Window win = XCreateSimpleWindow( disp, RootWindow(disp, scr), 0, 0, WIDTH, HEIGHT, 0, BlackPixel(disp, scr), WhitePixel(disp, scr)); XStoreName(disp, win, "N-Body Simulator"); Pixmap back_buf = XCreatePixmap(disp, RootWindow(disp, scr), WIDTH, HEIGHT, DefaultDepth(disp, scr)); GC gc = XCreateGC(disp, back_buf, 0, 0); // Make sure we're only looking for messages about closing the window Atom del_window = XInternAtom(disp, "WM_DELETE_WINDOW", 0); XSetWMProtocols(disp, win, &del_window, 1); XSelectInput(disp, win, StructureNotifyMask); XMapWindow(disp, win); XEvent event; // wait until window is mapped while (1) { XNextEvent(disp, &event); if (event.type == MapNotify) { break; } } struct timespec delay={0, 1000000000 / 60}; // for 60 FPS struct timespec remaining; int frame_num = 0; while (1) { // check if the window has been closed if (XCheckTypedEvent(disp, ClientMessage, &event)) { break; } // we first draw to the back buffer then copy it to the front (`win`) draw_world(disp, back_buf, gc, world); XCopyArea(disp, back_buf, win, gc, 0, 0, WIDTH, HEIGHT, 0, 0); step_world(world, 0.1); frame_num++; nanosleep(&delay, &remaining); } XFreeGC(disp, gc); XFreePixmap(disp, back_buf); XDestroyWindow(disp, win); XCloseDisplay(disp); return 0; }
int main( int argc, char *argv[ ] ) { srand(time(NULL));//Init randome seed. memset(world, 0, sizeof(world)); SDL_Window *window; SDL_Surface *screen; if( SDL_Init( SDL_INIT_VIDEO ) == -1 ) { printf( "Can't init SDL: %s\n", SDL_GetError( ) ); return EXIT_FAILURE; } atexit( SDL_Quit ); window = SDL_CreateWindow("Ma fenêtre de jeu", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH, SCREEN_HEIGHT, 0 ); screen = SDL_GetWindowSurface(window); if( screen == NULL ) { printf( "Can't set video mode: %s\n", SDL_GetError( ) ); return EXIT_FAILURE; } int xspeed=0, yspeed=0; // Main loop SDL_Event event; draw_world(screen, world); while(1) { if(xspeed != 0 || yspeed != 0) { if(move_snake(screen, xspeed, yspeed) == -1) { printf("Game Over !!!\n"); return EXIT_SUCCESS;// Quit the program break; } } // Check for messages if (SDL_PollEvent(&event)) { // Check for the quit message switch (event.type) { case SDL_QUIT: SDL_Quit(); return EXIT_SUCCESS;// Quit the program break; case SDL_KEYDOWN: printf("keydown %d\n", event.key.keysym.sym); switch(event.key.keysym.sym) { case SDLK_DOWN: if(yspeed != -SPEED_RATE) yspeed = SPEED_RATE; xspeed = 0; break; case SDLK_UP: if(yspeed != SPEED_RATE) yspeed = -SPEED_RATE; xspeed = 0; break; case SDLK_RIGHT: if(xspeed != -SPEED_RATE) xspeed = SPEED_RATE; yspeed = 0; break; case SDLK_LEFT: if(xspeed != SPEED_RATE) xspeed = -SPEED_RATE; yspeed = 0; break; case SDLK_ESCAPE: SDL_Quit(); return EXIT_SUCCESS;// Quit the program break; } printf("xspeed %d yspeed %d \n", xspeed, yspeed); break; } } //Update the display SDL_UpdateWindowSurface(window); } // Tell the SDL to clean up and shut down SDL_Quit(); return EXIT_SUCCESS; }
int main(){ //printf("at the beginning of main"); person* firstperson; person* personlist; person* current; int intmap[HEIGHT][WIDTH]; int clock=0; int i,j; srand(time(NULL)); //create firstperson //printf("before first creation"); //all names will be overwritten by getname() in createperson() firstperson=create_person(-110,10,' ',"God", 0,0); create_person_after(firstperson,0,10,'E',"Eve",2,5); create_person_after(firstperson,0,10,'F',"empty",4,5); create_person_after(firstperson,0,10,'F',"empty",4,5); create_person_after(firstperson,0,10,'F',"empty",4,5); create_person_after(firstperson,0,1,'M',"empty",4,5); create_person_after(firstperson,0,1,'M',"empty",4,5); create_person_after(firstperson,0,1,'M',"empty",4,5); while(clock<TIME){ //initialize intmap as empty for(i=0;i<HEIGHT;i++){ for(j=0;j<WIDTH;j++){ intmap[i][j]=0; } } personlist=firstperson; while(personlist){ intmap[personlist->y][personlist->x]+=personlist->gender; //printf("value of intmap is %d\n",intmap[personlist->y][personlist->x]); if(intmap[personlist->y][personlist->x]==11&&personlist->fertility){ //because women are after men in the linked-list this should ensure that only womeng get pregnant. //if a pregnant woman has sex, her child will be born sooner... i guess that's a feature then personlist->pregnancy+=1; printf("%s just got pregnant\n",personlist->name); } printf("%s has gender %d\n",personlist->name,personlist->gender); personlist=personlist->next; } //printf("intmap for starting point is %d", intmap[2][4]); printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); draw_world(firstperson,intmap); //printf("before time passes\n"); time_passes(firstperson); //printf("after time passes\n"); sleep(SLEEP); //printf("after sleep\n"); clock++; if(CONTROL!=0){ printf("there is no one left alive i'm afraid\n you...won i guess?"); break; } printf("the time is %d\n",clock); } personlist=firstperson->next; free(firstperson); while(personlist){ printf("%s with gender=%d\n",personlist->name,personlist->gender); free(personlist); personlist=personlist->next; } return 0; }
void draw(void) { draw_init(); draw_world(); stbwingraph_SwapBuffers(NULL); }