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

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

Putting Together a Full Game(11)

 

game_frame:

#define CLIENT_WIDTH        640
#define CLIENT_HEIGHT       480

#define MENU_BACK           1
#define MENU_LOAD           2
#define MENU_SAVE           4

#define NEW_GAME            0
#define RETURN_TO_GAME      1
#define LOAD_GAME           2
#define SAVE_GAME           3
#define QUIT_GAME           4

#define MAIN_MENU_TOP       126
#define MAIN_MENU_HEIGHT    64

#define BARTER_TOP_HEIGHT   128
#define BARTER_MENU_HEIGHT  32

#define STATUS_TOP_HEIGHT   128
#define STATUS_MENU_HEIGHT  32

const char* g_char_mesh_files[] = {
    "..\\Data\\Warrior1.x",     
    "..\\Data\\Warrior2.x",     
    "..\\Data\\Yodan1.x",       
    "..\\Data\\Yodan2.x",       
    "..\\Data\\Yodan3.x",       
    "..\\Data\\Yodan4.x"        
};

const sCharAnimInfo g_char_anims[] = {
    { "Idle",  
true  },
    { "Walk",  
true  },
    { "Swing", 
false },
    { "Spell", 
false },
    { "Swing", 
false },
    { "Hurt",  
false },
    { "Die",   
false },
    { "Idle",  
true  }
};

const char* g_spell_mesh_files[] = {
    "..\\Data\\Fireball.x",
    "..\\Data\\Explosion.x",
    "..\\Data\\Ice.x",
    "..\\Data\\Heal.x",
    "..\\Data\\Teleport.x",
    "..\\Data\\Groundball.x",
    "..\\Data\\Bomb.x",
    "..\\Data\\Force.x"     
};

const char* g_sound_files[] = {
    "..\\Data\\Attack1.wav",
    "..\\Data\\Attack2.wav",
    "..\\Data\\Fire.wav",
    "..\\Data\\Ice.wav",
    "..\\Data\\Heal.wav",
    "..\\Data\\Teleport.wav",
    "..\\Data\\Groundball.wav",
    "..\\Data\\Concussion.wav",
    "..\\Data\\Evil Force.wav",
    "..\\Data\\Roar.wav",
    "..\\Data\\Hurt1.wav",
    "..\\Data\\Hurt2.wav",
    "..\\Data\\Die1.wav",
    "..\\Data\\Die2.wav",
    "..\\Data\\Beep.wav"   
};

const char* g_music_files[] = {
    "..\\Data\\Cathedral_Sunrise.mid",
    "..\\Data\\Distant_tribe.mid",
    "..\\Data\\Escape.mid",
    "..\\Data\\Jungle1.mid",
    "..\\Data\\Magic_Harp.mid",
    "..\\Data\\Medi_Strings.mid",
    "..\\Data\\Medi_techno.mid",
    "..\\Data\\Song_of_the_sea.mid",
    "..\\Data\\Storm.mid"            
};

#define MAX_PLAYER_LEVEL        10
#define LEARN_SPELL_TOP_LEVEL   7

// max level 10, begin from level 2.
const long g_level_up_exp[] = { 100, 200, 350, 600, 900, 1300, 1800, 2400, 3100};

typedef 
struct 
{
    
float x, y, z;
    
float u, v;
} sMenuVertex;

#define MENU_FVF  (D3DFVF_XYZ | D3DFVF_TEX1)

long        g_cur_music = -1;
long        g_menu_options;
sCharacter* g_player;
char        g_barter_ics_file[MAX_PATH];

const char* g_title_name = "The road of warrior";
 
