void sample_load_cb(GtkWidget * widget, gpointer data) { GtkWidget *dialog; gchar load_current_file [512]; gint win_width, win_height; GSList *filenames, *list; filenames = list = NULL; win_width = gdk_screen_width () / 2; win_height = gdk_screen_height () / 2; dialog = gtk_file_chooser_dialog_new (_("Sweep: Open Files"), data, GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL); gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER); gtk_widget_set_size_request (dialog, win_width, win_height); gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE); sweep_set_window_icon (GTK_WINDOW(dialog)); attach_window_close_accel(GTK_WINDOW(dialog)); prefs_get_string (LAST_LOAD_KEY, load_current_file, sizeof (load_current_file), ""); if (load_current_file [0]) { gtk_file_chooser_set_filename (GTK_FILE_CHOOSER(dialog), load_current_file); } if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) { filenames = gtk_file_chooser_get_filenames (GTK_FILE_CHOOSER(dialog)); for (list = filenames; list; list = list->next) { if (list->data) { sample_load ((gchar *)list->data); g_free (list->data); } } if (filenames) g_slist_free(filenames); } else { /* do nothing so exit */ sample_bank_remove(NULL); } gtk_widget_destroy (dialog); }
void recent_chooser_menu_activated_cb(GtkRecentChooser *chooser, gpointer user_data) { gchar *uri = NULL; gchar *path = NULL; uri = gtk_recent_chooser_get_current_uri(chooser); path = g_filename_from_uri(uri, NULL, NULL); sample_load(path); g_free (path); }
static PyObject *cboodle_load_sample(PyObject *self, PyObject *args) { int retval; sample_t *samp; char *sampstr; int samplen; int framerate; long numframes; void *data; int datalen; long loopstart, loopend; int numchannels; int samplebits; int issigned, isbigend; if (!PyArg_ParseTuple(args, "s#(ils#lliiii):load_sample", &sampstr, &samplen, &framerate, &numframes, &data, &datalen, &loopstart, &loopend, &numchannels, &samplebits, &issigned, &isbigend)) { return NULL; } if (!sampstr || samplen != sizeof(sample_t *)) { PyErr_SetString(PyExc_TypeError, "load_sample: argument must be a string returned by new_sample"); return NULL; } samp = *((sample_t **)sampstr); if (!data || datalen != numframes * numchannels * (samplebits/8)) { PyErr_SetString(PyExc_ValueError, "load_sample: data length does not match frame count and frame size"); return NULL; } /* printf("load_sample(samp %p, framerate %d, numframes %ld," " data %p (len %d), loop %ld...%ld, numchannels %d, samplebits %d," " issigned %d, isbigend %d\n", samp, framerate, numframes, data, datalen, loopstart, loopend, numchannels, samplebits, issigned, isbigend); */ retval = sample_load(samp, framerate, numframes, data, loopstart, loopend, numchannels, samplebits, issigned, isbigend); return Py_BuildValue("i", retval); }
char conf_load(skin* p_skin, int skin_index, SDL_Renderer *renderer) { char tmp_path[BUFSIZ]; memset(tmp_path, '\0', BUFSIZ * sizeof(char)); append(tmp_path, "./res/", p_skin[skin_index].name, "/", p_skin[skin_index].gfx, NULL); gfx = image_load(tmp_path, renderer); if(!gfx)return 0; memset(tmp_path, '\0', BUFSIZ * sizeof(char)); append(tmp_path, "./res/", p_skin[skin_index].name, "/", p_skin[skin_index].bg, NULL); bg = image_load(tmp_path, renderer); if(!bg)return 0; memset(tmp_path, '\0', BUFSIZ * sizeof(char)); append(tmp_path, "./res/", p_skin[skin_index].name, "/", p_skin[skin_index].menu, NULL); menu = image_load(tmp_path, renderer); if(!menu)return 0; memset(tmp_path, '\0', BUFSIZ * sizeof(char)); append(tmp_path, "./res/", p_skin[skin_index].name, "/", p_skin[skin_index].music, NULL); music = music_load(tmp_path); memset(tmp_path, '\0', BUFSIZ * sizeof(char)); append(tmp_path, "./res/", p_skin[skin_index].name, "/", "start.wav", NULL); start = sample_load(tmp_path); memset(tmp_path, '\0', BUFSIZ * sizeof(char)); append(tmp_path, "./res/", p_skin[skin_index].name, "/", "pause.wav", NULL); pause = sample_load(tmp_path); memset(tmp_path, '\0', BUFSIZ * sizeof(char)); append(tmp_path, "./res/", p_skin[skin_index].name, "/", "line.wav", NULL); line = sample_load(tmp_path); memset(tmp_path, '\0', BUFSIZ * sizeof(char)); append(tmp_path, "./res/", p_skin[skin_index].name, "/", "double.wav", NULL); doubles = sample_load(tmp_path); memset(tmp_path, '\0', BUFSIZ * sizeof(char)); append(tmp_path, "./res/", p_skin[skin_index].name, "/", "triple.wav", NULL); triples = sample_load(tmp_path); memset(tmp_path, '\0', BUFSIZ * sizeof(char)); append(tmp_path, "./res/", p_skin[skin_index].name, "/", "tetris.wav", NULL); tetris = sample_load(tmp_path); memset(tmp_path, '\0', BUFSIZ * sizeof(char)); append(tmp_path, "./res/", p_skin[skin_index].name, "/", "put.wav", NULL); put = sample_load(tmp_path); memset(tmp_path, '\0', BUFSIZ * sizeof(char)); append(tmp_path, "./res/", p_skin[skin_index].name, "/", "gameover.wav", NULL); gameover = sample_load(tmp_path); memset(tmp_path, '\0', BUFSIZ * sizeof(char)); append(tmp_path, "./res/", p_skin[skin_index].name, "/", "rotate.wav", NULL); rotate = sample_load(tmp_path); memset(tmp_path, '\0', BUFSIZ * sizeof(char)); return 1; }
int state_options(SDL_Surface *screen) { TTF_Font *font_menu = font_load("res/asia.ttf", 50); image *bg_image = image_load("res/options.jpg"); Mix_Chunk *select = sample_load("res/select.wav"); int i; //int initial_unit_nb = g_game.unit_nb; int font_quality = SOLID; int choice_current=1; SDL_Rect cur_pos; bool done = false; cur_pos.x = 10; cur_pos.y = 0; char sz_choice[20]; #ifdef GEKKO unsigned int start=0; int timerset = false; #endif SDL_EnableKeyRepeat(50, 10); while (!done) { #ifdef GEKKO unsigned int start=0; if (!timerset) { timerset=true; start=SDL_GetTicks(); } unsigned int now=SDL_GetTicks(); if ((now-start)>50) { timerset=false; SDL_JoystickUpdate(); int joystate = SDL_JoystickGetHat(g_game.v_unit[0].joystick, 0); switch (joystate){ case SDL_HAT_DOWN: if (choice_current <= 1){ sample_play(select); choice_current++; } break; case SDL_HAT_UP: if (choice_current > 1){ sample_play(select); choice_current--; } break; case SDL_HAT_LEFT: if (choice_current == 2) { if (g_game.block_fill >= 0.01) g_game.block_fill -= 0.01; } else if (choice_current == 1) { if (g_game.unit_nb > 2) { g_game.unit_nb -= 1; } } break; case SDL_HAT_RIGHT: if (choice_current == 2) { if (g_game.block_fill < 0.99) g_game.block_fill += 0.01; } else if (choice_current == 1) { if (g_game.unit_nb < UNIT_MAX) { g_game.unit_nb++; } } break; default: break; } } #endif SDL_Event event; while (SDL_PollEvent(&event)) { switch ( event.type ) { case SDL_QUIT: exit(EXIT_SUCCESS); break; case SDL_JOYBUTTONDOWN: if(event.jbutton.button == 6){ done = true; } break; case SDL_KEYDOWN: switch ( event.key.keysym.sym ) { case SDLK_DOWN: if (choice_current <= 1){ sample_play(select); choice_current++; } break; case SDLK_UP: if (choice_current > 1) { sample_play(select); choice_current--; } break; case SDLK_LEFT: if (choice_current == 2) { if (g_game.block_fill >= 0.01) g_game.block_fill -= 0.01; } else if (choice_current == 1) { if (g_game.unit_nb > 2) { g_game.unit_nb--; } } break; case SDLK_RIGHT: if (choice_current == 2) { if (g_game.block_fill < 0.99) g_game.block_fill += 0.01; } else if (choice_current == 1) { if (g_game.unit_nb < UNIT_MAX) { g_game.unit_nb++; } } break; case SDLK_ESCAPE: done = true; break; default: break; } break; } if(event.type == SDL_JOYBUTTONDOWN && event.jbutton.button == 6)done=true; } SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 20, 20, 20)); image_draw(bg_image, screen, 0, 0); for (i=1;i<=2;i++) { if (i == 1) { sprintf(sz_choice, "%s < %.d >", "Player", g_game.unit_nb); } else if ( i == 2) { sprintf(sz_choice, "%s < %.0f%% >", "Block fill", g_game.block_fill * 100); } if (choice_current == i) { font_quality = SHADED; } else font_quality = SOLID; cur_pos.y = i*100; SDL_Surface *font_surface; font_surface = font_create_surface(font_menu, 250, 120, 35, 10, 100, 100, 100, 0, sz_choice, font_quality); SDL_BlitSurface(font_surface, NULL, screen, &cur_pos); SDL_FreeSurface(font_surface); } SDL_Flip(screen); } TTF_CloseFont(font_menu); SDL_FreeSurface(bg_image->surface); SDL_EnableKeyRepeat(0, 0); return OPTION; }
int state_in_game(SDL_Surface *screen) { SDL_Rect srcrect = {0, 0, 480, 480}; //the part of the screen to be stretched, must be sup 0 and inf screen surface Height and Width SDL_Rect dstrect = set_rect(0, 0, SCREEN_HEIGHT, SCREEN_WIDTH); //equals screen resolution int bomb_nb=0; int flame_nb=0; bool done = false; int i=0; //generic accumulator 1 int j=0; //generic accumulator 2 int k=0; //unit accumulator int tick_count=0; int tick_trigger=0; int time_elapsed=0; //time elapsed in this round (in secondes) int last_time=0; int current_game_status=-1; timer *timer_battle = timer_init(); timer_start(timer_battle); // load sample.wav in to sample Mix_Chunk *sample = sample_load("res/boom.wav"); Mix_Music* music = music_load("res/music.xm"); music_play(music); //initialize map map *p_map = malloc(sizeof(map)); p_map->tile_height = 32; p_map->tile_width = 32; map_load_level(p_map, "res/level_01.map"); p_map->p_chipset = image_load("res/classic.png"); SDL_Surface* surface_menu = IMG_Load("./res/menu.png"); SDL_SetColorKey(surface_menu, SDL_SRCCOLORKEY, SDL_MapRGB(surface_menu->format, 255, 0, 255)); for (k=0;k<g_game.unit_nb;k++) { unit_tile_protect(g_game.v_unit+k, p_map); } int block_nb = map_block_add(p_map, g_game.block_fill, .5); ///@todo the disp % is not implemented yet int panel_nb = panel_add(g_game.v_panel, p_map, block_nb); int random_comment = rand() % 9; char sz_comment[32]; SDL_Rect pos_comment = set_rect(10, 465, 0, 0); int comment_time_elapsed; timer *timer_comment = timer_init(); //Menu TTF_Font *font_menu = font_load("res/asia.ttf", 20); TTF_Font *font_result = font_load("res/asia.ttf", 75); SDL_Rect cur_pos; cur_pos.x = 42; cur_pos.y = 425; char sz_time[10]; while (!done) { SDL_Event event; SDL_JoystickUpdate(); while(SDL_PollEvent(&event)){ for (k=0;k<g_game.unit_nb;k++) { if (!g_game.v_unit[k].is_dead) { unit_handle_key(g_game.v_unit+k, &event, k, g_game.v_bomb, p_map, &bomb_nb); } } if(event.type == SDL_QUIT || ((event.type == SDL_KEYDOWN) && (event.key.keysym.sym == SDLK_ESCAPE)) || (event.type == SDL_JOYBUTTONDOWN && event.jbutton.button == 6)){ done = true; current_game_status = MAIN_MENU; } else if((event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_RETURN)|| (event.type == SDL_JOYBUTTONDOWN && event.jbutton.button == 5)){ Mix_PauseMusic(); state_paused(screen); Mix_ResumeMusic(); } } for (k=0;k<g_game.unit_nb;k++){ if(!g_game.v_unit[k].use_keyboard){ int joystate = SDL_JoystickGetHat(g_game.v_unit[k].joystick, 0); switch (joystate){ case SDL_HAT_DOWN: unit_set_vel_y(g_game.v_unit+k, g_game.v_unit[k].speed); unit_set_vel_x(g_game.v_unit+k, 0); g_game.v_unit[k].p_sprite->animation_current = DOWN; break; case SDL_HAT_UP: unit_set_vel_y(g_game.v_unit+k, -g_game.v_unit[k].speed); unit_set_vel_x(g_game.v_unit+k, 0); g_game.v_unit[k].p_sprite->animation_current = UP; break; case SDL_HAT_RIGHT: unit_set_vel_x(g_game.v_unit+k, g_game.v_unit[k].speed); unit_set_vel_y(g_game.v_unit+k, 0); g_game.v_unit[k].p_sprite->animation_current = RIGHT; break; case SDL_HAT_LEFT: unit_set_vel_x(g_game.v_unit+k, -g_game.v_unit[k].speed); unit_set_vel_y(g_game.v_unit+k, 0); g_game.v_unit[k].p_sprite->animation_current = LEFT; break; default: if ( g_game.v_unit[k].vel_x != 0 ){ unit_set_vel_x(g_game.v_unit+k, 0); g_game.v_unit[k].p_sprite->v_anim[g_game.v_unit[k].p_sprite->animation_current].frame_current = 1; } if ( g_game.v_unit[k].vel_y != 0 ){ unit_set_vel_y(g_game.v_unit+k, 0); g_game.v_unit[k].p_sprite->v_anim[g_game.v_unit[k].p_sprite->animation_current].frame_current = 1; } break; } } } tick_count = SDL_GetTicks(); if (tick_count > tick_trigger / 60){ tick_trigger = tick_count; SDL_FillRect(backbuffer, 0, SDL_MapRGB(backbuffer->format, 10, 20, 80)); //draw the map map_draw(p_map, backbuffer); for (i=0;i<panel_nb;i++) { if(p_map->pp_tile[g_game.v_panel[i]->p_sprite->y / TILE_SIZE][g_game.v_panel[i]->p_sprite->x / TILE_SIZE].type != BLOCK)panel_draw(g_game.v_panel[i], backbuffer); } //check panels for (i=0;i<panel_nb;i++) { // for all units for (k=0;k<g_game.unit_nb;k++) { //Check for bonus if (g_game.v_panel[i]->p_sprite->y / TILE_SIZE == unit_get_bounding_index_center_y(g_game.v_unit+k) && (g_game.v_panel[i]->p_sprite->x / TILE_SIZE == unit_get_bounding_index_center_x(g_game.v_unit+k))) { panel_apply(g_game.v_panel[i], g_game.v_unit+k); panel_free(g_game.v_panel[i]); panel_nb--; //Left shift the vector for (j=i;j<panel_nb;j++) { g_game.v_panel[j] = g_game.v_panel[j+1]; } } } } //Draw and update bombs for (i=0;i<bomb_nb;i++) { bomb_draw(g_game.v_bomb[i], backbuffer); anim_sprite_update_frame(g_game.v_bomb[i]->p_sprite); bomb_update_timer(g_game.v_bomb[i]); if ((g_game.v_bomb[i]->time_left <= 0) || (p_map->pp_tile[g_game.v_bomb[i]->p_sprite->y / TILE_SIZE][g_game.v_bomb[i]->p_sprite->x / TILE_SIZE].type == FLAME)) { sample_play(sample); bomb_explode(g_game.v_bomb[i], p_map, g_game.v_flame, &flame_nb); bomb_nb--; bomb_free(g_game.v_bomb[i]); //Left shift the vector for (j=i;j<bomb_nb;j++) { g_game.v_bomb[j] = g_game.v_bomb[j+1]; } } } //Check flame for (i=0;i<p_map->height;i++) { for (j=0;j<p_map->width[i];j++) { // for all units, check if hitten (if unit center is on a tile with a flame flag) for (k=0;k<g_game.unit_nb;k++) { if ((p_map->pp_tile[i][j].type == FLAME) && ((unit_get_index_x(g_game.v_unit+k) == j) && (unit_get_index_y(g_game.v_unit+k) == i)) && g_game.v_unit[k].is_dead == false) { g_game.v_unit[k].is_dead = true; timer_start(timer_comment); switch(random_comment) { case(0):sprintf(sz_comment, "Say goodbye, %s ", g_game.v_unit[k].name); break; case(1):sprintf(sz_comment, "burn %s, burn ! ", g_game.v_unit[k].name); break; case(2):sprintf(sz_comment, "%s vanished !!!!!! ", g_game.v_unit[k].name); break; case(3):sprintf(sz_comment, "unit_free(%s); //^^ ", g_game.v_unit[k].name); break; case(4):sprintf(sz_comment, "%s ? Where are you ? ", g_game.v_unit[k].name); break; case(5):sprintf(sz_comment, "%s was a good guy ", g_game.v_unit[k].name); break; case(6):sprintf(sz_comment, "HE says : \"HELLO, %s\" ", g_game.v_unit[k].name); break; case(7):sprintf(sz_comment, "%s has meet his programmer ", g_game.v_unit[k].name); break; case(8):sprintf(sz_comment, "$ %s>/dev/null ", g_game.v_unit[k].name); break; case(9):sprintf(sz_comment, "%s was not ignifugated ", g_game.v_unit[k].name); break; } } } } } //Draw and update flames for (i=0;i<flame_nb;i++) { flame_draw(g_game.v_flame[i], p_map, backbuffer); g_game.v_flame[i]->time_left--; if (g_game.v_flame[i]->time_left <= 0) { flame_free(g_game.v_flame[i], p_map); flame_nb--; //Left shift the vector for (j=i;j<flame_nb;j++) { g_game.v_flame[j] = g_game.v_flame[j+1]; } } } for (k=0;k<g_game.unit_nb;k++) { if (!g_game.v_unit[k].is_dead) { unit_calc_bounding_box(g_game.v_unit+k); unit_update(g_game.v_unit+k, p_map); } } // draw and update units unit_draw_from_z_index(g_game.v_unit, g_game.unit_nb, backbuffer); //Change every 1 second time_elapsed = timer_get_ticks (timer_battle) / 1000; if (time_elapsed != last_time){ last_time = time_elapsed; //Update current time /* Check if any unit won This function is performed every second in order to dont call it to often, and have a little delay if two or more units died almost in the same time (even ms, in the case a unit is at the left of a bomb and an other at the right, the right unit win because the flame is first put to the left...) */ int unit_win; unit_win = unit_check_victory(g_game.v_unit, g_game.unit_nb); if (unit_win >= 0) { //print win, sound, etc g_game.v_unit[unit_win].victory++; time_elapsed = 0; ///@todo set a victories limit (from 1 to 5) and display a special image if win... for the moment, another battle font_printf(font_result, TILE_SIZE * 2, TILE_SIZE * 5, 50, 150, 100, backbuffer, "%s wins", g_game.v_unit[unit_win].name); done = true; current_game_status = IN_GAME; SDL_SoftStretch(backbuffer, &srcrect, screen, &dstrect); SDL_Flip(screen); SDL_Delay(2000); break; } else if (unit_win == -1) { font_printf(font_result, (3)*TILE_SIZE, (6)*TILE_SIZE, 50, 150, 100, backbuffer, "DRAW !"); done = true; current_game_status = IN_GAME; SDL_SoftStretch(backbuffer, &srcrect, screen, &dstrect); SDL_Flip(screen); SDL_Delay(2000); } if (g_game.time - time_elapsed <= 0) { cur_pos.x = 240; cur_pos.y = 140; font_printf(font_result, (3)*TILE_SIZE, (6)*TILE_SIZE, 50, 150, 100, backbuffer, "TIMES UP !"); done = true; ///@todo select action in times up (blocks falling, etc) for the moment, just a draw... current_game_status = IN_GAME; SDL_SoftStretch(backbuffer, &srcrect, screen, &dstrect); SDL_Flip(screen); SDL_Delay(2000); } } //////////////////// MENU //////////////////// //TIME sprintf(sz_time, "%.3d", g_game.time - time_elapsed); SDL_Surface *surface_time = font_create_surface(font_menu, 200, 200, 200, 10, 100, 100, 100, 0, sz_time, SOLID); SDL_BlitSurface(surface_time, NULL, backbuffer, &cur_pos); SDL_FreeSurface(surface_time); SDL_Rect menu_src, menu_dest; menu_src.h = 32; menu_src.w = 32; menu_src.x = 0; menu_src.y = 0; menu_dest.x = 5; menu_dest.y = 420; SDL_BlitSurface(surface_menu, &menu_src, backbuffer, &menu_dest); //VICTORIES for (k=0;k<g_game.unit_nb;k++) { char sz_victory_nb[20]; SDL_Rect vic_pos = set_rect(10, 450, 0, 0); sprintf(sz_victory_nb, "%s: %d", g_game.v_unit[k].name, g_game.v_unit[k].victory); vic_pos.x += k * 100; SDL_Surface *surface_victory = font_create_surface(font_menu, 200, 200, 200, 10, 100, 100, 100, 0, sz_victory_nb, SOLID); SDL_BlitSurface(surface_victory, NULL, backbuffer, &vic_pos); SDL_FreeSurface(surface_victory); } //Comment if(timer_comment->started){ comment_time_elapsed = timer_get_ticks(timer_comment) / 1000; if (comment_time_elapsed < 3) //Display the comment 3 seconds { font_printf(font_menu, pos_comment.x, pos_comment.y, 200, 200, 200, backbuffer, sz_comment); } else{ //done timer_stop(timer_comment); random_comment = rand() % 9; } } //DEBUG #ifdef DEBUG font_printf(font_menu, 10, 10, 255, 255, 200, backbuffer, "flame nb : %d", flame_nb); font_printf(font_menu, 10, 30, 255, 255, 200, backbuffer, "bomb nb : %d", bomb_nb); font_printf(font_menu, 10, 50, 255, 255, 200, backbuffer, "unit nb : %d", g_game.unit_nb); font_printf(font_menu, 10, 70, 255, 255, 200, backbuffer, "fill nb : %.2f", g_game.block_fill); font_printf(font_menu, 10, 90, 255, 255, 200, backbuffer, "Blocks at startup : %d", block_nb); font_printf(font_menu, 10, 110, 255, 255, 200, backbuffer, "Time elapsed : %d", timer_get_ticks(timer_battle)/1000); font_printf(font_menu, 10, 130, 255, 255, 200, backbuffer, "unit 1 index: %d %d", unit_get_bounding_index_center_x(g_game.v_unit+0), unit_get_bounding_index_center_y(g_game.v_unit+0)); SDL_Rect rect = unit_get_bounding_box(g_game.v_unit+0); SDL_FillRect(backbuffer, &rect, SDL_MapRGB(backbuffer->format, 255, 255, 0)); #endif SDL_SoftStretch(backbuffer, &srcrect, screen, &dstrect); SDL_Flip(screen); }//end thick } //end while //Free the memory for (i=0;i<bomb_nb;i++) { bomb_free(g_game.v_bomb[i]); } for (i=0;i<panel_nb;i++) { panel_free(g_game.v_panel[i]); } for (i=0;i<flame_nb;i++) { flame_free(g_game.v_flame[i], p_map); } map_free(p_map); free(timer_battle); free(timer_comment); Mix_FreeChunk(sample); Mix_FreeMusic(music); TTF_CloseFont(font_menu); font_menu=NULL; // to be safe... TTF_CloseFont(font_result); font_result=NULL; // to be safe... return current_game_status; }
int state_main_menu(SDL_Surface *screen) { TTF_Font *font_menu = font_load("res/asia.ttf", 50); TTF_Font *font_credit = font_load("res/asia.ttf", 20); image *bg_image = image_load("res/main.jpg"); Mix_Chunk *select = sample_load("res/select.wav"); int i; const int item_nb = 2; int font_quality = SOLID; int choice_current=1; SDL_Rect cur_pos; bool done = false; //bool is_in_game = false; cur_pos.x = 10; cur_pos.y = 0; char sz_choice[20]; #ifdef GEKKO bool timerset = false; #endif while (!done) { #ifdef GEKKO unsigned int start=0; if (!timerset) { timerset=true; start=SDL_GetTicks(); } unsigned int now=SDL_GetTicks(); if ((now-start)>50) { timerset=false; SDL_JoystickUpdate(); int joystate = SDL_JoystickGetHat(g_game.v_unit[0].joystick, 0); switch (joystate){ case SDL_HAT_DOWN: if (choice_current < item_nb){ choice_current++; sample_play(select); } break; case SDL_HAT_UP: if (choice_current > 1){ choice_current--; sample_play(select); } break; } } #endif SDL_Event event; while (SDL_PollEvent(&event)) { switch ( event.type ) { case SDL_QUIT: done = true; break; case SDL_KEYUP: switch ( event.key.keysym.sym ) { case SDLK_DOWN: if (choice_current < item_nb){ choice_current++; sample_play(select); } break; case SDLK_UP: if (choice_current > 1){ choice_current--; sample_play(select); } break; case SDLK_RETURN: while (choice_current == IN_GAME) { unit_default_param(g_game.v_unit, g_game.unit_nb); choice_current = state_in_game(screen); if (choice_current == MAIN_MENU) //The current state is main menu, select in game as default choice and quit { choice_current = IN_GAME; break; } } if (choice_current == OPTION)state_options(screen); break; default: break; } break; case SDL_JOYBUTTONDOWN: switch(event.jbutton.button) { case 0: break; case 1: break; case 2: while (choice_current == IN_GAME) { unit_default_param(g_game.v_unit, g_game.unit_nb); choice_current = state_in_game(screen); if (choice_current == MAIN_MENU) //The current state is main menu, select in game as default choice and quit { choice_current = IN_GAME; break; } } if (choice_current == OPTION)state_options(screen); break; case 3: break; case 4: break; case 5: break; case 6: done = true; break; } break; default: break; } } SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0)); image_draw(bg_image, screen, 0, 0); int top_shift = 150; for (i=1;i<=2;i++) { if (i == 1) { strncpy(sz_choice, "Play", 20); sz_choice[19] = '\0'; } else if ( i == 2) { strncpy(sz_choice, "Options", 20); sz_choice[19] = '\0'; } if (choice_current == i) { font_quality = SHADED; } else font_quality = SOLID; cur_pos.y = top_shift + i*50; SDL_Surface *font_surface= font_create_surface(font_menu, 250, 120, 35, 10, 100, 100, 100, 0, sz_choice, font_quality); SDL_BlitSurface(font_surface, NULL, screen, &cur_pos); SDL_FreeSurface (font_surface); } cur_pos.y = 450; SDL_Surface *font_surface= font_create_surface(font_credit, 250, 120, 35, 10, 100, 100, 100, 0, "2010 - 2015 TheDrev", SOLID); SDL_BlitSurface(font_surface, NULL, screen, &cur_pos); SDL_FreeSurface (font_surface); SDL_Flip(screen); } //free font if(font_menu != NULL)TTF_CloseFont(font_menu); if(font_credit != NULL)TTF_CloseFont(font_credit); SDL_FreeSurface(bg_image->surface); Mix_FreeChunk(select); //free ressouces element* p_browse = images; while (p_browse) { ressource *res = p_browse->data; free(res->name); image_free(res->data); p_browse = p_browse->next; } linked_list_clear(&images); return EXIT_SUCCESS; }
void load_all_samples(void) { int l; sample_itexp[0] = sample_load("Itexp1"); sample_itexp[0]->left_volume = SAMPLE_VOLUME; sample_itexp[0]->right_volume = SAMPLE_VOLUME; sample_itexp[1] = sample_load("Itexp2"); sample_itexp[1]->left_volume = SAMPLE_VOLUME; sample_itexp[1]->right_volume = SAMPLE_VOLUME; sample_itexp[2] = sample_load("Itexp3"); sample_itexp[2]->left_volume = SAMPLE_VOLUME; sample_itexp[2]->right_volume = SAMPLE_VOLUME; sample_bomb[1] = sample_load("Bomb1"); sample_bomb[1]->left_volume = SAMPLE_VOLUME; sample_bomb[1]->right_volume = SAMPLE_VOLUME; sample_bomb[2] = sample_load("Bomb2"); sample_bomb[2]->left_volume = SAMPLE_VOLUME; sample_bomb[2]->right_volume = SAMPLE_VOLUME; sample_bomb[3] = sample_load("Bomb3"); sample_bomb[3]->left_volume = SAMPLE_VOLUME; sample_bomb[3]->right_volume = SAMPLE_VOLUME; sample_konsu[1] = sample_load("Guns1"); sample_konsu[1]->left_volume = SAMPLE_VOLUME; sample_konsu[1]->right_volume = SAMPLE_VOLUME; sample_konsu[2] = sample_load("Guns2"); sample_konsu[2]->left_volume = SAMPLE_VOLUME; sample_konsu[2]->right_volume = SAMPLE_VOLUME; sample_konsu[3] = sample_load("Guns3"); sample_konsu[3]->left_volume = SAMPLE_VOLUME; sample_konsu[3]->right_volume = SAMPLE_VOLUME; sample_hit[0] = sample_load("Hit1"); sample_hit[0]->left_volume = SAMPLE_VOLUME; sample_hit[0]->right_volume = SAMPLE_VOLUME; sample_hit[1] = sample_load("Hit2"); sample_hit[1]->left_volume = SAMPLE_VOLUME; sample_hit[1]->right_volume = SAMPLE_VOLUME; sample_hit[2] = sample_load("Hit3"); sample_hit[2]->left_volume = SAMPLE_VOLUME; sample_hit[2]->right_volume = SAMPLE_VOLUME; sample_hit[3] = sample_load("Hit4"); sample_hit[3]->left_volume = SAMPLE_VOLUME; sample_hit[3]->right_volume = SAMPLE_VOLUME; sample_aagun = sample_load("Aagun"); sample_aagun->left_volume = SAMPLE_VOLUME; sample_aagun->right_volume = SAMPLE_VOLUME; sample_splash[0] = sample_load("Spla1"); sample_splash[0]->left_volume = SAMPLE_VOLUME; sample_splash[0]->right_volume = SAMPLE_VOLUME; sample_splash[1] = sample_load("Spla2"); sample_splash[1]->left_volume = SAMPLE_VOLUME; sample_splash[1]->right_volume = SAMPLE_VOLUME; sample_splash[2] = sample_load("Spla3"); sample_splash[2]->left_volume = SAMPLE_VOLUME; sample_splash[2]->right_volume = SAMPLE_VOLUME; sample_hurr = sample_load("Hurr"); sample_hurr->left_volume = SAMPLE_VOLUME; sample_hurr->right_volume = SAMPLE_VOLUME; sample_itshot = sample_load("Itshot"); sample_itshot->left_volume = SAMPLE_VOLUME; sample_itshot->right_volume = SAMPLE_VOLUME; sample_spcrash = sample_load("Spcra1"); sample_spcrash->left_volume = SAMPLE_VOLUME; sample_spcrash->right_volume = SAMPLE_VOLUME; sample_crash[0] = sample_load("Crash1"); sample_crash[0]->left_volume = SAMPLE_VOLUME; sample_crash[0]->right_volume = SAMPLE_VOLUME; sample_crash[1] = sample_load("Crash2"); sample_crash[1]->left_volume = SAMPLE_VOLUME; sample_crash[1]->right_volume = SAMPLE_VOLUME; sample_alku = sample_load("Alku"); sample_alku->left_volume = 32; sample_alku->right_volume = 32; sample_die[0] = sample_load("Die1"); sample_die[1] = sample_load("Die2"); sample_die[2] = sample_load("Die3"); sample_die[3] = sample_load("Die4"); sample_die[4] = sample_load("Die5"); sample_die[5] = sample_load("Die6"); sample_die[6] = sample_load("Die7"); sample_die[7] = sample_load("Die8"); sample_die[8] = sample_load("Die9"); for (l = 0; l < 9; l++) { sample_die[l]->left_volume = SAMPLE_VOLUME - 8; sample_die[l]->right_volume = SAMPLE_VOLUME - 8; } }