青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

天行健 君子當(dāng)自強(qiáng)而不息

Putting Together a Full Game(15)

 

Handling Bartering

Previously you read about how the barter_frame state is used to render the bartering
scene in which the player can buy items from a character.

How does that state know what items to sell? The only way the game initiates the
bartering state is when a script triggers it via the Barter-with-Character script action.
That action, in turn, calls cApp::setup_barter, which configures the information
needed for the barter_frame function. This information includes the character that is
selling the items, as well as the filename of the character inventory control system
(ICS) item file:

void cApp::setup_barter(const char* ics_file)
{
    strcpy(g_barter_ics_file, ics_file);

    m_state_manager.push(barter_frame, 
this);
}

The barter_frame state function scans the ICS that was loaded, displaying every item
contained with the character’s inventory list on the screen. If the player clicks an
item and the player has the appropriate amount of money, that item is bought.
Once the player finishes dealing with the shopkeeper, the barter state is popped
from the state stack, and game-play returns.

 

Playing Sounds and Music

Music and other sounds are played during the game. Those game sounds, although
somewhat cheesy (as you can tell, I’m no recording artist!), are played by a call to
play_sound. The only argument to play_sound is an index number to an array of sound
files that you declare at the beginning of the application code:

To play one of the valid sounds, you use the following function:

void cApp::play_sound(long index)
{
    
if(index >= 0 && index < array_num(g_sound_files))
    {
        m_sound_data.free();

        
if(m_sound_data.load_wav(g_sound_files[index]))
            m_sound_channel.play(&m_sound_data, 100, 1);
    }
}

The play_sound function needs to load the sound to play, using the cSoundData object.
From there, the sound is played from memory. In much the same way that you call
the play_sound function, you can play different songs using the play_music function.

The play_music function also takes an index number into an array of song filenames.