void game_frame(void* data, long purpose)
{
    
if(purpose != FRAME_PURPOSE)    // only process frame stats
        return;

    cApp* app = (cApp*) data;

    
// quit to menu screen if ESC pressed
    if(app->m_keyboard.get_key_state(KEY_ESC))
    {
        g_menu_options = MENU_BACK | MENU_LOAD | MENU_SAVE;
        app->m_state_manager.push(menu_frame, app);
        
return;
    }

    
// If teleporting, then handle that first and return.
    if(app->m_teleport_map != -1)
    {
        app->load_level(app->m_teleport_map);
        app->m_teleport_map = -1;
        
return;     // no more processing this frame
    }

    
bool is_monster_in_level = false;   // mark no monsters in level

    // See if any character are in level. 
    //
    // If any monsters, flag as such and change their AI to wander if their charge is less then 70, 
    // follow AI otherwise.
    //
    // Also, process whenever a character reaches a route point.
    for(sCharacter* character = app->m_game_chars.get_root_char(); character != NULL; character = character->next)
    {
        
if(character->type == CHAR_MONSTER)
        {            
            is_monster_in_level = 
true;

            
// change AI based on charge
            if(character->charge >= 70.0f)
            {
                character->ai          = CHAR_FOLLOW;
                character->target_char = g_player;
                character->distance    = 0.0f;
            }
            
else
                character->ai = CHAR_WANDER;
        }
        
else if(character->type == CHAR_NPC && character->ai == CHAR_ROUTE)
        {
            
// check if an NPC character has reached last route point
            if(app->last_point_reached(character))
            {
                
// process the route point script for character.

                
char filename[MAX_PATH];
                sprintf(filename, "..\\Data\\EOR%lu.mls", character->id);

                app->m_game_script.execute(filename);
                
return;     // do not process any more this frame
            }
        }
    }

    
// handle start of combat stuff
    if(is_monster_in_level && !app->m_is_monster_last_frame)
        app->start_of_combat();

    
// handle end of combat stuff if combat over
    if(!is_monster_in_level && app->m_is_monster_last_frame)
        app->end_of_combat();

    
// remember if monsters where in this frame and reset player's charge to full if no monsters

    app->m_is_monster_last_frame = is_monster_in_level;

    
if(! is_monster_in_level)
        g_player->charge = 100.0f;

    app->m_game_chars.update(33);
    app->m_game_spells.update(33);

    
long trigger_index = app->m_trigger.get_trigger(g_player->pos_x, g_player->pos_y, g_player->pos_z);

    
// check for triggers and execute script
    if(trigger_index != 0)
    {
        
char filename[MAX_PATH];
        sprintf(filename, "..\\Data\\Trig%lu.mls", trigger_index);

        app->m_game_script.execute(filename);
        
return;     // do not process any more this frame
    }

    set_display_camera(&app->m_camera);

    
// render everything

    clear_display_zbuffer(1.0f);
    begin_display_scene();
    app->render_frame(33);

    
// render the player's charge bar, but only during combat.
    if(is_monster_in_level)
    {
        D3DXMATRIX mat_world, mat_view, mat_proj;
        D3DVIEWPORT9 viewport;
        
        
// get the world, projection, view transformations, viewport.
        D3DXMatrixIdentity(&mat_world);
        get_display_view_matrix(&mat_view);
        get_display_proj_matrix(&mat_proj);
        get_display_viewport(&viewport);

        
// offset charge bar by character's height

        
float max_y;
        g_player->
object.get_bounds(NULL, NULL, NULL, NULL, &max_y, NULL, NULL);

        
// project coordinates to screen

        D3DXVECTOR3 pos_screen;
        D3DXVECTOR3 pos_3d(g_player->pos_x, g_player->pos_y + max_y, g_player->pos_z);

        D3DXVec3Project(&pos_screen, &pos_3d, &viewport, &mat_proj, &mat_view, &mat_world);

        pos_screen.x += 8.0f;

        
// display charge bar below player

        disable_zbuffer();
        begin_display_sprite();        

        RECT rect;

        calculate_texture_rect(app->m_charge_bar, 0, 0, 16, 4, &rect);
        draw_texture(g_d3d_sprite, app->m_charge_bar, &rect, pos_screen.x, pos_screen.y, 1.0f, 1.0f, COLOR_WHITE);
        
        
long width = g_player->charge / 100.0f * 16.0f;
        calculate_texture_rect(app->m_charge_bar, 0, 4, width, 4, &rect);
        draw_texture(g_d3d_sprite, app->m_charge_bar, &rect, pos_screen.x, pos_screen.y, 1.0f, 1.0f, COLOR_WHITE);

        end_display_sprite();
    }

    
// draw the player's stats at top-left

    
char stats_text[256];

    sprintf(stats_text, "%ld/%ld HP\r\n%ld/%ld MP",
            g_player->health_points, g_player->char_def.health_points,
            g_player->mana_points, g_player->char_def.mana_points);

    app->m_text_stats.render(stats_text, COLOR_WHITE);

    end_display_scene();
    present_display();
}

Because this is a frame state, you can call the game_frame function for one of three
purposes—the state being initialized, the frame being processed, and the state
being shut down. The game_frame function uses only the update-frame purpose, so
processing is returned if any other calling purpose is used.

At the beginning of the game_frame function is a quick check to see whether the Esc
key has been pressed. If so, the main menu state is pushed onto the stack.

In order for the main menu to know which options to display, you declare a global
variable at the beginning of the application. This global variable, g_menu_options, is
bit-encoded and uses the following macros to define them—MENU_BACK to display the
back to game option, MENU_SAVE to display the save game option, and MENU_LOAD to display
the load game option. Once you define the options, the state is pushed.

Whenever the player needs to move from one map to another (such as calling the
teleport_player function with the map number and coordinates to which to move the
player), you set a global variable called m_teleport_map to the correct map number for
teleporting. The preceding bit of code checks each frame to see whether that vari-
able has been set and teleports the player to the appropriate map.

