void game_over() { vga_clear(); offset(6, graphic_game_over, vga_get_width()/2 - 150, vga_get_height()/2 - 150); vga_addpoly(6, graphic_game_over); vga_sync(); while(1); }
void win() { vga_clear(); offset(4, graphic_vict, vga_get_width()/2 - 150, vga_get_height()/2 - 150); vga_addpoly(4, graphic_vict); vga_sync(); while(1); }
void game_main() { keymap_t keys; vga_init(); go_initialize(); srand(time(NULL)); game_object_t* ship_o = go_getempty(); ship_o->enabled = 1; ship_o->poly_points = 4; ship_o->poly = ship; ship_o->center_point.x = 320; ship_o->center_point.y = 240; ship_o->location.x = vga_get_width()/2 - 320; ship_o->location.y = vga_get_height()/2 - 240; ship_o->identifier = OI_SHIP; int i; for (i = 0; i < 4; i++){ go_createasteroid(1); } while(1) { go_tick(); vga_sync(); keys = input_get_keys(); if(keys & KEY_SHOOT) { if (shoot_limit == 0) { shoot_limit = 25; game_object_t* bullet_o = go_getempty(); bullet_o->location.x = ship_o->location.x; bullet_o->location.y = ship_o->location.y; bullet_o->xvel = bullet_speed * cosine(ship_o->angle + 4.71); bullet_o->yvel = bullet_speed * sine(ship_o->angle + 4.71); bullet_o->center_point.x = 320; bullet_o->center_point.y = 240; bullet_o->angle = ship_o->angle; bullet_o->enabled = 1; bullet_o->poly = bullet_p; bullet_o->poly_points = 2; bullet_o->nowrap = 1; bullet_o->identifier = OI_BULLET; } } if(keys & KEY_LEFT) { ship_o->angle -= rotate_amount; } if(keys & KEY_RIGHT) { ship_o->angle += rotate_amount; } if(keys & KEY_UP) { //TODO: lookup table ship_o->xvel += ship_accel * cosine(ship_o->angle + 4.71); ship_o->yvel += ship_accel * sine(ship_o->angle + 4.71); } /*if(keys & KEY_DOWN) { ship_o->angle += 3.14; }*/ if (shoot_limit > 0) shoot_limit--; if (go_currentstate == STATE_DEAD) game_over(); if (go_currentstate == STATE_VICT) win(); vga_clear(); go_draw(); } }
void add_window(int pid, wm_reg_t *req) { char fname[255]; int fd; unsigned int *buf; win_info_t *win_info; /* allocate win_info structure */ win_info = malloc(sizeof(win_info_t)); /* get window shared file name */ get_win_shfname(fname, pid, req->id); /* open the shared file */ fd = open(fname, 0); /* map the pixel buffer */ buf = mmap(NULL, req->width*req->height*4, MMAP_TYPE_FILE, MMAP_FLAGS_SHARED, fd, 0); /* close the shared file */ close(fd); /* initialize win_info structure */ win_info->next = first; win_info->pid = pid; win_info->wid = req->id; win_info->visible = req->visible; strcpy(win_info->title, req->title); strcpy(win_info->iconfile, req->iconfile); win_info->ico = parse_png(win_info->iconfile); /* allocate pixel buffer structure */ win_info->pixbuf = malloc(sizeof(pixbuf_t)); /* initialize pixbuf */ win_info->pixbuf->width = req->width; win_info->pixbuf->height = req->height; win_info->pixbuf->buf = buf; /* x and y */ if (req->x == -1) { /* generate random offsets */ rand += 100; if (rand >= vga_get_width() || rand >= vga_get_height()) rand = 100; win_info->x = rand; win_info->y = rand; } else if (req->x == -2) { win_info->x = (get_osm()->width-req->width)/2; win_info->y = (get_osm()->height-req->height)/2; } else { win_info->x = req->x; win_info->y = req->y; } /* add to the linked list */ first = win_info; wincount++; /* update screen if window is visible */ /* if (req->visible) */ draw_window(win_info, 1, 1); }