Пример #1
0
void music_play_game (level_pos_t level_pos)
{
    static const char *music[] = {
        "data/music/charlotte.ogg",
        "data/music/charlotte_slow.ogg",
        "data/music/DST_Alters.ogg",
        "data/music/DST_Arch_Delerium.ogg",
        "data/music/DST_Arches.ogg",
        "data/music/DST_Aronara.ogg",
        "data/music/DST_BattleLands.ogg",
        "data/music/DST_Beneathere.ogg",
        "data/music/DST_BlackRiver.ogg",
        "data/music/DST_BloodAndIron.ogg",
        "data/music/DST_BoneTower.ogg",
        "data/music/DST_ClockTower.ogg",
        "data/music/DST_DarkDance.ogg",
        "data/music/DST_Darkening.ogg",
        "data/music/DST_DarkestKnight.ogg",
        "data/music/DST_ExInfernus.ogg",
        "data/music/DST_GhostHouse.ogg",
        "data/music/DST_H2O.ogg",
        "data/music/DST_LeDanse.ogg",
        "data/music/DST_Legends.ogg",
        "data/music/DST_MechaSelect.ogg",
        "data/music/DST_OldCavern.ogg",
        "data/music/DST_Ornament.ogg",
        "data/music/DST_OverlandTheme.ogg",
        "data/music/DST_ReflectingPool.ogg",
        "data/music/DST_Sarcophage.ogg",
        "data/music/DST_SnowMode.ogg",
        "data/music/DST_StarryBook.ogg",
        "data/music/DST_SuperWin.ogg",
        "data/music/DST_TwoHeaded.ogg",
        "data/music/DST_DoomCity.ogg",
    };

    /*
     * So we get the same music for each player on the same level.
     */
    int r = (level_pos.x + (level_pos.y * 10)) * 100;
    int x = r % ARRAY_SIZE(music);

    music_play(music[x], music[x], 22050);
}
Пример #2
0
/*----------------------------------------------------------------------------*/
void music_decode(void)
{

   sys_printf(" ------------------------------------>music_decode ");

#ifdef AC_SLAVE_ENABLE
	DSA_init();
#endif	
    dev_remov_timer=0;
    play_mode = REPEAT_OFF;
    disk_toc_ok=0;
    dev_invalid=0;
    input_number_en = 1;									//允许数字输入功能
    vol_change_en=1;
    key_voice_en=1;
    main_menu = MENU_MUSIC_MAIN;
    dec_msg = get_dec_msg_ptr();
    fat_ptr1.buf = win_buffer;
    SYSTEM_CLK_DIV1();
    //sd_speed_init(0, 100);
    key_table_sel(0);
    flush_all_msg();
    music_info_init();
    set_max_vol(MAX_ANOLOG_VOL,MAX_DIGITAL_VOL);///设置最大音量
    
    if(DSA_SEL_DEV==DEVICE_SDMMC0){
		
        given_device = DEVICE_SDMMC0;

    }
    else if(DSA_SEL_DEV==DEVICE_UDISK){
        given_device = DEVICE_UDISK;
   }
    //put_msg_lifo(MSG_MUSIC_SELECT_NEW_DEVICE);
    
    music_play();
    //delay_10ms(3);
    stop_decode();
    usb_suspend();				//Entered Suspend Mode
    key_voice_en=0;
    main_vol_set(0, CHANGE_VOL_NO_MEM);
    given_device = NO_DEVICE;
}
Пример #3
0
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow){
    ChangeWindowMode(TRUE);//ウィンドウモード
    if(DxLib_Init() == -1 || SetDrawScreen( DX_SCREEN_BACK )!=0) return -1;//初期化と裏画面化

    while(ProcessLoop()==0){//メインループ
		music_ini();
        switch(func_state){
            case 0://初回のみ入る処理
                load();        //データロード
                first_ini();//初回の初期化
                func_state=99;
                break;
            case 99://STGを始める前に行う初期化
                ini();
				load_story();
                func_state=100;
                break;
            case 100://通常処理
                calc_ch();   //キャラクタ計算
                ch_move();   //キャラクタの移動制御
                cshot_main();//自機ショットメイン
				enemy_main();//敵処理メイン
				shot_main(); //ショットメイン
				out_main();  //当たり計算
				effect_main();//エフェクトメイン
                graph_main();//描画メイン
                stage_count++;
                break;
            default:
                printfDx("不明なfunc_state\n");
                break;
        }
		music_play();
        if(CheckStateKey(KEY_INPUT_ESCAPE)==1)break;//エスケープが入力されたらブレイク
        ScreenFlip();//裏画面反映
    }

    DxLib_End();//DXライブラリ終了処理
    return 0;
}
Пример #4
0
void cmd_music_on(int music) {
    // 0 is special case; stops playback
    if(music == 0) {
        music_stop();
        return;
    }

    // Find file we want to play
    char filename[64];
    switch(music) {
        case 0: music_stop(); break;
        case 1: get_filename_by_id(PSM_END, filename); break;
        case 2: get_filename_by_id(PSM_MENU, filename); break;
        case 3: get_filename_by_id(PSM_ARENA0, filename); break;
        case 4: get_filename_by_id(PSM_ARENA1, filename); break;
        case 5: get_filename_by_id(PSM_ARENA2, filename); break;
        case 6: get_filename_by_id(PSM_ARENA3, filename); break;
        case 7: get_filename_by_id(PSM_ARENA4, filename); break;
    }
    music_play(filename);
    music_set_volume(settings_get()->sound.music_vol/10.0f);
}
Пример #5
0
void music_play_game_over (void)
{
    music_play("adventurine-data/music/DST_ClockTower.ogg", "game over", 22050 );
}
Пример #6
0
void music_play_intro (void)
{
    music_play("adventurine-data/music/DST_ClockTower.ogg", "intro", 22050 );
}
Пример #7
0
void music_play_dead (void)
{
    music_play("adventurine-data/music/DST_ClockTower.ogg", "dead", 22050 );
}
Пример #8
0
void music_play_game_over (void)
{
    music_play("data/music/DST_BattleLands.ogg", "game over", 22050 );
}
Пример #9
0
void music_play_demo (void)
{
    music_play("adventurine-data/music/DST_ClockTower.ogg", "battle", 22050 );
}
Пример #10
0
int main(void)
{
	music_init();
	music_play(3);
	u16 delay_mod = 4;
	u16 col_inc_cnt = 0;
	setup();
reset_demo:

		hint_val = 3;
	col = 0;
	col_off = 0;
	phrase_num = 0;
	scroll_off = 0;
	dscroll = 0;
	term_pos = 0;
	term_scrolling = 0;

	sprites_dma_simple();
	term_pos = 0;
	VDP_setHInterrupt(0);

	VDP_clearPlan(VDP_PLAN_A, 0);
	VDP_clearPlan(VDP_PLAN_B, 0);
	// Greyscale palette for text
	VDP_setPaletteColor(0,0x000);
	VDP_setPaletteColor(1,0x444);
	VDP_setPaletteColor(2,0x888);
	VDP_setPaletteColor(3,0xEEE);

	VDP_setScreenWidth256();
	bios_boot_demo();
	VDP_setScreenWidth320();
	VDP_clearPlan(VDP_PLAN_A, 0);
	VDP_clearPlan(VDP_PLAN_B, 0);


	awful_put_logo(8, 2);
	startup_stretch();

	VDP_setVerticalScroll(PLAN_A, 252);
	VDP_setVerticalScroll(PLAN_B, 252);

	VDP_setHIntCounter(hint_val);
	SYS_setHIntCallback((_voidCallback *)h_int);
	volatile u8 p1 = pad_read(0);
	sprites_init();

	col_puts40(8,0,"Computer Science House");

	// Initialize background stars
	star stars[NUM_STARS];
	u16 i = 0;
	for (i = 0; i < NUM_STARS; i++)
	{
		stars[i].x = i * 5;
		stars[i].y = 128 + i * 8;
		stars[i].speed = (i % 7) + 1;
		stars[i].offset = (3 * i) % 4;
		stars[i].size = (i % 4 == 0) ? ('.' + COL_FONT_VRAM_OFFSET) : (128 + '.' + COL_FONT_VRAM_OFFSET);
	}

	print_phrase(8);
	u16 delay = 0;
	u8 dir = 0;
	VDP_setHInterrupt(1);
	for (;;)
	{
		delay++;
		if (col_inc_cnt == 0)
		{
			col_inc_cnt = hint_val;
			col_off += 0x002;
		}
		else
		{
			col_inc_cnt--;
		}
		if (delay == 512)
		{
			if (phrase_num == 8)
			{
				phrase_num = 0;

				VDP_setHInterrupt(0);
				sprite_set(0, 0, 0, 0, 0, 0);
				sprites_dma_simple();
				while (vbl_wait)
		{	
			__asm__("nop");
		}

		vbl_wait = 1;
				goto reset_demo;
			}
			hint_val++;
			if (hint_val == 10)
			{
				hint_val = 3;
			}
			delay_mod = delay_mod >> 1;
			if (delay_mod == 0)
			{
				delay_mod = delay_mod = 4;
			}
			VDP_setHIntCounter(hint_val);
			VDP_setHInterrupt(0);
			print_phrase(phrase_num);
			VDP_setHInterrupt(1);
			phrase_num++;

			delay = 0;
		}	
		process_stars(&stars);
		while (vbl_wait)
		{	
			__asm__("nop");
		}
		VDP_setHInterrupt(0);
		VDP_setPaletteColor(14,palette[col]);
		col = col_off;
		vbl_wait = 1;
		sprites_dma_simple();
		VDP_setHInterrupt(1);
	}
	return 0;	
}
Пример #11
0
Файл: main.c Проект: odrevet/GE
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;

}
Пример #12
0
int melee_create(scene *scene) {
    char bitmap[51*36*4];

    // Init local data
    melee_local *local = malloc(sizeof(melee_local));
    memset(local, 0, sizeof(melee_local));
    scene_set_userdata(scene, local);

    game_player *player1 = game_state_get_player(scene->gs, 0);
    game_player *player2 = game_state_get_player(scene->gs, 1);

    controller *player1_ctrl = game_player_get_ctrl(player1);
    controller *player2_ctrl = game_player_get_ctrl(player2);

    palette *mpal = video_get_base_palette();
    palette_set_player_color(mpal, 0, 8, 0);
    palette_set_player_color(mpal, 0, 8, 1);
    palette_set_player_color(mpal, 0, 8, 2);
    video_force_pal_refresh();

    memset(&bitmap, 255, 51*36*4);
    local->ticks = 0;
    local->pulsedir = 0;
    local->selection = 0;
    local->row_a = 0;
    local->column_a = 0;
    local->row_b = 0;
    local->column_b = 4;
    local->done_a = 0;
    local->done_b = 0;

    menu_background2_create(&local->feh, 90, 61);
    menu_background2_create(&local->bleh, 160, 43);
    surface_create_from_data(&local->select_hilight, SURFACE_TYPE_RGBA, 51, 36, bitmap);

    // set up the magic controller hooks
    if(player1_ctrl && player2_ctrl) {
        if(player1_ctrl->type == CTRL_TYPE_NETWORK) {
            controller_add_hook(player2_ctrl, player1_ctrl, player1_ctrl->controller_hook);
        }

        if (player2_ctrl->type == CTRL_TYPE_NETWORK) {
            controller_add_hook(player1_ctrl, player2_ctrl, player2_ctrl->controller_hook);
        }
    }

    animation *ani;
    sprite *spr;
    for(int i = 0; i < 10; i++) {
        ani = &bk_get_info(&scene->bk_data, 3)->ani;
        object_create(&local->pilots[i], scene->gs, vec2i_create(0,0), vec2f_create(0, 0));
        object_set_animation(&local->pilots[i], ani);
        object_select_sprite(&local->pilots[i], i);

        ani = &bk_get_info(&scene->bk_data, 18+i)->ani;
        object_create(&local->har_player1[i], scene->gs, vec2i_create(110,95), vec2f_create(0, 0));
        object_set_animation(&local->har_player1[i], ani);
        object_select_sprite(&local->har_player1[i], 0);
        object_set_repeat(&local->har_player1[i], 1);

        int row = i / 5;
        int col = i % 5;
        spr = sprite_copy(animation_get_sprite(&bk_get_info(&scene->bk_data, 1)->ani, 0));
        mask_sprite(spr->data, 62*col, 42*row, 51, 36);
        ani = create_animation_from_single(spr, spr->pos);
        object_create(&local->harportraits_player1[i], scene->gs, vec2i_create(0, 0), vec2f_create(0, 0));
        object_set_animation(&local->harportraits_player1[i], ani);
        object_select_sprite(&local->harportraits_player1[i], 0);
        object_set_animation_owner(&local->harportraits_player1[i], OWNER_OBJECT);
        if (player2->selectable) {
            spr = sprite_copy(animation_get_sprite(&bk_get_info(&scene->bk_data, 1)->ani, 0));
            mask_sprite(spr->data, 62*col, 42*row, 51, 36);
            ani = create_animation_from_single(spr, spr->pos);
            object_create(&local->harportraits_player2[i], scene->gs, vec2i_create(0, 0), vec2f_create(0, 0));
            object_set_animation(&local->harportraits_player2[i], ani);
            object_select_sprite(&local->harportraits_player2[i], 0);
            object_set_animation_owner(&local->harportraits_player2[i], OWNER_OBJECT);
            object_set_pal_offset(&local->harportraits_player2[i], 48);

            ani = &bk_get_info(&scene->bk_data, 18+i)->ani;
            object_create(&local->har_player2[i], scene->gs, vec2i_create(210,95), vec2f_create(0, 0));
            object_set_animation(&local->har_player2[i], ani);
            object_select_sprite(&local->har_player2[i], 0);
            object_set_repeat(&local->har_player2[i], 1);
            object_set_direction(&local->har_player2[i], OBJECT_FACE_LEFT);
            object_set_pal_offset(&local->har_player2[i], 48);
        }
    }

    ani = &bk_get_info(&scene->bk_data, 4)->ani;
    object_create(&local->bigportrait1, scene->gs, vec2i_create(0,0), vec2f_create(0, 0));
    object_set_animation(&local->bigportrait1, ani);
    object_select_sprite(&local->bigportrait1, 0);

    if (player2->selectable) {
        object_create(&local->bigportrait2, scene->gs, vec2i_create(320,0), vec2f_create(0, 0));
        object_set_animation(&local->bigportrait2, ani);
        object_select_sprite(&local->bigportrait2, 4);
        object_set_direction(&local->bigportrait2, OBJECT_FACE_LEFT);
    }

    ani = &bk_get_info(&scene->bk_data, 5)->ani;
    object_create(&local->player2_placeholder, scene->gs, vec2i_create(0,0), vec2f_create(0, 0));
    object_set_animation(&local->player2_placeholder, ani);
    if (player2->selectable) {
        object_select_sprite(&local->player2_placeholder, 0);
    } else {
        object_select_sprite(&local->player2_placeholder, 1);
    }

    spr = sprite_copy(animation_get_sprite(&bk_get_info(&scene->bk_data, 1)->ani, 0));
    surface_convert_to_rgba(spr->data, video_get_pal_ref(), 0);
    ani = create_animation_from_single(spr, spr->pos);
    object_create(&local->unselected_har_portraits, scene->gs, vec2i_create(0,0), vec2f_create(0, 0));
    object_set_animation(&local->unselected_har_portraits, ani);
    object_select_sprite(&local->unselected_har_portraits, 0);
    object_set_animation_owner(&local->unselected_har_portraits, OWNER_OBJECT);

    for(int i = 0; i < 2; i++) {
        local->bar_power[i] = progressbar_create(PROGRESSBAR_THEME_MELEE, PROGRESSBAR_LEFT, 50);
        local->bar_agility[i] = progressbar_create(PROGRESSBAR_THEME_MELEE, PROGRESSBAR_LEFT, 50);
        local->bar_endurance[i] = progressbar_create(PROGRESSBAR_THEME_MELEE, PROGRESSBAR_LEFT, 50);
    }
    component_layout(local->bar_power[0], 74, 12, 20*4, 8);
    component_layout(local->bar_agility[0], 74, 30, 20*4, 8);
    component_layout(local->bar_endurance[0], 74, 48, 20*4, 8);
    component_layout(local->bar_power[1], 320-66-local->feh.w, 12, 20*4, 8);
    component_layout(local->bar_agility[1], 320-66-local->feh.w, 30, 20*4, 8);
    component_layout(local->bar_endurance[1], 320-66-local->feh.w, 48, 20*4, 8);

    refresh_pilot_stats(local);

    // initialize nova selection cheat
    memset(local->har_selected, 0, sizeof(local->har_selected));
    memset(local->katana_down_count, 0, sizeof(local->katana_down_count));

    // Set callbacks
    scene_set_input_poll_cb(scene, melee_input_tick);
    scene_set_render_cb(scene, melee_render);
    scene_set_free_cb(scene, melee_free);
    scene_set_dynamic_tick_cb(scene, melee_tick);

    // Play correct music
    music_play(PSM_MENU);

    // Pick renderer
    video_select_renderer(VIDEO_RENDERER_HW);

    // All done
    return 0;
}
Пример #13
0
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;
}
Пример #14
0
void music_play_demo (void)
{
    music_play("data/music/DST_BattleLands.ogg", "battle", 22050 );
}
Пример #15
0
// **************************************************************
// Summary:
//     play file.
// Description:
//     This function call play-engine to play media file.
// Returns:
//     returns RET_SUCCESS if play file successfully
//	  returns RET_FAILURE if not.
// Parameters:
//     idx :[IN]  dest file's idx in filelist, start with 1
//     type :[IN]  file type
//     fromPL :[IN]  whether play playlist
//     mode_rotate :[IN]  play mode and rotate mode, only used for pictrue play
// See Also:
//     file_pause, file_resume, file_jump, file_stop
RET_CODE 	file_play(UINT16 idx, file_type type, UINT8 fromPL, UINT8 mode_rotate)
{
	mp_type	mptype = _filetype2mptype(type);
	UDISK_ID id = _udisk_get_diskid();
	char path[FILE_NAME_SIZE];
	int ret_val;

	ENTER_FUNCTION;
	
	switch(mptype)
	{
		case MP_MUSIC:
			if(fromPL)
			{
				p_list_playlist	playlist = NULL;
				playlist = _udisk_get_playlist(id, mptype);
				if(RET_SUCCESS != _playlist_getpath_byidx(playlist, idx, path))
				{
					return  RET_FAILURE;
				}
				playlist->info.playidx = idx;
				playlist->info.playednum++;
				MP_DEBUG("play file:%d\t %s\n", idx, path);
				ret_val = music_play(path);
				if(ret_val < 0)
				{
					MP_DEBUG("CH error, return\n");
					return RET_FAILURE;
				}
			}
			else
			{
				if (temp_music_playlist_available)
				{
					if(RET_SUCCESS != _playlist_getpath_byidx(temp_music_playlist, idx, path))
					{
						return  RET_FAILURE;
					}
					temp_music_playlist->info.playidx = idx;
					temp_music_playlist->info.playednum++;
					MP_DEBUG("play file:%d\t %s\n", idx, path);
					ret_val = music_play(path);
					if(ret_val < 0)
					{
						MP_DEBUG("CH error, return\n");
						return RET_FAILURE;
					}
					
					return RET_SUCCESS;
				}
				
				p_list_filelist filelist = NULL;
				filelist = _udisk_get_filelist(id, mptype);
				if(filelist == NULL)
				{
					return RET_FAILURE;
				}
				if(RET_SUCCESS != _filelist_getpath_byidx(filelist, idx, path))
				{
					return RET_FAILURE;
				}
				MP_DEBUG("play file:%d\t %s\n", idx, path);
				snd_set_spdif_type((struct snd_device * )dev_get_by_id(HLD_DEV_TYPE_SND, 0), SND_OUT_SPDIF_PCM);
				ret_val = music_play(path);
				if(ret_val < 0)
				{
					MP_DEBUG("CH error, return\n");
					return RET_FAILURE;
				}
			}
			break;
		case MP_PICTURE:
			if(fromPL&0x7f)
			{
				p_list_playlist	playlist = NULL;
				int mode;
				unsigned char rotate;
				playlist = _udisk_get_playlist(id, mptype);
				if(RET_SUCCESS != _playlist_getpath_byidx(playlist, idx, path))
				{
					return RET_FAILURE;
				}
				playlist->info.playidx = idx;
				playlist->info.playednum++;
				MP_DEBUG("play file:%d\t %s\n", idx, path);
				mode = mode_rotate & IMAGE_DIS_MODE_MASK;
				rotate = (mode_rotate & IMAGE_ANGLE_MASK)>>4;
				//ret_val = image_decode(path, mode, 0, 0, 720, 576, rotate);

				//the following is shown how to use the image_decode_ex function with slideshow effect
				
				{
					struct image_slideshow_effect effect;

					if(fromPL&0x80)
						effect.mode = M_NORMAL;
					else
						effect.mode = osal_get_tick() % 5 + 1;
					switch(effect.mode)
					{
						case M_SHUTTERS:
							effect.mode_param.shuttles_param.direction = osal_get_tick() % 2;
							effect.mode_param.shuttles_param.time = 100;
							break;
						case M_BRUSH:
							effect.mode_param.brush_param.direction  = osal_get_tick() % 2;
							effect.mode_param.brush_param.time = 3;
							break;
						case M_SLIDE:
							effect.mode_param.slide_param.direction =  osal_get_tick() % 2;
							effect.mode_param.slide_param.time = 10;
							break;
						case M_RANDOM:
							effect.mode_param.random_param.type = osal_get_tick() % 3;
							effect.mode_param.random_param.time = 1;
							break;
						case M_FADE:
							effect.mode_param.fade_param.type = 0;
							effect.mode_param.fade_param.time = 0;
							break;
						default:
							break;
					}
					ret_val = image_decode_ex(path, mode, 0, 0, 720, 576, rotate, &effect);
				}
				
				if(ret_val < 0)
				{
					MP_DEBUG("CH error, return\n");
					return RET_FAILURE;
				}
			}
			else
			{
Пример #16
0
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow){

	//FullscreenMessage();
	ChangeWindowMode( FALSE );

	SetMainWindowText("高橋テトリスver0.04");
    if (DxLib_Init() == -1) return -1; //初期化

	load();

	if (SetDrawScreen( DX_SCREEN_BACK )!=0) return -1;//裏画面化

	exe_cnt=0;
	func_state=0;

    while(ProcessLoop()==0){//メインループ
			
		music_ini();

		switch(func_state){
		case 0: //初期ロード
			launch_ini();
			mode=0;
			menu_ini();
			func_state=1;
			break;
		case 1: //ロゴ画面
			graph_logo();
			break;
		case 2: //メニュー画面
			control_menu();
			graph_menu();
			break;
		case 50: //モード選択画面
			control_menu();
			graph_menu();
			break;
		case 51: //モード選択後移行画面
			graph_menu();
			menu_selected_cnt++;
			if (menu_selected_cnt>30) {
				first_ini();
				func_state=100;
			}
			break;
		case 100: //ゲームメイン画面
			control_main();
			block_main();
			cal_score();
			graph_main();
			stage_cnt++;
			if (gameover_flag==1 && CheckStatePad(-1,PAD_NUM_HOLD)==1) {
				result_ini();
				func_state=101;
			}
			if (CheckStatePad(-1,PAD_NUM_PAUSE)==1) {
				pause_push_Pl=PadPushPlayer;
				StopSoundMem( bgm_handle[bgm_num] ) ;
				pause_select=0;
				func_state=999;
			}
			break;
		case 999: //ポーズ画面
			control_game_pause();
			graph_main();
			if (CheckStatePad((all_cpu_flag==0)?pause_push_Pl:-1,PAD_NUM_HOLD)==1) {
				switch (pause_select) {
				case 0:
					PlaySoundMem( bgm_handle[bgm_num] , DX_PLAYTYPE_LOOP , FALSE ) ;
					func_state=100;
					break;
				case 1:
					first_ini();
					func_state=100;
					break;
				case 2:
					menu_ini();
					func_state=50;
					break;
				}
			}
			if (CheckStatePad((all_cpu_flag==0)?pause_push_Pl:-1,PAD_NUM_PAUSE)==1) {
				PlaySoundMem( bgm_handle[bgm_num] , DX_PLAYTYPE_LOOP , FALSE ) ;
				func_state=100;
			}
			break;
		case 101: //リザルト画面
			control_result();
			graph_main();
			stage_cnt++;
			if (CheckStatePad(-1,PAD_NUM_HOLD)==1) func_state=102;
			break;
		case 102: //ゲームオーバー後選択画面
			control_over_select();
			graph_main();
			stage_cnt++;
			if (CheckStatePad(-1,PAD_NUM_HOLD)==1) {
				switch (over_select) {
				case 0:
					first_ini();
					func_state=100;
					break;
				case 1:
					menu_ini();
					menu_select=mode;
					func_state=50;
					break;
				case 3:
					func_state=101;
					break;
				}
			}
			break;
		default:
			printfDx("error:不明なfunc_state\n");
			break;
		}

		control_func_state();

		exe_cnt++;

		music_play();
	
		if(CheckStateKey(KEY_INPUT_ESCAPE)==1) break;//エスケープが入力されたらブレイク
		ScreenFlip();//裏画面反映
    }

    DxLib_End();//DXライブラリ終了処理
    return 0;
}
Пример #17
0
void music_play_intro (void)
{
    music_play("data/music/charlotte8bit.ogg", "intro", 22050 );
}
Пример #18
0
uint32_t Game::run()
{
//This is a main game

    //Quit flag
    bool quit = false;

    //The frame rate regulator
    Timer fps;

    ih_init();
    music_init();
    world_init();

    //SOME SORT OF MENU SHOULD BE HERE


    //Constructor calls etc
    Player *player = new Player();
    center_camera((player->get_x() + PLAYER_WIDTH/2), (player->get_y() + PLAYER_HEIGTH/2));

    show_message();
    //BOX FOR TEST
    world_generate();


    //main loop
    while(quit == false)
    {
        //Start the frame timer
        fps.start();

        //While there's events to handle
        while( SDL_PollEvent( &event ) )
        {
            handle_events(player);
            //If the user has Xed out the window
            if( event.type == SDL_QUIT )
            {
                //Quit the program
                quit = true;
            }
        }

        music_play();


        //MOVES
        player->move();
        player->center();

        //CLS
        ih_clear_screen();

        //DRAWING

        //hide cursor
        SDL_ShowCursor(0);
        apply_cursor();

        player->draw();

        start_over();

        while(get_curr())
        {
            get_curr()->draw();
            traverse();
        }

        ih_update();

        //Cap the frame rate
        if( fps.get_ticks() < 1000 / FRAMES_PER_SECOND )
        {
            SDL_Delay( ( 1000 / FRAMES_PER_SECOND ) - fps.get_ticks() );
        }

    }


    delete player;
    world_finit();
    music_finit();
    ih_cleanup();


    return 0;
}
Пример #19
0
Файл: fifo.c Проект: hsgg/quark
static void
fifo_execute (const char *command)
{
    if (!g_ascii_strncasecmp (command, "quit", 4))
        main_quit ();
    else if (!g_ascii_strncasecmp (command, "play", 4))
        music_play ();
    else if (!g_ascii_strncasecmp (command, "pause", 5))
        if (music_playing)
            music_pause ();
        else
            music_play ();
    else if (!g_ascii_strncasecmp (command, "stop", 4))
        music_stop ();
    else if (!g_ascii_strncasecmp (command, "next", 4)) {
        playlist_advance (1, TRUE);
    }
    else if (!g_ascii_strncasecmp (command, "prev", 4)) {
        playlist_advance (-1, TRUE);
    }
    else if (!g_ascii_strncasecmp (command, "append", 6)) {
        if (strlen (command) > 7) {
            gchar *u;
            const gchar *path;

            path = (command + 7);
            if (!(u = g_filename_to_utf8 (path, -1, NULL, NULL, NULL))) {
                g_warning (_("Skipping '%s'. Could not convert to UTF-8. "
                             "See the README for a possible solution."), path);
            } else {
                playlist_append_single (u);
                g_free (u);
            }
        }
    }
    else if (!g_ascii_strncasecmp (command, "track", 5)) {
        if (strlen (command) > 6) {
            int i = atoi (command + 6);
            playlist_seek (i - 1); /* first track is '1' */
        }
    }
    else if (!g_ascii_strncasecmp (command, "remove", 6)) {
        if (strlen (command) > 7) {
            int i = atoi (command + 7);
            playlist_remove (i - 1); /* first track is '1' */
        }
    }
    else if (!g_ascii_strncasecmp (command, "clear", 5)) {
        playlist_clear ();
    }
    else if (!g_ascii_strncasecmp (command, "move", 4)) {
        if (strlen (command) > 5) {
            char *p;
            int i = strtol (command + 5, &p, 10);
            if (strlen (command) > (unsigned)(p - command)) {
                int before = atoi (p);
                playlist_move (i - 1, before - 1); /* first track is '1' */
            }
        }
    }
    else if (!g_ascii_strncasecmp (command, "loop", 4)) {
        main_set_loop_at_end(!main_loop_at_end);
    }
    else if (!g_ascii_strncasecmp (command, "random", 6)) {
        main_set_random_order(!main_random_order);
    }
    else if (!g_ascii_strncasecmp (command, "dump", 4)) {
        playlist_dump ();
    }
    else if (!g_ascii_strncasecmp (command, "connect", 7)) {
        if (strlen (command) > 8) {
            fifo_add_notify (command + 8);
        }
    }

}
Пример #20
0
int newsroom_create(scene *scene) {
    newsroom_local *local = malloc(sizeof(newsroom_local));

    local->news_id = rand_int(24)*2;
    local->screen = 0;
    menu_background_create(&local->news_bg, 280, 50);
    str_create(&local->news_str);
    str_create(&local->pilot1);
    str_create(&local->pilot2);
    str_create(&local->har1);
    str_create(&local->har2);

    game_player *p1 = game_state_get_player(scene->gs, 0);
    game_player *p2 = game_state_get_player(scene->gs, 1);

    int health = 0;
    if (p2->sp_wins > 0) {
        // AI won, player lost
        local->won = 0;
        health = game_player_get_score(p2)->health;
    } else {
        local->won = 1;
        health = game_player_get_score(p1)->health;
    }

    DEBUG("health is %d", health);

    if (health > 40 && local->won == 1) {
        local->news_id = rand_int(6)*2;
    } else if (local->won == 1) {
        local->news_id = 12+rand_int(6)*2;
    } else if (health < 40 && local->won == 0) {
        local->news_id = 38+rand_int(5)*2;
    } else {
        local->news_id = 24+rand_int(7)*2;
    }

    // XXX TODO get the real sex of pilot
    // XXX TODO strip spaces from the end of the pilots name
    // XXX TODO set winner/loser names properly
    newsroom_set_names(local, lang_get(20+p1->pilot_id),
                              lang_get(20+p2->pilot_id),
                              har_get_name(p1->har_id),
                              har_get_name(p2->har_id),
                              pilot_sex(p1->pilot_id),
                              pilot_sex(p2->pilot_id));
    newsroom_fixup_str(local);

    // Continue Dialog
    dialog_create(&local->continue_dialog, DIALOG_STYLE_YES_NO, "DO YOU WISH TO CONTINUE?", 72, 60);
    local->continue_dialog.userdata = scene;
    local->continue_dialog.clicked = newsroom_continue_dialog_clicked;

    // Set callbacks
    scene_set_userdata(scene, local);
    scene_set_input_poll_cb(scene, newsroom_input_tick);
    scene_set_render_overlay_cb(scene, newsroom_overlay_render);
    scene_set_free_cb(scene, newsroom_free);
    scene_set_static_tick_cb(scene, newsroom_static_tick);
    scene_set_startup_cb(scene, newsroom_startup);

    // Start correct music
    music_play(PSM_MENU);

    // Pick renderer
    video_select_renderer(VIDEO_RENDERER_HW);

    return 0;
}
Пример #21
0
int cutscene_create(scene *scene) {
    cutscene_local *local = malloc(sizeof(cutscene_local));

    game_player *p1 = game_state_get_player(scene->gs, 0);

    const char *text = "";
    switch (scene->id) {
      case SCENE_END:
        music_play(PSM_END);
        text = lang_get(END_TEXT);
        local->text_x = 10;
        local->text_y = 5;
        local->text_width = 300;
        local->color = COLOR_YELLOW;
        break;

      case SCENE_END1:
        text = lang_get(END1_TEXT+p1->pilot_id);
        local->text_x = 10;
        local->text_y = 160;
        local->text_width = 300;
        local->color = COLOR_RED;

        // Pilot face
        animation *ani = &bk_get_info(&scene->bk_data, 3)->ani;
        object *obj = malloc(sizeof(object));
        object_create(obj, scene->gs, vec2i_create(0,0), vec2f_create(0, 0));
        object_set_animation(obj, ani);
        object_select_sprite(obj, p1->pilot_id);
        obj->halt=1;
        game_state_add_object(scene->gs, obj, RENDER_LAYER_TOP, 0, 0);

        // Face effects
        ani = &bk_get_info(&scene->bk_data, 10+p1->pilot_id)->ani;
        obj = malloc(sizeof(object));
        object_create(obj, scene->gs, vec2i_create(0,0), vec2f_create(0, 0));
        object_set_animation(obj, ani);
        game_state_add_object(scene->gs, obj, RENDER_LAYER_TOP, 0, 0);
        break;

      case SCENE_END2:
        text = lang_get(END2_TEXT+p1->pilot_id);
        local->text_x = 10;
        local->text_y = 160;
        local->text_width = 300;
        local->color = COLOR_GREEN;
        break;
    }

    local->len = strlen(text)-1;
    local->pos = 0;
    local->text = malloc(strlen(text)+1);
    strcpy(local->text, text);
    local->current = local->text;
    char *p;

    if ((p = strchr(local->text, '\n'))) {
      // null out the byte
      *p = '\0';
    }

    // Callbacks
    scene_set_userdata(scene, local);
    scene_set_free_cb(scene, cutscene_free);
    scene_set_input_poll_cb(scene, cutscene_input_tick);
    scene_set_startup_cb(scene, cutscene_startup);
    scene_set_render_overlay_cb(scene, cutscene_render_overlay);

    // Pick renderer
    video_select_renderer(VIDEO_RENDERER_HW);

    return 0;
}
Пример #22
0
/**
 * @brief Plays the loaded song.
 *
 * @luafunc play()
 */
static int musicL_play( lua_State *L )
{
   (void)L;
   music_play();
   return 0;
}
Пример #23
0
void cutscene_music(int id) {
    music_stop();
    char *filename = get_path_by_id(id);
    music_play(filename);
    free(filename);
}
Пример #24
0
void music_play_death (void)
{
    music_play("data/music/DST_TheHauntedChapel.ogg", "death", 22050 );
}
Пример #25
0
int music_prev(void)
{
	int ret = 0;

	music_lock();

	switch (g_list.cycle_mode) {
		case conf_cycle_single:
			{
				if (g_list.curr_pos == 0)
					g_list.curr_pos = music_maxindex() - 1;
				else
					g_list.curr_pos--;
				break;
			}
		case conf_cycle_repeat:
			{
				if (g_list.curr_pos == 0)
					g_list.curr_pos = music_maxindex() - 1;
				else
					g_list.curr_pos--;
				break;
			}
			break;
		case conf_cycle_repeat_one:
			{
				if (g_list.curr_pos == 0)
					g_list.curr_pos = music_maxindex() - 1;
				else
					g_list.curr_pos--;
				break;
			}
			break;
		case conf_cycle_random:
			{
				if (shuffle_prev() != 0) {
					ret = music_stop();

					if (ret < 0) {
						music_unlock();
						return ret;
					}

					g_list.is_list_playing = false;
					goto end;
				}
				break;
			}
			break;
	}

	if (!g_list.is_list_playing)
		g_list.is_list_playing = true;

  end:
	if (g_list.is_list_playing)
		ret = music_play(g_list.curr_pos);

	music_unlock();

	return ret;
}
Пример #26
0
void music_play_dead (void)
{
    music_play("data/music/DST_AncientCurse_II.ogg", "dead", 22050 / 2);
}
Пример #27
0
Файл: main.c Проект: odrevet/GE
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;
}
Пример #28
0
void player_run(object *obj) {
    // Some vars for easier life
    player_animation_state *state = &obj->animation_state;
    player_sprite_state *rstate = &obj->sprite_state;
    if(state->finished) return;

    // Handle slide operation
    if(obj->slide_state.timer > 0) {
        obj->pos.x += obj->slide_state.vel.x;
        obj->pos.y += obj->slide_state.vel.y;
        obj->slide_state.timer--;
    }

    if(obj->enemy_slide_state.timer > 0) {
        obj->enemy_slide_state.duration++;
        obj->pos.x = state->enemy->pos.x + obj->enemy_slide_state.dest.x;
        obj->pos.y = state->enemy->pos.y + obj->enemy_slide_state.dest.y;
        obj->enemy_slide_state.timer--;
    }

    // Not sure what this does
    const sd_script_frame *frame = sd_script_get_frame_at(&state->parser, state->current_tick);

    // Animation has ended ?
    if(frame == NULL) {
        if(state->repeat) {
            player_reset(obj);
            frame = sd_script_get_frame_at(&state->parser, state->current_tick);
        } else if(obj->finish != NULL) {
            obj->cur_sprite = NULL;
            obj->finish(obj);
            return;
        } else {
            obj->cur_sprite = NULL;
            state->finished = 1;
            return;
        }
    }

    // Handle frame
    state->entered_frame = 0;
    if(frame == NULL) {
        DEBUG("Something went wery wrong!");
        // We shouldn't really get here, unless stringparser messes something up badly
    } else {
        // If frame changed, do something
        if(sd_script_frame_changed(&state->parser, state->previous_tick, state->current_tick)) {
            state->entered_frame = 1;
            player_clear_frame(obj);

            // Tick management
            if(sd_script_isset(frame, "d")) {
                if(!obj->animation_state.disable_d) {
                    state->previous_tick = sd_script_get(frame, "d")-1;
                    state->current_tick = sd_script_get(frame, "d");
                }
            }

            // Hover flag
            if(sd_script_isset(frame, "h")) {
                rstate->disable_gravity = 1;
            } else {
                rstate->disable_gravity = 0;
            }

            if(sd_script_isset(frame, "ua")) {
                obj->animation_state.enemy->sprite_state.disable_gravity = 1;
            }

            // Animation creation command
            if(sd_script_isset(frame, "m") && state->spawn != NULL) {
                int mx = 0;
                if (sd_script_isset(frame, "mrx")) {
                    int mrx = sd_script_get(frame, "mrx");
                    int mm = sd_script_isset(frame, "mm") ? sd_script_get(frame, "mm") : mrx;
                    mx = random_int(&obj->rand_state, 320 - 2*mm) + mrx;
                    DEBUG("randomized mx as %d", mx);
                } else if(sd_script_isset(frame, "mx")) {
                    mx = obj->start.x + (sd_script_get(frame, "mx") * object_get_direction(obj));
                }

                int my = 0;
                if (sd_script_isset(frame, "mry")) {
                    int mry = sd_script_get(frame, "mry");
                    int mm = sd_script_isset(frame, "mm") ? sd_script_get(frame, "mm") : mry;
                    my = random_int(&obj->rand_state, 320 - 2*mm) + mry;
                    DEBUG("randomized my as %d", my);
                } else if(sd_script_isset(frame, "my")) {
                    my = obj->start.y + sd_script_get(frame, "my");
                }

                int mg = sd_script_isset(frame, "mg") ? sd_script_get(frame, "mg") : 0;
                state->spawn(
                    obj,
                    sd_script_get(frame, "m"),
                    vec2i_create(mx, my),
                    mg,
                    state->spawn_userdata);
            }

            // Animation deletion
            if(sd_script_isset(frame, "md") && state->destroy != NULL) {
                state->destroy(obj, sd_script_get(frame, "md"), state->destroy_userdata);
            }

            // Music playback
            if(sd_script_isset(frame, "smo")) {
                if(sd_script_get(frame, "smo") == 0) {
                    music_stop();
                    return;
                }
                music_play(PSM_END + (sd_script_get(frame, "smo") - 1));
            }
            if(sd_script_isset(frame, "smf")) {
                music_stop();
            }

            // Sound playback
            if(sd_script_isset(frame, "s")) {
                float pitch = PITCH_DEFAULT;
                float volume = VOLUME_DEFAULT * (settings_get()->sound.sound_vol/10.0f);
                float panning = PANNING_DEFAULT;
                if(sd_script_isset(frame, "sf")) {
                    int p = clamp(sd_script_get(frame, "sf"), -16, 239);
                    pitch = clampf((p/239.0f)*3.0f + 1.0f, PITCH_MIN, PITCH_MAX);
                }
                if(sd_script_isset(frame, "l")) {
                    int v = clamp(sd_script_get(frame, "l"), 0, 100);
                    volume = (v / 100.0f) * (settings_get()->sound.sound_vol/10.0f);
                }
                if(sd_script_isset(frame, "sb")) {
                    panning = clamp(sd_script_get(frame, "sb"), -100, 100) / 100.0f;
                }
                int sound_id = obj->sound_translation_table[sd_script_get(frame, "s")] - 1;
                sound_play(sound_id, volume, panning, pitch);
            }

            // Blend mode stuff
            if(sd_script_isset(frame, "b1")) { rstate->method_flags &= 0x2000; }
            if(sd_script_isset(frame, "b2")) { rstate->method_flags &= 0x4000; }
            if(sd_script_isset(frame, "bb")) {
                rstate->method_flags &= 0x0010;
                rstate->blend_finish = sd_script_get(frame, "bb");
                rstate->screen_shake_vertical = sd_script_get(frame, "bb");
            }
            if(sd_script_isset(frame, "be")) { rstate->method_flags &= 0x0800; }
            if(sd_script_isset(frame, "bf")) {
                rstate->method_flags &= 0x0001;
                rstate->blend_finish = sd_script_get(frame, "bf");
            }
            if(sd_script_isset(frame, "bh")) { rstate->method_flags &= 0x0040; }
            if(sd_script_isset(frame, "bl")) {
                rstate->method_flags &= 0x0008;
                rstate->blend_finish = sd_script_get(frame, "bl");
                rstate->screen_shake_horizontal = sd_script_get(frame, "bl");
            }
            if(sd_script_isset(frame, "bm")) {
                rstate->method_flags &= 0x0100;
                rstate->blend_finish = sd_script_get(frame, "bm");
            }
            if(sd_script_isset(frame, "bj")) {
                rstate->method_flags &= 0x0400;
                rstate->blend_finish = sd_script_get(frame, "bj");
            }
            if(sd_script_isset(frame, "bs")) {
                rstate->blend_start = sd_script_get(frame, "bs");
            }
            if(sd_script_isset(frame, "bu")) { rstate->method_flags &= 0x8000; }
            if(sd_script_isset(frame, "bw")) { rstate->method_flags &= 0x0080; }
            if(sd_script_isset(frame, "bx")) { rstate->method_flags &= 0x0002; }

            // Palette tricks
            if(sd_script_isset(frame, "bpd")) { rstate->pal_ref_index = sd_script_get(frame, "bpd"); }
            if(sd_script_isset(frame, "bpn")) { rstate->pal_entry_count = sd_script_get(frame, "bpn"); }
            if(sd_script_isset(frame, "bps")) { rstate->pal_start_index = sd_script_get(frame, "bps"); }
            if(sd_script_isset(frame, "bpf")) {
                // Exact values come from master.dat
                if(game_state_get_player(obj->gs, 0)->har == obj) {
                    rstate->pal_start_index =  1;
                    rstate->pal_entry_count = 47;
                } else {
                    rstate->pal_start_index =  48;
                    rstate->pal_entry_count = 48;
                }
            }
            if(sd_script_isset(frame, "bpp")) {
                rstate->pal_end = sd_script_get(frame, "bpp") * 4;
                rstate->pal_begin = sd_script_get(frame, "bpp") * 4;
            }
            if(sd_script_isset(frame, "bpb")) { rstate->pal_begin = sd_script_get(frame, "bpb") * 4; }
            if(sd_script_isset(frame, "bz"))  { rstate->pal_tint = 1; }

            // The following is a hack. We don't REALLY know what these tags do.
            // However, they are only used in CREDITS.BK, so we can just interpret
            // then as we see fit, as long as stuff works.
            if(sd_script_isset(frame, "bc") && frame->tick_len >= 50) {
                rstate->blend_start = 0;
            } else if(sd_script_isset(frame, "bd") && frame->tick_len >= 30) {
                rstate->blend_finish = 0;
            }

            // Handle movement
            if(sd_script_isset(frame, "ox")) {
                DEBUG("changing X from %f to %f", obj->pos.x, obj->pos.x+sd_script_get(frame, "ox"));
                /*obj->pos.x += sd_script_get(frame, "ox");*/
            }

            if(sd_script_isset(frame, "oy")) {
                DEBUG("changing Y from %f to %f", obj->pos.y, obj->pos.y+sd_script_get(frame, "oy"));
                /*obj->pos.y += sd_script_get(frame, "oy");*/
            }

            if (sd_script_isset(frame, "bm")) {
                // hack because we don't have 'walk to other HAR' implemented
                obj->pos.x = state->enemy->pos.x;
                obj->pos.y = state->enemy->pos.y;
                player_next_frame(state->enemy);
            }

            if (sd_script_isset(frame, "v")) {
                int x = 0, y = 0;
                if(sd_script_isset(frame, "y-")) {
                    y = sd_script_get(frame, "y-") * -1;
                } else if(sd_script_isset(frame, "y+")) {
                    y = sd_script_get(frame, "y+");
                }
                if(sd_script_isset(frame, "x-")) {
                    x = sd_script_get(frame, "x-") * -1 * object_get_direction(obj);
                } else if(sd_script_isset(frame, "x+")) {
                    x = sd_script_get(frame, "x+") * object_get_direction(obj);
                }

                if (x || y) {
                    DEBUG("x vel %d, y vel %d", x, y);
                    obj->vel.x += x;
                    obj->vel.y += y;
                }
            }

            if (sd_script_isset(frame, "bu") && obj->vel.y < 0.0f) {
                float x_dist = dist(obj->pos.x, 160);
                // assume that bu is used in conjunction with 'vy-X' and that we want to land in the center of the arena
                obj->slide_state.vel.x = x_dist / (obj->vel.y*-2);
                obj->slide_state.timer = obj->vel.y*-2;
            }

            // handle scaling on the Y axis
            if(sd_script_isset(frame, "y")) {
                obj->y_percent = sd_script_get(frame, "y") / 100.0f;
            }
            if (sd_script_isset(frame, "e")) {
                // x,y relative to *enemy's* position
                int x = 0, y = 0;
                if(sd_script_isset(frame, "y-")) {
                    y = sd_script_get(frame, "y-") * -1;
                } else if(sd_script_isset(frame, "y+")) {
                    y = sd_script_get(frame, "y+");
                }
                if(sd_script_isset(frame, "x-")) {
                    x = sd_script_get(frame, "x-") * -1 * object_get_direction(obj);
                } else if(sd_script_isset(frame, "x+")) {
                    x = sd_script_get(frame, "x+") * object_get_direction(obj);
                }

                if (x || y) {
                    obj->enemy_slide_state.timer = frame->tick_len;
                    obj->enemy_slide_state.duration = 0;
                    obj->enemy_slide_state.dest.x = x;
                    obj->enemy_slide_state.dest.y = y;
                    /*DEBUG("ENEMY Slide object %d for (x,y) = (%f,%f) for %d ticks. (%d,%d)",
                            obj->cur_animation->id,
                            obj->enemy_slide_state.dest.x,
                            obj->enemy_slide_state.dest.y,
                            param->duration,
                            x, y);*/
                }
            }
            if (sd_script_isset(frame, "v") == 0 &&
                sd_script_isset(frame, "e") == 0 &&
                (sd_script_isset(frame, "x+") || sd_script_isset(frame, "y+") || sd_script_isset(frame, "x-") || sd_script_isset(frame, "y-"))) {
                // check for relative X interleaving
                int x = 0, y = 0;
                if(sd_script_isset(frame, "y-")) {
                    y = sd_script_get(frame, "y-") * -1;
                } else if(sd_script_isset(frame, "y+")) {
                    y = sd_script_get(frame, "y+");
                }
                if(sd_script_isset(frame, "x-")) {
                    x = sd_script_get(frame, "x-") * -1 * object_get_direction(obj);
                } else if(sd_script_isset(frame, "x+")) {
                    x = sd_script_get(frame, "x+") * object_get_direction(obj);
                }

                obj->slide_state.timer = frame->tick_len;
                obj->slide_state.vel.x = (float)x;
                obj->slide_state.vel.y = (float)y;
                /*DEBUG("Slide object %d for (x,y) = (%f,%f) for %d ticks.",*/
                    /*obj->cur_animation->id,*/
                    /*obj->slide_state.vel.x, */
                    /*obj->slide_state.vel.y, */
                    /*param->duration);*/
            }

            if(sd_script_isset(frame, "x=") || sd_script_isset(frame, "y=")) {
                obj->slide_state.vel = vec2f_create(0,0);
            }
            if(sd_script_isset(frame, "x=")) {
                obj->pos.x = obj->start.x + (sd_script_get(frame, "x=") * object_get_direction(obj));

                // Find frame ID by tick
                int frame_id = sd_script_next_frame_with_tag(&state->parser, "x=", state->current_tick);
                
                // Handle it!
                if(frame_id >= 0) {
                    int mr = sd_script_get_tick_pos_at_frame(&state->parser, frame_id);
                    int r = mr - state->current_tick;
                    int next_x = sd_script_get(sd_script_get_frame(&state->parser, frame_id), "x=");
                    int slide = obj->start.x + (next_x * object_get_direction(obj));
                    if(slide != obj->pos.x) {
                        obj->slide_state.vel.x = dist(obj->pos.x, slide) / (float)(frame->tick_len + r);
                        obj->slide_state.timer = frame->tick_len + r;
                        /*DEBUG("Slide object %d for X = %f for a total of %d ticks.",*/
                                /*obj->cur_animation->id,*/
                                /*obj->slide_state.vel.x,*/
                                /*param->duration + r);*/
                    }

                }
            }
            if(sd_script_isset(frame, "y=")) {
                obj->pos.y = obj->start.y + sd_script_get(frame, "y=");

                // Find frame ID by tick
                int frame_id = sd_script_next_frame_with_tag(&state->parser, "y=", state->current_tick);

                // handle it!
                if(frame_id >= 0) {
                    int mr = sd_script_get_tick_pos_at_frame(&state->parser, frame_id);
                    int r = mr - state->current_tick;
                    int next_y = sd_script_get(sd_script_get_frame(&state->parser, frame_id), "y=");
                    int slide = next_y + obj->start.y;
                    if(slide != obj->pos.y) {
                        obj->slide_state.vel.y = dist(obj->pos.y, slide) / (float)(frame->tick_len + r);
                        obj->slide_state.timer = frame->tick_len + r;
                        /*DEBUG("Slide object %d for Y = %f for a total of %d ticks.",*/
                                /*obj->cur_animation->id,*/
                                /*obj->slide_state.vel.y,*/
                                /*param->duration + r);*/
                    }

                }
            }
            if(sd_script_isset(frame, "as")) {
                // make the object move around the screen in a circular motion until end of frame
                obj->orbit = 1;
            } else {
                obj->orbit = 0;
            }
            if(sd_script_isset(frame, "q")) {
                // Enable hit on the current and the next n-1 frames.
                obj->hit_frames = sd_script_get(frame, "q");
            }
            if(obj->hit_frames > 0) {
                obj->can_hit = 1;
                obj->hit_frames--;
            }

            if(sd_script_isset(frame, "at")) {
                // set the object's X position to be behind the opponent
                obj->pos.x = obj->animation_state.enemy->pos.x + (15 * object_get_direction(obj));
            }

            if(sd_script_isset(frame, "ar")) {
                DEBUG("flipping direction %d -> %d", object_get_direction(obj), object_get_direction(obj) *-1);
                // reverse direction
                object_set_direction(obj, object_get_direction(obj) * -1);
                DEBUG("flipping direction now %d", object_get_direction(obj));
            }

            // Set render settings
            if(frame->sprite < 25) {
                object_select_sprite(obj, frame->sprite);
                if(obj->cur_sprite != NULL) {
                    rstate->duration = frame->tick_len;
                    rstate->blendmode = sd_script_isset(frame, "br") ? BLEND_ADDITIVE : BLEND_ALPHA;
                    if(sd_script_isset(frame, "r")) {
                        rstate->flipmode ^= FLIP_HORIZONTAL;
                    }
                    if(sd_script_isset(frame, "f")) {
                        rstate->flipmode ^= FLIP_VERTICAL;
                    }
                }
            } else {
                object_select_sprite(obj, -1);
            }

        }
    }

    // Animation ticks
    state->previous_tick = state->current_tick;
    if(state->reverse) {
        state->current_tick--;
    } else {
        state->current_tick++;
    }

    // Sprite ticks
    rstate->timer++;

    // All done.
    return;
}
Пример #29
0
int music_restart(void) {
	return music_play(TUNE_INVALID);
}
Пример #30
0
/* Music stopped playing, move on to the next track */
static void playlist_forward (void)
{
    music_skip (1);
    music_play ();
}