Now comes the real bulk of the game_frame function. At the start of the following
block of code, you set a flag that records whether any monsters are in the map is
cleared. From there, scan the entire list of loaded characters. If you find a monster
character in the list, set the is_monster_in_level flag. Also, for each monster in the map,
change its AI settings based on its action charge. For charges less than 70, set the
monster’s AI to wander (to let the monster wander around the map). If the charge
is over 70, set the monster’s AI type to follow the player (so that the monster is
attempting to attack the player).

If, on the other hand, an NPC is found on the map and that character has its AI set
to follow a route, a separate function is called to determine whether that character
has reached the last route point assigned. If the last point on the route has been
touched, that character’s end-of-route script is executed.

Once you are past the scan-for-characters phase of game_frame, you compare the
is_monster_in_level flag to the same flag that was stored from the last frame. If they do
not match, either combat has started or ended, and the appropriate script is called.

Next comes the point at which all characters and spells are updated. Because the
cApp::frame function is locked to update the game 30 times a second, all controllers
use an update time of 33 milliseconds. Notice that before being updated, the
player's charge meter is set to full if no monsters are in the level.

After the characters are updated, the trigger object comes into play. If the player
walks into an active trigger, the appropriate script is executed.

From this point on, you render the scene by calling the render_frame function from
the application class. The render_frame function renders only the backdrop and
character in the map—it’s up to the rest of this function’s code to draw the status
window and charge meter.

void cApp::render_frame(long elapsed)
{
    
// render simplified scene mesh for z-values
    enable_zbuffer();
    m_scene_object.render();

    
// draw the backdrop (composed of six textures)

    disable_zbuffer();

    begin_display_sprite();

    
for(int i = 0; i < 2; i++)
    {
        
for(int j = 0; j < 3; j++)
        {
            IDirect3DTexture9* texture = m_scene_backdrops[i * 3 + j];

            RECT rect;
            calculate_texture_rect(texture, 0, 0, 0, 0, &rect);

            draw_texture(g_d3d_sprite, texture, &rect, j * 256, i * 256, 1.0f, 1.0f, COLOR_WHITE);
        }   
    }

    end_display_sprite();

    
// draw characters and spells

    enable_zbuffer();

    m_game_chars.render(elapsed, NULL, 0.0f);
    m_game_spells.render(NULL, 0.0f);
}

Again, you first render the scene by using the render_frame function, which takes as
an argument the amount of time (in milliseconds) that the animations should be
updated. You then draw the player's charge meter, but only if monsters are present
on the map.

There are numerous matrix- and vector-related functions at work here—you use
them to calculate the screen coordinates in which to draw the charge meter. To
determine where to draw the meter, using the preceding D3DXVec3Project function,
calculate the 2D coordinates based on the 3D world space coordinates of the player.

During the game-play, you display the player's statistics at the upper-left corner of
the screen—this includes the health and mana points, at their current levels and at
their maximum level.

The game_frame function ends up by calling end_display_scene and displaying the frame to the
user.

posted on 2007-12-29 22:24 lovedday 閱讀(454) 評(píng)論(0)  編輯 收藏 引用


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


公告

導(dǎo)航

統(tǒng)計(jì)

常用鏈接

