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

天行健 君子當自強而不息

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) 評論(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>
            亚洲日本激情| 国产伦精品一区二区三| 在线视频精品一区| 亚洲日韩视频| 亚洲国产va精品久久久不卡综合| 亚洲第一福利在线观看| 最近中文字幕日韩精品| 亚洲最新视频在线| 亚洲欧美激情一区| 久久女同互慰一区二区三区| 欧美精品videossex性护士| 欧美日韩一区二区免费视频| 国产精品一区二区久久国产| 国内伊人久久久久久网站视频| 亚洲国产精品一区制服丝袜 | 欧美国产精品中文字幕| 亚洲欧洲三级电影| 亚洲免费在线| 欧美成人午夜免费视在线看片| 欧美日韩视频第一区| 国外成人网址| 亚洲曰本av电影| 欧美激情久久久久久| 亚洲综合精品自拍| 欧美精品1区2区3区| 国产一区二区黄| 久久九九国产精品| 久久riav二区三区| 亚洲欧美日韩一区二区在线| 欧美一区二区三区久久精品茉莉花 | 欧美日韩高清免费| 国产九九视频一区二区三区| 在线日韩电影| 久久av最新网址| 亚洲免费观看| 久久久久www| 国产精品久久久久高潮| 亚洲黄色免费网站| 久久―日本道色综合久久| 日韩一级片网址| 麻豆9191精品国产| 韩国精品久久久999| 欧美一级网站| 99精品视频一区| 欧美成人日本| 怡红院av一区二区三区| 欧美专区亚洲专区| 一区二区三区四区五区视频| 农夫在线精品视频免费观看| 狠狠v欧美v日韩v亚洲ⅴ| 久久国产精彩视频| 亚洲欧美日韩精品在线| 国产精品乱码| 午夜在线不卡| 亚洲一区二区欧美日韩| 欧美视频官网| 亚洲男人的天堂在线aⅴ视频| 亚洲日本视频| 麻豆成人在线观看| 亚洲国产成人久久综合| 免费久久99精品国产自| 久久另类ts人妖一区二区| 国内激情久久| 玖玖玖免费嫩草在线影院一区| 午夜精品久久久久久久99樱桃 | 欧美一区观看| 国产综合久久| 麻豆国产va免费精品高清在线| 久久国产精品久久w女人spa| 黑人中文字幕一区二区三区| 免费在线亚洲欧美| 欧美h视频在线| 一区二区三区欧美在线| 亚洲深夜福利在线| 国产一区二区黄| 欧美一区二区高清在线观看| 国产日韩欧美高清免费| 欧美一区二区三区的| 性做久久久久久久免费看| 国产一区二区日韩精品欧美精品| 久久久久久97三级| 久久亚洲视频| 中日韩高清电影网| 性欧美在线看片a免费观看| 在线成人免费观看| 亚洲精品自在在线观看| 国产精品草草| 噜噜噜在线观看免费视频日韩| 久久在线视频| 亚洲桃花岛网站| 欧美专区亚洲专区| 亚洲人成网站在线播| 亚洲视频免费看| 怡红院精品视频| 日韩午夜精品| 韩日成人在线| 一区二区三区精品视频| 黄色精品一区二区| 亚洲精品日韩在线观看| 国产一区二区三区黄视频| 亚洲激情女人| 国产亚洲人成网站在线观看| 亚洲人午夜精品免费| 国产日产欧产精品推荐色 | 国产在线日韩| 亚洲欧洲日韩综合二区| 国产一区在线看| 夜夜嗨av色一区二区不卡| 在线不卡中文字幕| 亚洲一区二区三区午夜| 日韩视频中文| 久久久国产午夜精品| 午夜精品久久久久| 欧美精品午夜| 欧美~级网站不卡| 国产一区二区三区免费在线观看| 夜夜嗨av一区二区三区中文字幕| 亚洲国产精品精华液2区45| 亚洲女同性videos| 亚洲图片你懂的| 欧美日本免费| 亚洲国产一区二区三区青草影视 | 亚洲视频一二三| 开元免费观看欧美电视剧网站| 久久精品国产一区二区电影| 欧美特黄视频| 一区二区三区精品视频在线观看| 91久久精品www人人做人人爽| 欧美在线免费观看视频| 小嫩嫩精品导航| 国产精品久久久久久久久免费| 一区二区av在线| 亚洲乱码国产乱码精品精可以看| 一区二区日韩精品| 一区二区成人精品| 欧美乱妇高清无乱码| 亚洲高清视频中文字幕| 亚洲国产精品久久久久秋霞蜜臀| 久久国产精品色婷婷| 久久男人资源视频| 黄色成人在线网址| 久久久久9999亚洲精品| 久久久久久久久久看片| 精品成人在线视频| 久久综合狠狠综合久久综青草| 麻豆久久婷婷| 日韩亚洲欧美中文三级| 欧美日韩亚洲一区二区三区在线观看 | 91久久线看在观草草青青| 亚洲精品国产无天堂网2021| 欧美大学生性色视频| 亚洲高清激情| 亚洲香蕉成视频在线观看| 欧美婷婷六月丁香综合色| 亚洲一区在线视频| 噜噜噜躁狠狠躁狠狠精品视频| 亚洲国产精品女人久久久| 欧美成人综合| 亚洲一区二区三区精品视频| 久久久久久久综合狠狠综合| 亚洲福利在线看| 欧美日韩精品欧美日韩精品| 亚洲一二三区精品| 美女主播精品视频一二三四| 亚洲精选成人| 国产欧美一区二区三区久久| 美女免费视频一区| 日韩一区二区精品| 久久亚洲风情| 亚洲一区网站| 亚洲国产影院| 国产欧美 在线欧美| 免费观看亚洲视频大全| 一区二区三区四区国产| 久久综合中文色婷婷| a4yy欧美一区二区三区| 国产真实精品久久二三区| 欧美福利在线| 香蕉久久夜色精品国产| 亚洲黄色大片| 久久久久久久久蜜桃| 亚洲婷婷综合色高清在线 | 在线视频国产日韩| 国产精品欧美风情| 欧美国产亚洲精品久久久8v| 亚洲欧美日韩视频一区| 91久久精品www人人做人人爽| 久久gogo国模裸体人体| 亚洲精品美女久久久久| 国产原创一区二区| 国产精品国产三级国产aⅴ浪潮| 久久青青草综合| 中文一区二区| 亚洲精品一区二区三区99| 免费亚洲电影| 久久久久成人网| 欧美一区1区三区3区公司| 9久草视频在线视频精品| 亚洲国产日韩欧美综合久久| 国产精品久久一区二区三区|