Beispiel #1
0
/***********************************
 sound_play
 Input: sound filename
 Output:
 ***********************************/
static int l_sound_play(lua_State* p_pLuaState)
{
	const char * l_FileName;
	l_FileName = luaL_checkstring(p_pLuaState, -1);
	sfx_play(context_get_player(), std::string(l_FileName), ANY_CHANNEL,
			NO_LOOP);

	return 0; // number of results
}
Beispiel #2
0
void gfx_draw_outro(SDL_Surface * screen)
{
    SDL_Surface *logo = NULL;

    int stime = 0, alpha = 0, time_var = 0;
    SDL_Surface *black = gfx_new_surface(320, 240, 1);

    if (!black)
    {
        if (black)
            SDL_FreeSurface(black);

        return;
    }

    logo = gfx_load_image("images/icons/game_run.png", 0);

    stime = SDL_GetTicks();

    time_var = SDL_GetTicks();

    while (stime + 200 > SDL_GetTicks())
    {
        SDL_FillRect(black, NULL,
                     SDL_MapRGBA(black->format, 0, 0, 0, alpha));
        bg_draw(screen);
        gfx_draw_image(black, 0, 0, screen);
        SDL_Flip(screen);

        alpha += (255 / (float) 200) * (SDL_GetTicks() - time_var);
        if (alpha > 255)
            alpha = 255;
        time_var = SDL_GetTicks();
    }

    sfx_play(SFXRUN);

    alpha = 255;
    while (stime + 3000 > SDL_GetTicks())
    {
        SDL_FillRect(black, NULL,
                     SDL_MapRGBA(black->format, 0, 0, 0, alpha));
        gfx_draw_image(black, 0, 0, screen);
        if (logo)
            gfx_draw_image(logo, (screen->w - logo->w) / 2,
                           (screen->h - logo->h) / 2, screen);
        SDL_Flip(screen);
    }
    SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
    SDL_Flip(screen);

    SDL_FreeSurface(logo);
}
Beispiel #3
0
void sub_music_handle_input(unsigned int button)
{
    switch (button)
    {
    case GP2X_BUTTON_L:
        if (music_stage == MUS_FULLSCREEN)
        {
            if (LIST_up())
            {
                mus_stop();
                while (!mus_ready());
                sub_music_playsel();
            }
        }
        break;

    case GP2X_BUTTON_R:
        if (music_stage == MUS_FULLSCREEN)
        {
            if (LIST_down())
            {
                mus_stop();
                while (!mus_ready());
                sub_music_playsel();
            }
        }
        break;

    case GP2X_BUTTON_B:
        if (music_stage == MUS_FULLSCREEN && sub_music_playing)
        {
            sub_music_playing = 0;
            mus_stop();
            music_stage = 0;
            xmb_deactivateFlag(XMB_APPFULLSCREEN);

            while (!mus_ready());

            if (Mix_OpenAudio
                (AUDIO_RATE, AUDIO_FORMAT, AUDIO_CHANNELS, AUDIO_BUFFERS))
            {
                printf("Unable to open audio!\n");
            }
            break;
        }
    case GP2X_BUTTON_LEFT:
        {
            if (music_stage == MUS_FULLSCREEN && sub_music_playing)
            {
                mus_bwd();
                break;
            }

            if (!music_stage && music_stage < 5)
            {
                sfx_play(SFXBACK);
                LIST_setEmptyMsg(NULL);
                if (LIST_out())
                    music_stage = 4;
                else
                    music_stage = 2;
                music_levels--;
                music_animtimer_b = music_animtimer = SDL_GetTicks();
            }
            break;
        }
    case GP2X_BUTTON_RIGHT:
        if (music_stage == MUS_FULLSCREEN && sub_music_playing)
        {
            mus_fwd();
            break;
        }
        break;
    case GP2X_BUTTON_UP:
        {
            if (music_stage == MUS_FULLSCREEN && sub_music_playing)
            {
                break;
            }

            if (LIST_up())
                sfx_play(SFXMOVE);
            break;
        }
    case GP2X_BUTTON_DOWN:
        {
            if (music_stage == MUS_FULLSCREEN && sub_music_playing)
            {
                break;
            }

            if (LIST_down())
                sfx_play(SFXMOVE);
            break;
        }
    case GP2X_BUTTON_Y:
        {
            break;
        }
    case GP2X_BUTTON_X:
        {
            if (!music_stage && LIST_getSelected())
            {
                if (music_stage == MUS_FULLSCREEN && sub_music_playing)
                {
                    break;
                }

                if (li_create_new)
                    break;

                LIST_setEmptyMsg(NULL);

                sub_music_playsel();
            }
            break;
        }
    default:
        break;
    }
}
Beispiel #4
0
void sub_music_playsel(void)
{
    struct stat statbuf;
    char *path;
    tlistitem *item = NULL;

    item = LIST_getSelected();
    if (!item)
        return;

    path = (char *) item->extra;
    if (!path)
        return;

    stat(path, &statbuf);

    if (S_ISDIR(statbuf.st_mode))
    {
        LIST_in();
        sprintf(music_path, "%s", path);
        music_levels++;
        music_stage = 1;
        music_animtimer_b = music_animtimer = SDL_GetTicks();
        sfx_play(SFXOK);
    }
    else
    {
        Mix_CloseAudio();
        music_stage = MUS_FULLSCREEN;
        xmb_activateFlag(XMB_APPFULLSCREEN);
        if (!strncasecmp(sub_music_ext(path), ".ogg", 4))
        {
            mus_init = op_init;
            mus_play = op_play;
            mus_stop = op_stop;
            mus_getpos = op_getpos;
            mus_getlength = op_getlength;
            mus_ready = op_ready;
            mus_fwd = op_fwd;
            mus_bwd = op_bwd;
            mus_eof = op_eof;
        }
        else
        {
            mus_init = mp3_init;
            mus_play = mp3_play;
            mus_stop = mp3_stop;
            mus_getpos = mp3_getpos;
            mus_getlength = mp3_getlength;
            mus_ready = mp3_ready;
            mus_fwd = mp3_fwd;
            mus_bwd = mp3_bwd;
            mus_eof = mp3_eof;
        }

        mus_init(path);
        mus_play();

        sub_music_playing = 1;
    }
}
Beispiel #5
0
/**********************************
Compose the character select screen
**********************************/
item_t * scr_play_compose(context_t * ctx)
{
	int bg_red = 0;
	int bg_blue = 0;
	int bg_green = 0;
	char * map_filename;
	int layer_index = 0;
	char * old_sfx = NULL;

	option = option_get();

	if(item_list) {
		item_list_free(item_list);
		item_list = NULL;
	}

	if(ctx->map == NULL ) {
		if(context_update_from_file(ctx) == RET_NOK) {
			return NULL;
		}
	}

	if(init) {
		/* Register this character to receive server notifications */
		network_request_start(ctx,ctx->id);
		ui_play_init();
		init = false;
	}

	sdl_free_keycb();
	sdl_free_mousecb();
	sdl_add_mousecb(MOUSE_WHEEL_UP,cb_zoom);
	sdl_add_mousecb(MOUSE_WHEEL_DOWN,cb_unzoom);

	change_map = ctx->change_map;

	if( change_map == true ) {
		map_filename = strconcat( MAP_TABLE,"/",ctx->map,NULL);
		network_send_req_file(ctx,map_filename);
		free(map_filename);
		if(default_layer) {
			map_layer_delete(default_layer);
		}
		default_layer = map_layer_new(ctx->map,DEFAULT_LAYER,NULL);
	}

	if( default_layer && default_layer->active ) { // Make sure map data are available
		for(layer_index = 0; layer_index < MAX_LAYER; layer_index++) {
			compose_map_set(ctx,layer_index);
			compose_map_scenery(ctx,layer_index);
			compose_item(ctx,layer_index);
			compose_sprite(ctx,layer_index);
			compose_type(ctx,layer_index);
		}
		compose_map_button(ctx);
		compose_select(ctx);

		ui_play_compose(ctx,item_list);

		// force virtual coordinate on map change
		if( change_map == true ) {
			sdl_force_virtual_x(map_t2p_x(ctx->pos_tx,ctx->pos_ty,default_layer) + default_layer->col_width[ctx->pos_tx%default_layer->col_num]/2 + default_layer->row_width[ctx->pos_ty%default_layer->row_num]/2 );
			sdl_force_virtual_y(map_t2p_y(ctx->pos_tx,ctx->pos_ty,default_layer) + default_layer->col_height[ctx->pos_tx%default_layer->col_num]/2 + default_layer->row_height[ctx->pos_ty%default_layer->row_num]/2 );
		}
		// set virtual coordinate on the same map
		else {
			sdl_set_virtual_x(map_t2p_x(ctx->pos_tx,ctx->pos_ty,default_layer) + default_layer->col_width[ctx->pos_tx%default_layer->col_num]/2 + default_layer->row_width[ctx->pos_ty%default_layer->row_num]/2 );
			sdl_set_virtual_y(map_t2p_y(ctx->pos_tx,ctx->pos_ty,default_layer) + default_layer->col_height[ctx->pos_tx%default_layer->col_num]/2 + default_layer->row_height[ctx->pos_ty%default_layer->row_num]/2 );
		}
	}

	entry_read_int(MAP_TABLE,ctx->map,&bg_red,MAP_KEY_BG_RED,NULL);
	entry_read_int(MAP_TABLE,ctx->map,&bg_blue,MAP_KEY_BG_BLUE,NULL);
	entry_read_int(MAP_TABLE,ctx->map,&bg_green,MAP_KEY_BG_GREEN,NULL);
	SDL_SetRenderDrawColor(ctx->render, bg_red, bg_blue, bg_green, 255);

	old_sfx = sfx;
	sfx = NULL;

	entry_read_string(MAP_TABLE,ctx->map,&sfx,MAP_SFX,NULL);

	if(old_sfx)  {
		if( sfx ) {
			if( strcmp(old_sfx,sfx) ) {
				sfx_stop(ctx,old_sfx);
			}
		} else  { // sfx == NULL
			sfx_stop(ctx,old_sfx);
		}
		free(old_sfx);
	}

	if( sfx && sfx[0]!=0 ) {
		sfx_play(ctx,sfx,NO_RESTART);
	}

	return item_list;
}
Beispiel #6
0
void rockpush_init_game(Rock_Screen *screen_data)
{
  SDL_Event event;
  Rock_Sprite *object_rocco;
  Rock_Scroll_Map map;
  int16_t current_level;
  bool done = false;
  Uint32 init_ms;
  Uint32 move_ms;
  SDL_Joystick *joystick = NULL;
  Sint16 joy_event = 0;

    if (SDL_NumJoysticks() >= 1) {
        joystick = SDL_JoystickOpen(0);
        SDL_JoystickEventState(SDL_ENABLE);
    }

    map.view_height   = VIEW_HEIGHT;
    map.view_width    = VIEW_WIDTH;
    map.scroll_shift  = SCROLL_SHIFT;
    map.diamonds      = 0;
    map.level         = 0;
    map.points        = 0;
    map.lives         = INIT_ROCCO_LIVE;
    map.update_score  = false;
    map.refresh_rocco = false;
    map.rocco_death   = false;
    current_level     = map.level;

    screen_show_background(screen_data->screen);
    sprites_set_tiles_textures();
    object_rocco = set_level_rocco(&map);
    set_score(&map, screen_data);


    if (sfx_get_active()) {
        sfx_set_level_music(&map);
        Mix_PlayMusic(map.level_music, -1);
    }

    SDL_GL_SetSwapInterval(0);

    distorsion_in(&map, screen_data);

    while (!done) {

        init_ms = SDL_GetTicks();

        while (SDL_PollEvent(&event)) {
            if (event.type == SDL_QUIT || event.key.keysym.sym == SDLK_ESCAPE)
                done = true;

            if (SDL_JoystickGetAttached(joystick))
                joy_event = SDL_JoystickGetAxis(joystick, 0) | SDL_JoystickGetAxis(joystick, 1);

            while (event.type == SDL_KEYDOWN || event.type == SDL_JOYBUTTONDOWN || joy_event) {
                move_ms = SDL_GetTicks();

                if (SDL_JoystickGetAttached(joystick)) {
                    joy_event = SDL_JoystickGetAxis(joystick, 0) | SDL_JoystickGetAxis(joystick, 1);

                    if (SDL_JoystickGetButton(joystick, 0))
                        done = true;

                    if (SDL_JoystickGetButton(joystick, 1))
                        map.rocco_death = true;
                }

                /*if (event.key.keysym.sym == SDLK_n)
                    map.level ++;*/

                // Reinicia el nivel
                if (event.key.keysym.sym == SDLK_r)
                    map.rocco_death = true;

                set_position(object_rocco, event, joystick);
                sprites_update(&map);
                map_show(screen_data, &map, false);
                screen_dump_buffer(screen_data, map.view_width, map.view_height);

                SDL_PollEvent(&event);

                if (map.update_score) {
                    set_score(&map, screen_data);
                    map.update_score = false;
                }

                if (map.level > current_level && map.level < TOTAL_LEVELS) {

                    sfx_play(SFX_LEVEL);

                    if (sfx_get_active()) {
                        Mix_HaltMusic();
                        Mix_FreeMusic(map.level_music);
                        sfx_set_level_music(&map);
                        Mix_PlayMusic(map.level_music, -1);
                    }

                    distorsion_out(&map, screen_data);

                    free(sprites);
                    object_rocco  = set_level_rocco(&map);
                    current_level = map.level;
                    set_score(&map, screen_data);

                    distorsion_in(&map, screen_data);

                } else if (map.level >= TOTAL_LEVELS)
                    done = true;

                if (map.refresh_rocco) {
                    object_rocco      = sprite_get_object(map.rocco_index);
                    map.refresh_rocco = false;
                }

                while ((SDL_GetTicks() - move_ms) < TICK_RATE);

            }

            if (event.type == SDL_KEYUP || !joy_event) {
                rocco_set_action(object_rocco, WAIT_LEFT);
                sprites_push_off(&map);
            }

        }

        sprites_update(&map);
        map_show(screen_data, &map, false);
        screen_dump_buffer(screen_data, map.view_width, map.view_height);

        if (map.update_score) {
            set_score(&map, screen_data);
            map.update_score = false;
        }

        // Si se añaden más elementos al mapa (realloc), hay que reasignar el puntero del personaje
        if (map.refresh_rocco) {
            object_rocco      = sprite_get_object(map.rocco_index);
            map.refresh_rocco = false;
        }

        if (map.rocco_death) {
            map.lives --;

            if (map.lives <= 0)
                done = true;
            else {
                free(sprites);
                object_rocco  = set_level_rocco(&map);
                current_level = map.level;
                set_score(&map, screen_data);
                map.rocco_death = false;
            }
        }

        while ((SDL_GetTicks() - init_ms) < TICK_RATE);

    }

    if (sfx_get_active()) {
        Mix_HaltMusic();
        Mix_FreeMusic(map.level_music);
    }

    distorsion_out(&map, screen_data);

    SDL_GL_SetSwapInterval(0);

    if (SDL_JoystickGetAttached(joystick))
        SDL_JoystickClose(joystick);
}
void sub_shc_handle_input(unsigned int button)
{
    switch (button)
    {
    case GP2X_BUTTON_B:
        {
            sfx_play(SFXBACK);
            if(shc_showpopup)
            {
            	POPUP_empty();
            	xmb_deactivateFlag(XMB_NOBATT | XMB_FOCUS);
				shc_showpopup = 0;
            }
            else
            {
            	shc_init_stage = 10;
            	shc_timer = 0;
           	}
            break;
        }
    case GP2X_BUTTON_LEFT:
        {
        	if(shc_showpopup)
        		break;

            sfx_play(SFXBACK);
            shc_init_stage = 10;
            shc_timer = 0;
            break;
        }
    case GP2X_BUTTON_UP:
        {
        	if(shc_showpopup)
        	{
        		if(POPUP_up())
        			sfx_play(SFXMOVE);

        		break;
        	}

            if (shc_selection > 0)
            {
                shc_movereq += 1;
                shc_selection--;
            }
            break;
        }
    case GP2X_BUTTON_DOWN:
        {
        	if(shc_showpopup)
        	{
				if(POPUP_down())
					sfx_play(SFXMOVE);

				break;
        	}

            if (shc_selection + 1 < shc_menucount)
            {
                shc_movereq -= 1;
                shc_selection++;
            }
            break;
        }
	case GP2X_BUTTON_Y:
        {
        	shc_node *curr = shc_root;
            unsigned int i = 0;

            for (i = 0; curr != NULL && i < shc_selection;
                 curr = curr->next, i++);

            if (!shc_init_stage && curr && !shc_showpopup)
            {
                struct stat statbuf;

                stat(curr->path, &statbuf);

                if (S_ISREG(statbuf.st_mode))
                {
                    xmb_activateFlag(XMB_NOBATT | XMB_FOCUS);

                    POPUP_setrevert(NULL, 0);

                    POPUP_add(NULL, "Delete Shortcut", sub_shc_popexec, 0);

                    POPUP_setselected(0);

		            shc_showpopup = 1;
                }
            }
            break;
        }
    case GP2X_BUTTON_X:
        {
            shc_node *curr = shc_root;
            unsigned int i = 0;

            if (shc_showpopup)
            {
                POPUP_execsel();
                sub_shc_destroy();         /* Empty list */
                sub_shc_init(shc_self);    /* Reload */
                xmb_deactivateFlag(XMB_NOBATT | XMB_FOCUS);
                POPUP_empty();
                shc_showpopup = 0;
                break;
            }

            for (i = 0; curr != NULL && i < shc_selection;
                 curr = curr->next, i++);

            if (curr)
            {
                char *dir_name = (char *) calloc(1, 1024);

                if (config_lookup_bool(&CONFIG, "outro"))
                    gfx_draw_outro(SDL_GetVideoSurface());

                gp2xmb_deinit();

                if (dir_name)
                {
                    strncpy(dir_name, curr->path, 1023);
                    chdir(dirname(dir_name));
                    free(dir_name);
                }

                gp2x_setclock(200);

                if (execl(curr->path, curr->path, NULL))
                {
                    gp2xmb_init();      /* start everything up again */
                    while (!xmb_getFlagState(XMB_LOADED))
                    {
                        bg_draw(SDL_GetVideoSurface());
                        progress_draw(SDL_GetVideoSurface(), 1);
                        SDL_Flip(SDL_GetVideoSurface());
                    }
                    msgbox(SDL_GetVideoSurface(),NULL, "System Error",
                           "Failed to execute program.", OK);
                    msgbox_retval();
                    return;
                }
            }

            break;
        }
    default:
        break;
    }
}
void sub_shc_draw(SDL_Surface * screen)
{
    int td, animating = 0;
    shc_node *curr = NULL;

    if (shc_init_stage)
    {
        sub_shc_stages(screen);
    }

    if (shc_movereq && !shc_movedir)
    {
        if (shc_movereq < 0)
        {
            sfx_play(SFXMOVE);
            shc_movedir = -1;
            shc_movereq++;
        }
        else if (shc_movereq > 0)
        {
            sfx_play(SFXMOVE);
            shc_movedir = 1;
            shc_movereq--;
        }
        shc_assign_move(shc_movedir);
        shc_timer2 = SDL_GetTicks();
    }

    if (!shc_init_stage)
        gfx_draw_image(shc_arrow, 25, 113, screen);

    curr = shc_root;

    td = (SDL_GetTicks() - shc_timer2);

    shc_timer2 = SDL_GetTicks();

    if (!curr && !shc_init_stage)       /* Did not find anything */
    {
        gfx_draw_text(screen, font_normal, 50, 115, USESHADOW, NOGLOW,
                      "There are no applications.");
    }

    while (curr && !shc_init_stage)
    {
        char t_name[32];
        t_name[0] = '\0';
        strncat(t_name, curr->title, 31);
        if (shc_movedir)
        {
            int move_td_x =
                (int) rint((curr->move_x) / (float) XMBMOVEDELAY * td);
            int move_td_y =
                (int) rint((curr->move_y) / (float) XMBMOVEDELAY * td);

            curr->pos_x += move_td_x;
            curr->pos_y += move_td_y;

            if ((move_td_x > 0 && curr->pos_x > curr->move_tx) ||
                (move_td_x < 0 && curr->pos_x < curr->move_tx))
            {
                curr->pos_x = curr->move_tx;
                curr->move_x = 0;
                curr->move_tx = 0;

                if (curr->pos_x == 50)
                {
                    SDL_FreeSurface(curr->icon_curr);
                    curr->icon_curr =
                        gfx_scaleperc_surface(curr->icon_orig, 1.0, 1.0);
                }
                else
                {
                    SDL_FreeSurface(curr->icon_curr);
                    curr->icon_curr =
                        gfx_scaleperc_surface(curr->icon_orig, 0.5, 0.5);
                }

            }

            if ((move_td_y > 0 && curr->pos_y > curr->move_ty) ||
                (move_td_y < 0 && curr->pos_y < curr->move_ty))
            {
                curr->pos_y = curr->move_ty;
                curr->move_y = 0;
                curr->move_ty = 0;
            }

            if (curr->move_x)
            {
                float bval =
                    ((1.0 / (SHCICONX / 4)) *
                     (curr->pos_x + (curr->move_x - curr->move_tx)) / 2.0);

                if (bval < 0)
                    bval = 0.5 + fabs(bval);
                else if (bval > 0)
                    bval = 0.5 + (0.5 - fabs(bval));

                if (bval)
                {
                    SDL_FreeSurface(curr->icon_curr);
                    curr->icon_curr =
                        gfx_scaleperc_surface(curr->icon_orig, bval, bval);
                }
            }

            if (curr->move_x || curr->move_y)
                animating = 1;
        }
        else if (curr->pos_y == 83)     /* selected ... ugly but it works, for now */
        {
            gfx_draw_text(screen,
                          font_normal,
                          curr->pos_x + SHCICONX + 10,
                          curr->pos_y +
                          ((SHCICONY - SFont_TextHeight(font_normal)) / 2),
                          USESHADOW, NOGLOW, curr->title);
        }

        if ((curr->pos_y + curr->icon_curr->h) > 0 && curr->pos_y < 240)
            gfx_draw_image(curr->icon_curr, curr->pos_x, curr->pos_y,
                           screen);

        curr = curr->next;
    }
    if (!animating)
        shc_movedir = 0;

	if(shc_showpopup)
		POPUP_draw(screen);
}