隨筆分類(lèi)(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>
            国产日韩免费| 欧美影院视频| 亚洲欧美日韩中文视频| 欧美.日韩.国产.一区.二区| 亚洲伊人网站| 中文日韩欧美| 99热这里只有精品8| 在线欧美小视频| 一区免费观看| 欧美午夜视频在线观看| 欧美专区第一页| 亚洲图片在线观看| 亚洲午夜高清视频| 欧美a级一区二区| 麻豆成人91精品二区三区| 欧美呦呦网站| 亚洲视频视频在线| 国产精品久久久久久久免费软件| 欧美新色视频| 国产精品久久久久久久久久三级| 国产精品www994| 欧美激情中文字幕在线| 欧美日产在线观看| 国产精品家教| 激情综合在线| 亚洲国产一区二区三区高清| 伊人婷婷欧美激情| 亚洲人成网在线播放| 亚洲精品国产精品国产自| 国产一区日韩二区欧美三区| 国产一区二区0| 亚洲大胆美女视频| 亚洲嫩草精品久久| 欧美在线视频观看| 欧美国产日韩a欧美在线观看| 久久久久久夜精品精品免费| 欧美福利影院| 亚洲婷婷免费| 久久精品国产综合精品| 欧美xxx成人| 国产精品午夜在线| 在线播放一区| 亚洲一区二区免费视频| 久久亚洲风情| 欧美一级电影久久| 欧美sm重口味系列视频在线观看| 亚洲精品免费在线| 久久成人18免费观看| 欧美国产第一页| 国产美女诱惑一区二区| 亚洲国产日韩欧美在线动漫| 午夜精品一区二区在线观看| 另类专区欧美制服同性| 99re8这里有精品热视频免费| 性8sex亚洲区入口| 欧美母乳在线| 亚洲国产成人一区| 欧美在线观看视频一区二区三区| 亚洲国产成人av在线| 午夜国产精品视频| 欧美日韩高清一区| 亚洲高清av| 久久精品国产亚洲一区二区三区| 亚洲精品极品| 葵司免费一区二区三区四区五区| 国产精品分类| 一区二区欧美日韩| 亚洲福利视频网| 久久精品一区二区三区四区| 国产精品三级视频| 黄色成人91| 日韩视频在线播放| 久久婷婷蜜乳一本欲蜜臀| 亚洲欧美制服中文字幕| 国产精品成人一区二区艾草| 亚洲精品乱码视频| 欧美成人综合在线| 久久视频在线视频| 亚洲二区三区四区| 每日更新成人在线视频| 亚洲在线中文字幕| 国产精品激情av在线播放| 99在线热播精品免费99热| 亚洲黄色高清| 欧美精品在线免费| 妖精视频成人观看www| 亚洲国产高清aⅴ视频| 美女久久网站| 麻豆精品精华液| 久久久久www| 亚洲视屏一区| 欧美视频官网| 亚洲欧美日韩一区二区三区在线观看 | 另类av一区二区| 午夜精品久久久久久久99黑人 | 久久国产婷婷国产香蕉| 国产亚洲一二三区| 久久岛国电影| 久久精品一区四区| 亚洲国产高清在线| 亚洲精品国产品国语在线app| 欧美成人精品不卡视频在线观看| 亚洲激情自拍| 欧美v国产在线一区二区三区| 亚洲综合视频在线| 黄色亚洲精品| 可以看av的网站久久看| 久久综合九色综合久99| 99在线精品视频| 欧美高清视频| 免费不卡亚洲欧美| 亚洲日本视频| 亚洲欧美另类综合偷拍| 欧美久久久久久久| 欧美一区二区在线| 免费亚洲婷婷| 亚洲欧美日韩专区| 久久久久一区二区三区| 99re6热在线精品视频播放速度| 亚洲一区在线播放| 亚洲人精品午夜| 亚洲一区二区三区四区在线观看| 韩日成人av| 一区二区三区四区五区精品| 伊大人香蕉综合8在线视| 亚洲美洲欧洲综合国产一区| 国产亚洲亚洲| 99国产一区二区三精品乱码| 狠狠色狠狠色综合日日五| 亚洲三级电影在线观看 | 欧美激情乱人伦| 99国产精品自拍| 久久国产乱子精品免费女| 日韩午夜激情电影| 久久精品国产v日韩v亚洲 | 国产精品视区| 在线免费观看视频一区| 欧美激情网友自拍| 国产视频在线观看一区| 亚洲高清毛片| 国产综合欧美| 亚洲午夜av| 亚洲精选91| 老司机aⅴ在线精品导航| 久久精品男女| 国产精品腿扒开做爽爽爽挤奶网站| 欧美成人激情在线| 国产亚洲欧美一区二区三区| 亚洲视频一区在线| 亚洲大片精品永久免费| 午夜亚洲激情| 欧美夜福利tv在线| 久久躁日日躁aaaaxxxx| 久久精品视频免费播放| 欧美激情按摩| 欧美大香线蕉线伊人久久国产精品| 国产精品青草久久久久福利99| 亚洲国产精品悠悠久久琪琪| 一区二区视频免费完整版观看| 亚洲中无吗在线| 在线观看一区欧美| 久久久久欧美精品| 麻豆国产va免费精品高清在线| 国产视频自拍一区| 欧美在线一级视频| 久久久一区二区三区| 国产日韩精品在线| 欧美一区网站| 久久亚洲美女| 亚洲电影av| 欧美v国产在线一区二区三区| 欧美freesex8一10精品| 亚洲国产你懂的| 欧美96在线丨欧| 亚洲日本无吗高清不卡| 国产精品99久久久久久白浆小说| 欧美日韩另类国产亚洲欧美一级| 日韩视频不卡中文| 亚洲欧美日韩中文视频| 国产欧美日韩综合一区在线观看 | 玖玖精品视频| 久久精品国产69国产精品亚洲| 久久精品30| 欧美怡红院视频| 国产一区二区三区四区三区四| 久久男人资源视频| 日韩视频永久免费观看| 欧美亚洲午夜视频在线观看| 国产欧美日韩高清| 久久婷婷国产麻豆91天堂| 亚洲精品美女久久久久| 久久爱www久久做| 亚洲人成在线观看| 黄色亚洲免费| 国产精品一区亚洲| 欧美午夜精品久久久久久久| 欧美大片一区| 另类成人小视频在线| 欧美专区一区二区三区| 亚洲欧美在线看|