static int music_list_refresh(void) { music_lock(); g_list.curr_pos = 0; if (music_maxindex() > 0) { if (g_list.is_list_playing) { if (music_play(g_list.curr_pos) < 0) { g_list.is_list_playing = false; } } else { // only load information if (music_load(g_list.curr_pos) >= 0) { musicdrv_end(); } } } else { musicdrv_end(); set_musicdrv(NULL); } g_list.first_time = true; g_shuffle.first_time = true; music_unlock(); return 0; }
int load_pmdwin(const char* cszFileName) { music_stop(); int ret = music_load((char*)cszFileName); __android_log_print(ANDROID_LOG_DEBUG, "PMDWin", "music_load: %d", ret); switch(ret) { case PMDWIN_OK: case ERR_OPEN_PPC_FILE: case WARNING_PPC_ALREADY_LOAD: case ERR_OPEN_P86_FILE: case ERR_OPEN_PPS_FILE: case WARNING_PPS_ALREADY_LOAD: case ERR_OPEN_PPZ1_FILE: case ERR_OPEN_PPZ2_FILE: case WARNING_PPZ1_ALREADY_LOAD: case WARNING_PPZ2_ALREADY_LOAD: music_start(); return 1; case ERR_WRONG_PPC_FILE: case ERR_WRONG_PPZ1_FILE: case ERR_WRONG_PPZ2_FILE: case ERR_WRONG_P86_FILE: case ERR_OPEN_MUSIC_FILE: case ERR_WRONG_MUSIC_FILE: case ERR_OUT_OF_MEMORY: case ERR_OTHER: return 0; } }
int trap_LoadMusic(lua_State *s) { MUSIC *m; const char *file; trap_args(s, "LoadMusic", "s", &file); m = music_load(file); lua_pushlightuserdata(s, m); return 1; }
/** * @brief Loads a song. * * @luaparam name Name of the song to load. * @luafunc load( name ) */ static int musicL_load( lua_State *L ) { const char* str; /* check parameters */ str = luaL_checkstring(L,1); if (music_load( str )) { NLUA_ERROR(L,"Music '%s' invalid or failed to load.", str ); return 0; } return 0; }
static int music_play(int i) { int ret; ret = music_load(i); if (ret < 0) { return ret; } ret = musicdrv_play(); return ret; }
void music_play (const char *file, const char *alias, uint32_t rate) { int audio_format = MIX_DEFAULT_FORMAT; int audio_channels = 2; int audio_buffers = 4096; if (!music_init_done) { if (Mix_OpenAudio(rate, audio_format, audio_channels, audio_buffers) != 0) { MSG_BOX("Mix_OpenAudio fail: %s %s", Mix_GetError(), SDL_GetError()); SDL_ClearError(); } music_init_done = true; } musicp music = music_load(file, alias); music_update_volume(); static int sound_loaded; if (!sound_loaded) { sound_loaded = true; sound_load_all(); } if (HEADLESS) { return; } if (Mix_FadeInMusicPos(music->music, -1, 2000, 0) == -1) { // if (Mix_PlayMusic(music->music, -1) == -1) { WARN("cannot play music %s: %s", music->tree.key, Mix_GetError()); } }
// Start playing the given track void music_start_loop(enum music_track track, int loop) { OSStatus result; // Load as necessary music_load(track); // Ensure we can we play this if (!music_files[track].sequence_loaded) return; // Keep track of if we should loop or not music_files[track].loop = loop; // Is this already playing, or would it be playing if we weren't muted? if (music_files[track].playing || music_files[track].muted) return; // TODO: fix the code that calls the music system so that we don't have two tracks running at once // For now, stop any other tracks music_stop(); // If we're muted, mark this track as muted, and bail out if (mute_music) { music_files[track].muted = 1; return; } // Initialize the music player and attach the sequence require_noerr(result = NewMusicPlayer(&music_files[track].player), fail); require_noerr(result = MusicPlayerSetSequence(music_files[track].player, music_files[track].sequence), fail); // Determine the track length if we don't know it already if (music_files[track].track_length <= 1.0) { UInt32 track_count, i; require_noerr(result = MusicSequenceGetTrackCount(music_files[track].sequence, &track_count), fail); for (i = 0; i < track_count; i++) { MusicTrack midi_track; MusicTimeStamp track_length; UInt32 property_size = sizeof(MusicTimeStamp); // Get the track within the MIDI file require_noerr(result = MusicSequenceGetIndTrack(music_files[track].sequence, i, &midi_track), fail); // Determine its length require_noerr(result = MusicTrackGetProperty(midi_track, kSequenceTrackProperty_TrackLength, &track_length, &property_size), fail); // Update the music track length if this MIDI track is longer if (track_length > music_files[track].track_length) music_files[track].track_length = track_length; } } // Seek and pre-roll to the beginning require_noerr(result = MusicPlayerSetTime(music_files[track].player, 0), fail); require_noerr(result = MusicPlayerPreroll(music_files[track].player), fail); // Start playing require_noerr(result = MusicPlayerStart(music_files[track].player), fail); // Mark as playing music_files[track].playing = 1; return; fail: WARNING2("unexpected error playing MIDI track; result=%ld", result); music_files[track].unplayable = 1; return; }
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; }
game_status state_in_game(SDL_Surface *screen, game* p_game) { int i=0; bool done=false; game_status ret_code = GAME_OVER; SDL_Rect srcrect = {0,0,160,144}; dstrect = set_rect(0,0,SCREEN_HEIGHT,SCREEN_WIDTH); #ifdef USE_LUA lua_State *L; L = lua_open(); luaopen_base(L); luaL_openlibs(L); luaopen_globals(L); luaopen_game(L); luaopen_unit(L); luaopen_sprite(L); luaopen_var(L); luaopen_map(L); //register lua functions lua_register(L ,"say", script_lua_unit_say); lua_register(L ,"unit_get_x", script_lua_unit_get_x); lua_register(L ,"unit_get_y", script_lua_unit_get_y); lua_register(L ,"unit_set_index_x", script_lua_unit_set_index_x); lua_register(L ,"unit_set_index_y", script_lua_unit_set_index_y); lua_register(L ,"event_text", script_lua_event_exec_text); lua_register(L ,"event_teleport", script_lua_event_exec_teleport); lua_register(L ,"unit_set_life", script_lua_unit_set_life); lua_register(L ,"unit_set_speed", script_lua_unit_set_speed); p_game->L = L; g_game = p_game; #endif long timelastcall=SDL_GetTicks(); if(map_get_current(p_game->p_map, p_game->cur_map)->music != NULL){ char* music = strdup(map_get_current(p_game->p_map, p_game->cur_map)->music); Mix_Music* ingame_music = music_load(music); music_play(ingame_music); } message_box* p_menu = NULL; p_menu = menu_ingame_create(p_game); bool action; while (!done) { action = false; SDL_Event event; SDL_JoystickUpdate(); while (SDL_PollEvent(&event)){ switch ( event.type ){ case SDL_QUIT: ret_code = QUIT; done = true; break; case SDL_KEYUP: switch ( event.key.keysym.sym ){ case SDLK_RETURN: switch(menu_start(get_backbuffer_surface(), p_game)){ case 0: menu_status(get_backbuffer_surface(), p_game); break; case 1: menu_save(get_backbuffer_surface(), p_game); break; case 2: ret_code = LOAD; done=true; break; } break; default:break; } break; case SDL_JOYBUTTONDOWN: switch(event.jbutton.button){ case 0: switch(menu_start(get_backbuffer_surface(), p_game)){ case 0: menu_status(get_backbuffer_surface(), p_game); break; case 1: menu_save(get_backbuffer_surface(), p_game); break; case 2: ret_code = LOAD; done=true; break; } break; case 2: action = true; break; } break; default:break; } unit_handle_key(p_game->p_unit, &event, p_game); } int joystate = SDL_JoystickGetHat(p_game->p_unit->joystick, 0); switch (joystate){ case SDL_HAT_DOWN: unit_set_vel_y(p_game->p_unit, p_game->p_unit->speed); unit_set_vel_x(p_game->p_unit, 0); p_game->p_unit->p_sprite->animation_current = DOWN; p_game->p_unit->dir = DOWN; p_game->p_unit->current_action = NOTHING; break; case SDL_HAT_UP: unit_set_vel_y(p_game->p_unit, -p_game->p_unit->speed); unit_set_vel_x(p_game->p_unit, 0); p_game->p_unit->p_sprite->animation_current = UP; p_game->p_unit->dir = UP; p_game->p_unit->current_action = NOTHING; break; case SDL_HAT_RIGHT: unit_set_vel_x(p_game->p_unit, p_game->p_unit->speed); unit_set_vel_y(p_game->p_unit, 0); p_game->p_unit->p_sprite->animation_current = RIGHT; p_game->p_unit->dir = RIGHT; p_game->p_unit->current_action = NOTHING; break; case SDL_HAT_LEFT: unit_set_vel_x(p_game->p_unit, -p_game->p_unit->speed); unit_set_vel_y(p_game->p_unit, 0); p_game->p_unit->p_sprite->animation_current = LEFT; p_game->p_unit->dir = LEFT; p_game->p_unit->current_action = NOTHING; break; default: break; } //drawing SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0)); map_draw(map_get_current(p_game->p_map, p_game->cur_map), backbuffer); if(p_game->p_unit->current_action == FIGHT){ anim_sprite_draw(p_game->p_unit->weapon, get_backbuffer_surface()); } anim_sprite_draw(p_game->p_unit->p_sprite, backbuffer); for(i=0;i<p_game->NPC_nb;i++){ NPC_update(p_game->p_NPC+i, map_get_current(p_game->p_map, p_game->cur_map), p_game->p_unit); anim_sprite_draw(p_game->p_NPC[i].p_sprite, backbuffer); } for(i=0;i<p_game->ennemie_nb;i++){ ennemie_update(p_game->p_ennemie+i, map_get_current(p_game->p_map, p_game->cur_map), p_game->p_unit); anim_sprite_draw(p_game->p_ennemie[i].p_sprite, backbuffer); } Uint8* key = SDL_GetKeyState(NULL); if(key[p_game->p_unit->key_b] || action){ for(i=0;i<p_game->NPC_nb;i++){ if(sprite_intersect((sprite*)p_game->p_unit->p_sprite, (sprite*)p_game->p_NPC[i].p_sprite)){ struct t_event* p_event = malloc(sizeof(struct t_event)); p_event->is_auto = true; p_event->p_next = NULL; p_event->type = EVENT_SCRIPT; event_script* p_event_script = malloc(sizeof(event_script)); p_event_script->language = strdup("lua"); p_event_script->script = strdup(p_game->p_NPC[i].script); p_event_script->version = strdup("1.0"); p_event->data = p_event_script; event_exec_script(p_event, p_game); event_free(p_event); } } } //logic sprite_calc_bounding_box((sprite*)p_game->p_unit->p_sprite, true); //events when entering a tile point* p_point_enter = unit_check_on_tile_enter(p_game->p_unit, map_get_current(p_game->p_map, p_game->cur_map)); if( p_point_enter != NULL && map_get_current(p_game->p_map, p_game->cur_map)->pp_tile[p_point_enter->y][p_point_enter->x].p_event != NULL && map_get_current(p_game->p_map, p_game->cur_map)->pp_tile[p_point_enter->y][p_point_enter->x].p_event->is_auto){ p_game->p_unit->p_sprite->v_anim[p_game->p_unit->p_sprite->animation_current].frame_current = 1; event_dispatch(map_get_current(p_game->p_map, p_game->cur_map)->pp_tile[p_point_enter->y][p_point_enter->x].p_event, p_game); free(p_point_enter); } map* p_cur_map = map_get_current(p_game->p_map, p_game->cur_map); if(SDL_GetTicks() - timelastcall>1000/40) { unit_update(p_game->p_unit, p_cur_map); for(i=0;i<p_game->ennemie_nb;i++){ //Check weapon / ennemie collides if(p_game->p_unit->current_action == FIGHT){ if(sprite_intersect((sprite*)p_game->p_unit->weapon, (sprite*)p_game->p_ennemie[i].p_sprite)){ p_game->p_ennemie[i].HP--; if(p_game->p_ennemie[i].HP <= 0){ //ennemie dead //sound dead //animation dead p_game->p_unit->XP += p_game->p_ennemie[i].XP; //increase unit status p_game->p_unit->gold += p_game->p_ennemie[i].gold; ennemie_remove(p_game->p_ennemie, i, &p_game->ennemie_nb); //remove ennemie break; } } } //Check unit / ennemie collides if(p_game->p_unit->invincible_time <= 0 && sprite_intersect((sprite*)p_game->p_unit->p_sprite, (sprite*)p_game->p_ennemie[i].p_sprite)){ //sample_play(unit_hitted); p_game->p_unit->invincible_time = 40; unit_hitted(p_game->p_unit, p_game->p_ennemie+i, p_cur_map); if(p_game->p_unit->HP <= 0){ //sound dead //animation dead //message game over ret_code = GAME_OVER; done = true; break; } } } //Game events menu_ingame_update(get_backbuffer_surface(), p_menu, p_game); //update timer timelastcall=SDL_GetTicks(); } #if RENDER == 3 && !GEKKO SDL_GL_SwapBuffers(); #else SDL_SoftStretch(backbuffer, &srcrect, screen, &dstrect); SDL_Flip(screen); #endif } game_free(p_game); return ret_code; }
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; }
static int music_thread(SceSize arg, void *argp) { dword key = 0; dword oldkey = 0; u64 start, end; double interval = 0; g_thread_actived = 1; g_thread_exited = 0; xrRtcGetCurrentTick(&start); xrRtcGetCurrentTick(&end); while (g_thread_actived) { music_lock(); if (g_list.is_list_playing) { if (musicdrv_has_stop()) { if (g_list.first_time) { int ret; ret = music_play(g_list.curr_pos); if (ret == 0) g_list.first_time = false; } else { get_next_music(); if (!g_list.is_list_playing) { music_unlock(); music_load(g_list.curr_pos); music_stop(); continue; } music_play(g_list.curr_pos); } } music_unlock(); xrKernelDelayThread(100000); } else { music_unlock(); xrKernelDelayThread(500000); } if (g_music_hprm_enable) { key = ctrl_hprm_raw(); xrRtcGetCurrentTick(&end); interval = pspDiffTime(&end, &start); if (key == PSP_HPRM_FORWARD || key == PSP_HPRM_BACK || key == PSP_HPRM_PLAYPAUSE) { if (key != oldkey) { xrRtcGetCurrentTick(&start); xrRtcGetCurrentTick(&end); interval = pspDiffTime(&end, &start); } if (interval >= 0.5) { if (key == PSP_HPRM_FORWARD) { musicdrv_fforward(5); xrKernelDelayThread(200000); } else if (key == PSP_HPRM_BACK) { musicdrv_fbackward(5); xrKernelDelayThread(200000); } } oldkey = key; if (key == PSP_HPRM_PLAYPAUSE && interval >= 4.0) { power_down(); xrPowerRequestSuspend(); } } else { if ((oldkey == PSP_HPRM_FORWARD || oldkey == PSP_HPRM_BACK || oldkey == PSP_HPRM_PLAYPAUSE)) { if (interval < 0.5) { if (oldkey == PSP_HPRM_FORWARD) music_next(); else if (oldkey == PSP_HPRM_BACK) music_prev(); } if (interval < 4.0) { if (oldkey == PSP_HPRM_PLAYPAUSE) music_list_playorpause(); } } oldkey = key; xrRtcGetCurrentTick(&start); } } { int thid = xrKernelGetThreadId(); int oldpri = xrKernelGetThreadCurrentPriority(); xrKernelChangeThreadPriority(thid, 90); cache_routine(); xrKernelChangeThreadPriority(thid, oldpri); } } g_thread_actived = 0; g_thread_exited = 1; return 0; }