char *exec_menu() { SDL_Surface *screen; SDL_Surface *background; SDL_Rect pos; int continuer; char *ret; if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0) err_SDL("Can't init SDL", 1); SDL_WM_SetIcon(SDL_LoadBMP("image/DonkeyKong2.bmp"), NULL); screen = SDL_SetVideoMode(MWIN_WIDTH, MWIN_HEIGHT, WIN_COLOR, SDL_HWSURFACE | SDL_DOUBLEBUF ); SDL_WM_SetCaption("Epikong", NULL); background = img_load(MENU_BACK); pos.x = 0; pos.y = 0; while (continuer) { SDL_BlitSurface(background, NULL, screen, &pos); disp_menu(screen); ret = menu_loop(screen); if (ret) continuer = 0; } SDL_Quit(); return (ret); }
int launch_vm(t_param *param) { t_vm *vm; int i; if ((vm = my_malloc(sizeof(t_vm), "Error: fail to malloc vm\n")) == 0) return (1); vm->screen = SDL_SetVideoMode(MEM_SIZE / NB_COL * WIDTH + DECAL, NB_COL * WIDTH, 32, SDL_HWSURFACE | SDL_DOUBLEBUF); SDL_WM_SetCaption("Corewar", NULL); if (vm->screen == NULL) err_SDL(); vm->police = TTF_OpenFont("arial.ttf", 20); vm->param = param; vm->cycle = 0; vm->cycle_to_die = CYCLE_TO_DIE; vm->nb_live = 0; owner_set(vm->mem_owner, -1, 0, MEM_SIZE); my_memset(vm->register_player, 0, (MAX_PLAYER + 1) * sizeof(char)); i = 0; while (i < MAX_PROG_NUMBER) vm->progs_live[i++] = -1; if (load_all_programs(vm) != 0) return (1); my_printf("%d program(s) loaded\n", vm->prog_list->nb_elm); if (param->debug == 1) dump_memory(vm->memory); pause_vm(vm, 1); vm_run(vm); pause_vm(vm, 0); if (param->debug == 1) dump_memory(vm->memory); TTF_CloseFont(vm->police); return (0); }
int exec_map(char *path) { int result; SDL_Surface *screen; t_map *map; map = check_map(get_map(path)); if (!map) return (EXIT_FAILURE); if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0) err_SDL("Can't init SDL", 1); screen = creat_win(map); if (!screen) err_SDL("screen load fail", 1); result = exec_fct(screen, map); SDL_FreeSurface(screen); SDL_Quit(); return (result); }