No need for tracking the number of songs here (we're living on the wild side!), so
you can jump right into the play_music function:

void cApp::play_music(long index)
{
    
// do not botther changing song if same already playing
    if(g_cur_music == index)
        
return;

    m_music_channel.stop();
    m_music_channel.free();

    
// Fade music out, giving DirectMusic enough time to finish up last song or else new song doesn't play correctly.  
    // The 700 is based on play volume of music, so adjust ahead.

    DWORD timer = timeGetTime() + 700;

    
while(timeGetTime() < timer)
    {
        DWORD level = (timer - timeGetTime()) / 10;
        m_music_channel.set_volume(level);
    }

    
// load and play new song
    m_music_channel.load(g_music_files[index]);
    m_music_channel.play(70, 0);

    g_cur_music = index;
}

Before continuing, you want to check whether a song is currently playing. A global
variable keeps track of which song was last played, and if that song is still playing,
you don’t need to start playing the same song again (the current song continues to
play). If a new song is to be played, fade out the volume, free the current song,
load the new song, and start playing the music playing.

 

Other functions:

int PASCAL WinMain(HINSTANCE inst, HINSTANCE, LPSTR cmd_line, int cmd_show)
{
    DWORD pos_x = (get_screen_width()  - CLIENT_WIDTH) / 2;
    DWORD pos_y = (get_screen_height() - CLIENT_HEIGHT) / 4;

    build_window(inst, "GameClass", g_title_name, 
                 WS_BORDER | WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU,
                 pos_x, pos_y, CLIENT_WIDTH, CLIENT_HEIGHT);

    cApp app;
    app.run();

    
return 0;
}

void cGameSpells::play_spell_sound(long index)
{
    m_app->play_sound(index);
}

/*********************************************************************************************************/

void cApp::win_game()
{
    m_state_manager.pop_all(
this);

    g_menu_options = MENU_LOAD;
    m_state_manager.push(menu_frame, 
this);
}

void cApp::start_of_combat()
{
    m_combat_exp   = 0;
    m_combat_money = 0;

    
// trigger start of combat script

    
char filename[MAX_PATH];
    sprintf(filename, "..\\Data\\SOC%lu.mls", m_scene_index);

    m_game_script.execute(filename);
}
 
void cApp::end_of_combat()
{
    g_player->char_def.money += m_combat_money;
    g_player->char_def.exp   += m_combat_exp;

    m_text_header.set_text("Victory!", COLOR_WHITE);
    m_text_window.set_text("", COLOR_WHITE);

    
char window_text[2000], gained[128];

    
// start constructing the main window text

    strcpy(window_text, "\r\n\n");

    
if(m_combat_money)
    {
        sprintf(gained, "Gained %lu gold!\r\n", m_combat_money);
        strcat(window_text, gained);
    }

    sprintf(gained, "Gained %lu experience!\r\n", m_combat_exp);
    strcat(window_text, gained);    

    
// process level up
    for(int i = 0; i < array_num(g_level_up_exp); i++)
    {
        
if(g_player->char_def.exp >= g_level_up_exp[i] && g_player->char_def.level < i+2)
        {
            g_player->char_def.level = i+2;
            strcat(window_text, "Level up!\r\n");

            
// add bonuses for leveling up

            g_player->char_def.health_points += 10;
            g_player->char_def.mana_points   += 10;
            g_player->char_def.attack        += 4;
            g_player->char_def.defense       += 2;
            g_player->char_def.agility       += 2;
            g_player->char_def.resistance    += 2;
            g_player->char_def.mental        += 2;
            g_player->char_def.to_hit        += 10;

            strcat(window_text, "Stats up!\r\n");

            
// learn spells
            if(g_player->char_def.level < SPELL_LEARN_TOP_LEVEL)
            {
                g_player->char_def.magic_spell[0] |= (1 << i);
                sprintf(gained, "Learned spell %s\r\n", m_game_spells.get_spell(i)->name);
                strcat(window_text, gained);
            }

            
// max health and mana to match definition
            g_player->health_points = g_player->char_def.health_points;
            g_player->mana_points   = g_player->char_def.mana_points;
        }
    }

    
// lock the keyboard and mouse
    m_keyboard.m_locks[KEY_SPACE] = true;
    m_keyboard.set_key_state(KEY_SPACE, 
false);
    m_mouse.m_locks[MOUSE_LBUTTON] = 
true;
    m_mouse.set_button_state(MOUSE_LBUTTON, 
false);

    
// render the scene while waiting for key press or button press
    for(;;)
    {
        
// break when space pressed

        m_keyboard.acquire();
        m_keyboard.read();

        
if(m_keyboard.get_key_state(KEY_SPACE))
            
break;

        
// break when left mouse button pressed

        m_mouse.acquire();
        m_mouse.read();

        
if(m_mouse.get_button_state(MOUSE_LBUTTON))
            
break;

        
// render the scene and text window

        clear_display_zbuffer(1.0f);

        begin_display_scene();        

        render_frame(0);

        m_text_window.render(window_text, COLOR_WHITE);
        m_text_header.render(NULL, COLOR_WHITE);

        end_display_scene();

        present_display();
    }

    
// trigger end of combat script

    
char filename[MAX_PATH];
    sprintf(filename, "..\\Data\\EOC%lu.mls", m_scene_index);

    m_game_script.execute(filename);
}

bool cApp::last_point_reached(sCharacter* character)
{
    
if(character == NULL || character->ai != CHAR_ROUTE)
        
return false;

    
long last_index = character->num_points - 1;
    sRoutePoint* last_point = &character->route[last_index];

    
// determine if character has reached point

    
float x_diff = fabs(character->pos_x - last_point->pos_x);
    
float y_diff = fabs(character->pos_y - last_point->pos_y);
    
float z_diff = fabs(character->pos_z - last_point->pos_z);

    
float dist = x_diff * x_diff + y_diff * y_diff + z_diff * z_diff;
    
float radius = m_game_chars.get_xz_radius(character) * 0.25f;

    
// return true if point being touched
    return (dist < radius * radius);
}

posted on 2007-12-30 14:26 lovedday 閱讀(329) 評(píng)論(0)  編輯 收藏 引用


只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問(wèn)   Chat2DB   管理


公告

導(dǎo)航

統(tǒng)計(jì)

常用鏈接

隨筆分類(178)

3D游戲編程相關(guān)鏈接

搜索

最新評(píng)論

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            亚洲日本欧美| 亚洲第一在线视频| 亚洲欧美视频| 国产精品免费看| 久久精品电影| 玖玖玖国产精品| 9人人澡人人爽人人精品| 一本色道久久综合| 国产精品亚发布| 欧美本精品男人aⅴ天堂| 欧美激情亚洲激情| 亚洲欧美日韩区| 久久精品国内一区二区三区| 亚洲欧洲精品天堂一级| 在线亚洲一区二区| 激情成人在线视频| 99精品国产一区二区青青牛奶| 国产精品普通话对白| 另类尿喷潮videofree| 欧美日韩国产色视频| 久久久久久精| 欧美日韩一区二区免费在线观看| 午夜国产精品视频| 欧美成人久久| 久久国产成人| 欧美日韩中文字幕| 欧美www视频| 国产精品香蕉在线观看| 亚洲国产精品一区二区www| 国产精品免费一区二区三区在线观看| 久久偷看各类wc女厕嘘嘘偷窃| 欧美日本视频在线| 女人色偷偷aa久久天堂| 国产精品色网| 日韩视频在线观看国产| 在线成人性视频| 亚洲欧美日韩在线不卡| 日韩午夜av在线| 久久精品国产免费| 亚洲欧美在线高清| 欧美日韩国产精品 | 国产精品一区二区三区四区| 欧美黄色精品| 好吊妞**欧美| 午夜在线精品偷拍| 亚洲一区二区成人| 欧美另类综合| 亚洲日本免费| 日韩视频免费观看高清在线视频| 久久精品官网| 久久亚洲欧美国产精品乐播| 国产精品视频导航| 亚洲视频久久| 亚洲免费视频一区二区| 欧美日韩一视频区二区| 亚洲日本成人女熟在线观看| 亚洲高清一二三区| 久久综合久久美利坚合众国| 久久影院亚洲| 亚洲国产精品久久精品怡红院| 午夜精品理论片| 久久av最新网址| 麻豆成人精品| 国产欧美日韩专区发布| 亚洲一区二区日本| 性娇小13――14欧美| 国产精品视频网站| 亚洲欧美在线播放| 老司机免费视频一区二区| 国产综合视频在线观看| 久久精品最新地址| 欧美高清在线一区| 一本色道久久综合狠狠躁篇怎么玩| 欧美成人精品在线视频| 日韩系列欧美系列| 亚洲欧美日韩综合一区| 国内精品视频一区| 欧美 日韩 国产一区二区在线视频 | 久久久一本精品99久久精品66| 亚洲高清不卡在线| 国产亚洲欧美一区二区| 欧美色123| 欧美日韩免费在线观看| 欧美日韩精品免费看 | 亚洲高清免费在线| 亚洲国产精品第一区二区三区 | 欧美国产精品久久| 亚洲理论在线观看| 欧美怡红院视频一区二区三区| 国产精品日本一区二区| 久久av一区二区三区漫画| 欧美77777| 亚洲综合首页| 精品88久久久久88久久久| 欧美韩国日本一区| 午夜久久tv| 最近中文字幕日韩精品 | 久久久999成人| 亚洲精品美女| 国产日韩欧美精品综合| 久久综合伊人77777尤物| 一级成人国产| 欧美电影免费观看| 午夜亚洲视频| 亚洲精品一级| 国产亚洲欧洲997久久综合| 欧美国产综合一区二区| 欧美在线资源| 一二三区精品| 亚洲国产高清aⅴ视频| 性欧美暴力猛交另类hd| 亚洲精选一区二区| 国产在线精品一区二区夜色| 欧美人妖在线观看| 久久久久久日产精品| 亚洲在线日韩| 日韩一区二区电影网| 欧美成人69| 久久久亚洲一区| 欧美一区二区三区电影在线观看| 亚洲精品一区二区三区四区高清| 国产午夜精品视频| 国产精品男女猛烈高潮激情| 欧美美女福利视频| 欧美成人精品在线观看| 久久久高清一区二区三区| 午夜国产精品视频免费体验区| 亚洲精选视频免费看| 亚洲国产精品久久久久秋霞不卡 | 欧美一区二区高清| 亚洲中午字幕| 亚洲午夜极品| 一区二区三区免费观看| 亚洲自拍电影| 99热精品在线| 一区二区三区四区在线| 日韩亚洲精品在线| 日韩视频在线观看免费| 亚洲精品久久久久久久久久久久 | 久久久久久穴| 久久免费午夜影院| 裸体素人女欧美日韩| 久久夜色精品国产欧美乱| 久久久噜噜噜久久| 久久综合九色综合久99| 久久这里有精品15一区二区三区 | 日韩亚洲一区二区| 9久草视频在线视频精品| 亚洲最黄网站| 亚洲天堂av高清| 性久久久久久久久久久久| 欧美一级理论性理论a| 久久av资源网站| 久久综合婷婷| 欧美日本亚洲视频| 国产精品扒开腿做爽爽爽软件 | 欧美另类在线观看| 国产精品老牛| 精品成人国产在线观看男人呻吟| 影音先锋亚洲电影| 99在线|亚洲一区二区| 亚洲欧美激情视频| 久久伊人精品天天| 亚洲黄色成人久久久| avtt综合网| 久久久精品动漫| 欧美美女日韩| 国产一区二区三区直播精品电影 | 在线一区欧美| 久久午夜色播影院免费高清| 亚洲第一毛片| 亚洲性感美女99在线| 久久久久久久综合| 欧美日韩精品一区二区三区四区| 国产精品永久| 亚洲精品一区二区三区av| 午夜综合激情| 亚洲大片精品永久免费| 亚洲欧美日韩国产综合精品二区| 久久亚洲综合色一区二区三区| 欧美日韩国产综合视频在线观看中文 | 欧美激情一区二区三区在线视频| 国产精品久久久久aaaa樱花| 激情婷婷久久| 香蕉国产精品偷在线观看不卡| 麻豆精品网站| 在线中文字幕一区| 欧美福利网址| 一色屋精品亚洲香蕉网站| 亚洲在线观看| 最新日韩在线视频| 久久久久成人精品| 欧美性猛片xxxx免费看久爱| 亚洲国产成人精品久久久国产成人一区| 亚洲一区二区三区精品动漫| 亚洲第一视频网站| 欧美制服丝袜| 国产日韩免费| 欧美伊久线香蕉线新在线| 夜夜嗨av一区二区三区中文字幕 |