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

天行健 君子當自強而不息

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 閱讀(465) 評論(0)  編輯 收藏 引用


只有注冊用戶登錄后才能發表評論。
網站導航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


公告

導航

統計

常用鏈接

隨筆分類(178)

3D游戲編程相關鏈接

搜索

最新評論

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            夜夜嗨av色一区二区不卡| 午夜精品福利一区二区三区av| 久久精品盗摄| 欧美亚洲一区二区在线| 国产一区二区| 久久在线播放| 麻豆精品传媒视频| 亚洲欧洲一区| 夜夜嗨av色综合久久久综合网| 欧美日韩成人在线| 亚洲——在线| 久久久人成影片一区二区三区观看| 黄色日韩网站| 亚洲人永久免费| 国产精品久久久久国产a级| 亚洲欧美日韩一区二区三区在线观看 | 亚洲第一色在线| 欧美高清日韩| 西西人体一区二区| 麻豆国产va免费精品高清在线| 一区二区三区产品免费精品久久75 | 99亚洲精品| 黄色精品一二区| 亚洲精品一区二区三区樱花| 国产日本欧美一区二区三区在线| 免费欧美在线视频| 欧美视频你懂的| 老司机精品福利视频| 欧美片第1页综合| 久久精品在线观看| 欧美日韩一区视频| 免费高清在线视频一区·| 欧美国产视频日韩| 久久久噜噜噜久久中文字免| 欧美高清日韩| 久久野战av| 国产精品美女一区二区| 欧美黄色成人网| 国产亚洲制服色| 国产精品99久久99久久久二8| 亚洲高清视频在线观看| 亚洲一区图片| 中日韩视频在线观看| 久久综合999| 欧美中文字幕不卡| 欧美亚洲成人精品| 亚洲国产精品视频一区| 精品av久久久久电影| 亚洲一区网站| 亚洲欧美国产制服动漫| 欧美精选午夜久久久乱码6080| 老司机一区二区三区| 国产欧美精品xxxx另类| 亚洲最新合集| 亚洲特级片在线| 欧美日韩福利| 亚洲精品永久免费精品| 亚洲韩国青草视频| 美女999久久久精品视频| 老司机aⅴ在线精品导航| 国产自产2019最新不卡| 新67194成人永久网站| 欧美一激情一区二区三区| 国产精品久久久久久久9999| 亚洲日本精品国产第一区| 亚洲国产三级网| 免费欧美高清视频| 欧美福利网址| 日韩午夜中文字幕| 欧美激情小视频| 亚洲精品系列| 亚洲在线国产日韩欧美| 国产精品qvod| 亚洲一区中文| 久久精品首页| 精品91在线| 蜜臀a∨国产成人精品| 欧美黄在线观看| 日韩亚洲在线| 欧美视频在线观看视频极品 | 欧美在线影院| 国内伊人久久久久久网站视频 | 亚洲伊人久久综合| 久久国产精品毛片| 亚洲第一级黄色片| 欧美激情综合色综合啪啪| 亚洲每日更新| 久久国内精品视频| 亚洲第一页在线| 欧美欧美在线| 午夜欧美视频| 亚洲国产精品美女| 新狼窝色av性久久久久久| 国产夜色精品一区二区av| 另类人畜视频在线| 一区二区高清视频| 久久久久久网| 一区二区免费看| 国产一区二区中文字幕免费看| 久久一二三四| 正在播放欧美一区| 欧美成人一区二区三区在线观看| 99精品国产热久久91蜜凸| 国产精品夜夜夜一区二区三区尤| 久久国产精品99国产精| 亚洲茄子视频| 久久久九九九九| 一区二区三区蜜桃网| 黄色成人在线| 国产精品任我爽爆在线播放| 久久久久网站| 亚洲自拍偷拍一区| 欧美激情中文字幕一区二区| 欧美影院在线| 日韩午夜av电影| 国内一区二区三区在线视频| 欧美日韩免费高清| 久久精品国产清自在天天线| aa级大片欧美| 亚洲人永久免费| 欧美sm重口味系列视频在线观看| 中文一区二区| 欧美福利电影网| 久久国产综合精品| 亚洲欧美www| 亚洲视频国产视频| 最新国产成人av网站网址麻豆| 国产亚洲毛片| 国产精品毛片在线| 国产精品xxx在线观看www| 欧美金8天国| 欧美二区在线播放| 免费毛片一区二区三区久久久| 久久精品国产91精品亚洲| 欧美一级大片在线观看| 亚洲午夜久久久久久久久电影院| 亚洲精品久久久久久久久久久久久 | 久久久久久久久久久久久久一区| 亚洲视频在线观看网站| 一区二区三区四区在线| 亚洲三级视频| 亚洲精品在线观看免费| 亚洲国产婷婷香蕉久久久久久| 激情久久久久久| 悠悠资源网久久精品| 伊人婷婷久久| 亚洲高清不卡一区| 亚洲三级网站| 一区二区三区日韩在线观看| 一区二区三区免费观看| 亚洲一级黄色av| 亚洲欧美精品伊人久久| 午夜国产精品视频| 久久久国产精品一区| 久久久噜噜噜久久人人看| 老牛影视一区二区三区| 亚洲国产va精品久久久不卡综合| 亚洲国产裸拍裸体视频在线观看乱了 | 亚洲精品国产精品国自产观看浪潮 | 美日韩精品视频免费看| 免费在线观看日韩欧美| 欧美福利影院| 国产精品第三页| 国产乱码精品| 伊人久久婷婷色综合98网| 亚洲日本精品国产第一区| 国产精品99久久久久久久vr| 欧美一区二区黄色| 久久网站热最新地址| 亚洲第一色在线| 一区二区欧美在线观看| 欧美综合国产| 欧美精品一区二区视频| 国产精品久久久久999| 国内揄拍国内精品久久| 日韩午夜免费视频| 欧美在线视频一区二区| 欧美国产成人精品| 国产精品99久久久久久人| 久久精品盗摄| 欧美色图天堂网| 黄色日韩网站视频| 亚洲一区二区3| 牛牛影视久久网| 亚洲一二三级电影| 免费看精品久久片| 国产日韩欧美不卡| 亚洲美女视频网| 久久伊伊香蕉| 亚洲综合色丁香婷婷六月图片| 久久久久久久久蜜桃| 国产精品日韩一区二区| 亚洲精品免费一二三区| 久久精品国产亚洲一区二区| 最新国产成人在线观看| 久久久久五月天| 国产区在线观看成人精品| 一区二区激情视频| 亚洲国产精品成人一区二区| 欧美一区二区高清在线观看|