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

天行健 君子當自強而不息

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>
            一区二区三区视频在线| 欧美一二三区精品| 欧美国产日韩二区| 亚洲精品中文字幕女同| 亚洲精品一区二| 欧美日韩一区二区在线观看视频 | 国产精品成人在线观看| 中文在线不卡| 亚洲欧美在线一区二区| 国产一区二区精品久久99| 看片网站欧美日韩| 欧美日韩18| 欧美在线视频a| 久久久久久久久久看片| 亚洲肉体裸体xxxx137| 99视频在线观看一区三区| 国产区在线观看成人精品| 久久天天躁狠狠躁夜夜爽蜜月| 久久成人一区二区| 亚洲精品一区二区在线| 亚洲天堂av在线免费观看| 国产在线拍揄自揄视频不卡99 | 亚洲伦理网站| 亚洲欧美综合精品久久成人| 国语对白精品一区二区| 亚洲精品国产精品国产自| 国产精品久久久爽爽爽麻豆色哟哟| 久久久久中文| 欧美色欧美亚洲高清在线视频| 久久久久九九视频| 欧美精品精品一区| 久久综合国产精品| 欧美天天综合网| 欧美大片在线看| 国产欧美精品久久| 亚洲精品一区在线观看香蕉| 国产中文一区二区| 9色porny自拍视频一区二区| 在线观看一区| 亚洲一二三四区| 一区二区欧美国产| 久热精品视频在线观看| 欧美亚洲免费在线| 欧美性色综合| 欧美激情一区二区在线 | 欧美午夜片在线免费观看| 久久综合久久综合九色| 国产精品久久久久久久久婷婷 | 欧美激情va永久在线播放| 国产精品午夜在线观看| 日韩视频免费| 99精品欧美一区二区蜜桃免费| 欧美一区中文字幕| 久久精品在线| 国产欧美日本在线| 亚洲在线一区| 亚洲欧美国产精品桃花| 欧美日韩视频在线第一区| 欧美激情 亚洲a∨综合| 在线观看视频一区二区| 久久黄金**| 美女视频黄 久久| 尤物99国产成人精品视频| 欧美中文日韩| 你懂的视频欧美| 在线免费观看日韩欧美| 久久久伊人欧美| 麻豆精品视频在线观看视频| 在线电影一区| 免费亚洲一区二区| 91久久精品视频| 日韩香蕉视频| 欧美天堂亚洲电影院在线播放| 亚洲九九爱视频| 亚洲影院免费| 国产欧美日韩视频| 欧美伊久线香蕉线新在线| 久久在线免费观看视频| 亚洲成人影音| 欧美精品18| 一区二区三区色| 久久久久久久网站| 在线免费观看成人网| 欧美激情1区2区3区| 亚洲毛片av| 久久精品观看| 亚洲国产精品专区久久| 欧美日韩理论| 亚洲欧美日韩精品久久久久| 久久天堂国产精品| 99精品福利视频| 国产精品稀缺呦系列在线| 久久精品国产一区二区三区免费看 | 国产伦精品一区二区三区四区免费 | 亚洲一区二三| 国产在线欧美日韩| 欧美日韩国产大片| 午夜在线视频观看日韩17c| 免费成人黄色av| 亚洲一区二区毛片| 狠狠色狠狠色综合系列| 欧美日韩一区二区三区在线看| 亚洲自啪免费| 最新热久久免费视频| 欧美一级艳片视频免费观看| 1000部精品久久久久久久久| 欧美日韩在线综合| 久久先锋资源| 亚洲欧美在线x视频| 欧美激情影院| 久久精品亚洲| 亚洲欧美成人在线| 亚洲国内自拍| 国内成人自拍视频| 国产精品久久777777毛茸茸| 老司机午夜精品| 欧美一区日韩一区| 99精品国产在热久久婷婷| 免费欧美高清视频| 久久久久久久性| 亚洲综合国产激情另类一区| 亚洲精华国产欧美| 伊人蜜桃色噜噜激情综合| 欧美日韩亚洲一区二区三区| 久久中文精品| 久久精品国产精品亚洲| 亚洲影院色无极综合| 亚洲精品一区二区网址| 亚洲国产精品久久久| 久久久久在线观看| 久久国产精品亚洲77777| 亚洲欧美日韩精品久久久| 日韩亚洲国产欧美| 亚洲精品乱码久久久久| 亚洲国产色一区| 亚洲国产高清aⅴ视频| 一区二区在线观看视频| 国产午夜精品久久久久久久| 国产精品久久久久aaaa| 国产精品美女| 国产目拍亚洲精品99久久精品| 国产精品国产三级国产专区53| 欧美日韩精品久久| 欧美日本中文| 欧美四级在线观看| 国产精品久久久久久亚洲毛片| 欧美天天综合网| 国产精品青草久久| 国产精品一区二区在线| 国产欧美日韩视频| 国内精品一区二区| 在线日韩欧美| 亚洲区一区二| 亚洲香蕉网站| 欧美伊人久久大香线蕉综合69| 午夜激情一区| 久久九九热re6这里有精品| 久久先锋影音av| 欧美福利一区二区| 亚洲区免费影片| 亚洲色图综合久久| 欧美在线视频日韩| 欧美va亚洲va香蕉在线| 欧美片在线观看| 国产精品久久九九| 狠狠网亚洲精品| 亚洲精品在线一区二区| 亚洲欧美亚洲| 女主播福利一区| 一本到12不卡视频在线dvd| 性做久久久久久免费观看欧美| 久久先锋资源| 国产精品久久久对白| 合欧美一区二区三区| 亚洲免费av片| 久久精品一二三区| 亚洲国产精品久久久久久女王| 亚洲少妇在线| 久久一区二区三区超碰国产精品| 欧美精品在线观看91| 国产亚洲精品久久久久动| 亚洲美女黄色| 欧美综合国产精品久久丁香| 亚洲国产成人在线| 亚洲欧美欧美一区二区三区| 狼狼综合久久久久综合网| 欧美亚州韩日在线看免费版国语版| 国模套图日韩精品一区二区| 亚洲精品一区久久久久久| 久久精品一区蜜桃臀影院| 亚洲精品自在久久| 久久亚洲一区二区三区四区| 欧美四级电影网站| 亚洲人成高清| 久久视频免费观看| 亚洲欧美久久久久一区二区三区| 免费观看成人www动漫视频| 国产日韩欧美视频| 亚洲欧美www| 亚洲大胆视频|