亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? g09-01.cpp

?? 模擬游戲中人的行走
?? CPP
?? 第 1 頁 / 共 2 頁
字號:
// ============================================================================
// G09-01.cpp
// Adventure Game Demo v1
// ============================================================================
#include "SDL.h"
#include "SDLHelpers.h"
#include "Array.h"
#include "Array3D.h"
#include <stdlib.h>


// ============================================================================
//  Global Constants
// ============================================================================
const char PROGRAM_NAME[]   = "Adventure Game Demo v1";
const int WIDTH             = 800;
const int HEIGHT            = 600;

const int TILES             = 24;
const int ITEMS             = 14;
const int PEOPLE            = 3;
const int MOVETIME          = 750;

const int DIRECTIONS = 4;
const int FRAMES = 4;




#include "Object.h"
#include "Map.h"
#include "TileMap.h"


// ============================================================================
//  Function Headers
// ============================================================================
void DrawStatus();
void AddPersonToArray( Person* p_person );
void AddPersonToMap( Person* p_person );
float Distance( Object* p_object1, Object* p_object2 );
void PerformAI( int p_time );
void Attack( Person* p_person );
void CheckForDeadPeople();
void Init();
Map* LoadMap( char* p_filename );
void SetNewMap( char* p_filename );

// ============================================================================
//  Global Variables
// ============================================================================

// this is the main window for the framework
SDL_Surface* g_window = 0;

// the bitmaps
SDL_Surface* g_tiles[TILES];
SDL_Surface* g_items[ITEMS];
SDL_Surface* g_people[PEOPLE][DIRECTIONS][FRAMES];
SDL_Surface* g_statusbar;
SDL_Surface* g_verticalbar;
SDL_Surface* g_youlose;


// current map and player
Map* g_currentmap = 0;
Person* g_currentplayer = 0;

// array of people in the map.
Array<Person*> g_peoplearray( 128 );
int g_peoplecount;

// is the user dead?
bool g_dead = false;

// cheat mode on?
bool g_cheat = false;


// ============================================================================
//  Drawing Functions
// ============================================================================
// this draws the players status
void DrawStatus()
{   
    int x;
    int i;

    // blit the status bar
    SDLBlit( g_statusbar, g_window, 16, 488 );


    // get an iterator pointing to the item 2 places before the current.
    DListIterator<Item*> itr = g_currentplayer->GetItemIterator();
    
    for( x = 2; x > 0; x-- )
    {
        // move the iterator backwards
        itr.Back();

        if( itr.Valid() == false )
        {
            // if the iterator is not valid, then the algorithm went past
            // the beginning. So, make the iterator valid again
            // and set x so that it exits the loop
            itr.Start();
            i = x;
            x = -1;
        }
        else
        {
            i = x - 1;
        }
    }

    
    // draw the inventory
    for( x = i; x < 5; x++ )
    {
        SDLBlit( itr.Item()->GetGraphic(), g_window,
                 67 * x + 27, 511 );

        // move the iterator forward
        itr.Forth();

        // if the iterator is invalid, then the end of the inventory
        // has been reached, so set x so that the loop exits out
        if( itr.Valid() == false )
            x = 6;
    }
    


    // draw the health bar
    SDLBox( g_window, 520, 503, 
            (248 * g_currentplayer->GetHealth()) / 100,
            16, BLUE );

    // draw the Armor bar
    SDLBox( g_window, 520, 544, 
            (248 * g_currentplayer->GetArmor()) / 100,
            16, GREEN );


    // draw the attack bar background
    SDLBlit( g_verticalbar, g_window, 736, 232 );

    // get the weapon speed
    x = g_currentplayer->GetCurrentWeapon()->GetSpeed();

    // get the amount of time that has passed since the last time
    // the player attacked
    i = SDL_GetTicks() - g_currentplayer->GetAttackTime();

    // now figure out the height of the attack bar
    if( i >= x )
    {
        x = 235;
    }
    else
    {
        x = (235 * i) / x;
    }

    // finally, draw the actual bar
    SDLBox( g_window, 746, 243 + (235 - x), 28, x, RED );

}


// ============================================================================
//  Game Functions
// ============================================================================
void AddPersonToArray( Person* p_person )
{
    // add the person to the array.
    g_peoplearray[g_peoplecount] = p_person;

    // increment the number of people in the array
    g_peoplecount++;

    // resize the people array if you ran out of room
    if( g_peoplecount == g_peoplearray.Size() )
        g_peoplearray.Resize( g_peoplecount + 128 );
}


float Distance( Object* p_object1, Object* p_object2 )
{
    // perform the pythagorean theorem on the 
    // coordinates of the two objects.
    int dx = p_object1->GetX() - p_object2->GetX();
    int dy = p_object1->GetY() - p_object2->GetY();
    return (float)sqrt( (float)(dx*dx + dy*dy) );
}


void PerformAI( int p_time )
{
    int i;
    float dist;
    int direction;

    // loop through each person
    for( i = 0; i < g_peoplecount; i++ )
    {
        // if the person isn't the current player
        if( g_peoplearray[i] != g_currentplayer )
        {
            // get the direction that the AI needs to
            // face in order to look at the player
            direction = 
                g_currentmap->GetClosestDirection( g_peoplearray[i],
                                                   g_currentplayer );

            // get the distance from the player to the current AI.
            dist = Distance( g_peoplearray[i], g_currentplayer );

            // check to see if the person is within sight range, and
            // the appropriate amount of time has passed
            if( dist > 1.0f && dist <= 6.0f &&
                p_time - g_peoplearray[i]->GetMoveTime() > MOVETIME )
            {
                // reset the movement timer
                g_peoplearray[i]->SetMoveTime( p_time );

                // set the new direction, and move the person closer
                g_peoplearray[i]->SetDirection( direction );
                g_currentmap->Move( g_peoplearray[i], direction );
            }
            if( dist <= 1.0f )
            {
                // turn the person towards the player, and attack
                g_peoplearray[i]->SetDirection( direction );
                Attack( g_peoplearray[i] );
            }
        }
    }
}



void Attack( Person* p_person )
{
    int time;
    int difference;
    int cell;
    Item* weapon;
    Person* person;

    // get the current time.
    time = SDL_GetTicks();

    // get the time difference
    difference = time - p_person->GetAttackTime();

    // get the weapon index;
    weapon = p_person->GetCurrentWeapon();


    // if the player can attack...
    if( difference >= weapon->GetSpeed() )
    {
        // get the cell number that the player is facing
        cell = g_currentmap->GetCellNumber( p_person->GetCell(), 
                                            p_person->GetDirection() );

        // get the person in that cell.
        person = g_currentmap->GetPerson( cell );

        // check to see if there is a person actually there
        if( person != 0 )
        {
            // hit the object
            p_person->Attack( person );

            // reset the attack counter
            p_person->SetAttackTime( time );
        }
    }
}


void PickUp( Person* p_person )
{
    Item* i = g_currentmap->GetItem( p_person->GetCell() );
    if( i != 0 )
    {
        p_person->PickUp( i );
        g_currentmap->SetItem( p_person->GetCell(), 0 );
    }
}


void CheckForDeadPeople()
{
    int i;
    Person* p;

    // scan through the list of people
    for( i = 0; i < g_peoplecount; i++ )
    {
        // if the person is dead, and not the current player,
        // then remove the person
        if( g_peoplearray[i]->IsDead() ) 
        {
            if( g_peoplearray[i] == g_currentplayer )
            {
                g_dead = true;
                return;
            }
         
            // keep track of the dead player, 
            // and "Fast Remove" him from the array.
            p = g_peoplearray[i];
            g_peoplearray[i] = g_peoplearray[g_peoplecount - 1];
            g_peoplecount--;
            i--;

            // remove him from the map
            g_currentmap->SetPerson( p->GetCell(), 0 );

            // finally, delete the player
            delete p;
        }
    }
}




// ============================================================================
//  Initialize the game
// ============================================================================
void Init()
{
    int x;
    int d, f;
    
    // load the bmps
    g_tiles[0] = SDL_LoadBMP( "grass1.bmp" );
    g_tiles[1] = SDL_LoadBMP( "grass2.bmp" );
    g_tiles[2] = SDL_LoadBMP( "grass3.bmp" );
    g_tiles[3] = SDL_LoadBMP( "grass4.bmp" );

    // snow1
    g_tiles[4] = SDL_LoadBMP( "snow1.bmp" );
    g_tiles[5] = SDL_LoadBMP( "snow2.bmp" );

    // road1
    g_tiles[6] = SDL_LoadBMP( "roadh.bmp" );
    g_tiles[7] = SDL_LoadBMP( "roadv.bmp" );
    g_tiles[8] = SDL_LoadBMP( "roadtopleft.bmp" );
    g_tiles[9] = SDL_LoadBMP( "roadtopright.bmp" );
    g_tiles[10] = SDL_LoadBMP( "roadbottomleft.bmp" );
    g_tiles[11] = SDL_LoadBMP( "roadbottomright.bmp" );


    // layer 1 bmps:

    // snow2
    g_tiles[12] = SDL_LoadBMP( "snowtop.bmp" );
    g_tiles[13] = SDL_LoadBMP( "snowbottom.bmp" );
    g_tiles[14] = SDL_LoadBMP( "snowleft.bmp" );
    g_tiles[15] = SDL_LoadBMP( "snowright.bmp" );

    // snow 3
    g_tiles[16] = SDL_LoadBMP( "snowotl.bmp" );
    g_tiles[17] = SDL_LoadBMP( "snowotr.bmp" );
    g_tiles[18] = SDL_LoadBMP( "snowobl.bmp" );
    g_tiles[19] = SDL_LoadBMP( "snowobr.bmp" );
    g_tiles[20] = SDL_LoadBMP( "snowitl.bmp" );
    g_tiles[21] = SDL_LoadBMP( "snowitr.bmp" );
    g_tiles[22] = SDL_LoadBMP( "snowibl.bmp" );
    g_tiles[23] = SDL_LoadBMP( "snowibr.bmp" );



    // players
    g_people[0][0][0] = SDL_LoadBMP( "hero1u1.bmp" );

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
色一情一乱一乱一91av| 麻豆91在线播放免费| 日韩一区和二区| 精品视频免费在线| 欧美日韩一区二区在线观看| av影院午夜一区| 成人黄色av网站在线| 成人性视频网站| 不卡一区在线观看| 一本大道av伊人久久综合| 成人ar影院免费观看视频| www.av精品| 91美女精品福利| 欧美图片一区二区三区| 欧美一级欧美三级| 日本一区二区成人| |精品福利一区二区三区| 亚洲国产精品久久久久婷婷884 | 欧美成人一区二区三区片免费| 久久亚洲一区二区三区明星换脸 | 免费在线看成人av| 九九在线精品视频| 日本道免费精品一区二区三区| 奇米色一区二区| 国产东北露脸精品视频| 欧美视频一区二区三区四区| 国产欧美日韩一区二区三区在线观看| 亚洲成人自拍网| 一本到一区二区三区| 精品污污网站免费看| 91精品国产综合久久蜜臀| 亚洲国产精品t66y| 亚洲mv在线观看| 成人免费视频网站在线观看| 91福利社在线观看| 精品国产乱码91久久久久久网站| 国产欧美综合在线| 亚洲成人777| 97se亚洲国产综合自在线观| 欧美一区二区三区成人| 亚洲激情综合网| 国产精品99久久久久久似苏梦涵| 在线观看视频一区| 国产精品入口麻豆原神| 美女视频黄a大片欧美| 一本到不卡精品视频在线观看| 久久婷婷综合激情| 久色婷婷小香蕉久久| 精品欧美乱码久久久久久| 中文字幕巨乱亚洲| 免费在线观看日韩欧美| 欧美亚洲综合一区| 亚洲欧美另类小说| 成人国产精品免费观看| 日韩精品一区二区三区在线观看 | 成人午夜电影久久影院| 欧美福利视频导航| 亚洲资源在线观看| 一本到三区不卡视频| 亚洲女同ⅹxx女同tv| 成人avav在线| 日韩毛片精品高清免费| 成人高清视频在线| 亚洲视频小说图片| 99久久99久久久精品齐齐 | 亚洲精品综合在线| av网站一区二区三区| 国产精品国产三级国产普通话99 | 色婷婷综合中文久久一本| |精品福利一区二区三区| 欧美午夜片在线看| 久国产精品韩国三级视频| 国产视频一区二区三区在线观看| 高清在线不卡av| 亚洲一区二区三区免费视频| 91丨porny丨蝌蚪视频| 亚洲自拍偷拍av| 欧美成人video| 国产很黄免费观看久久| 国产精品传媒入口麻豆| 91国偷自产一区二区开放时间 | 麻豆精品视频在线观看视频| 精品国产乱码久久久久久1区2区| 国产麻豆成人传媒免费观看| 国产精品久久一卡二卡| 在线观看视频91| 老司机精品视频导航| 国产精品国产馆在线真实露脸| 欧美一a一片一级一片| 久久99久久99| 亚洲国产欧美日韩另类综合 | 一本久道久久综合中文字幕| 琪琪一区二区三区| 亚洲精选一二三| 国产精品天美传媒沈樵| 欧美日本在线播放| 成人高清免费观看| 韩国av一区二区三区在线观看| 亚洲自拍都市欧美小说| 日本一区二区三区在线观看| 制服丝袜激情欧洲亚洲| 色综合色狠狠综合色| 国产精品资源在线| 免费成人性网站| 天天影视涩香欲综合网| 一区二区三区在线高清| 国产精品电影院| 国产精品天干天干在线综合| 久久精品欧美日韩| 久久综合资源网| 欧美大片免费久久精品三p| 欧美一区二区黄| 在线不卡中文字幕| 欧美日韩电影一区| 欧美精品黑人性xxxx| 在线观看精品一区| 欧美日韩一区二区三区高清| 在线免费不卡视频| 日本韩国一区二区| 欧美在线视频全部完| 欧美伊人久久久久久午夜久久久久| 91蜜桃视频在线| 欧美日韩国产大片| 日韩一本二本av| 久久久久久久综合色一本| 久久久久久久久久久久久女国产乱| 久久九九久精品国产免费直播| 欧美第一区第二区| 中文字幕欧美日韩一区| 亚洲激情成人在线| 日韩av电影一区| 国产精品一区二区视频| 99re这里只有精品视频首页| 欧美性猛交xxxx乱大交退制版| 在线成人免费视频| 国产精品乱人伦| 日韩不卡在线观看日韩不卡视频| 国产一区二区91| 日本一二三四高清不卡| 亚洲成人av福利| 成人一二三区视频| 国产精品三级视频| 丝瓜av网站精品一区二区| 国产美女精品人人做人人爽| 91久久精品一区二区三| 2021久久国产精品不只是精品| 亚洲精品videosex极品| 国产一区三区三区| 欧美自拍丝袜亚洲| 国产精品丝袜黑色高跟| 蜜臀av性久久久久蜜臀aⅴ流畅| 成人av网站在线| 久久综合九色综合欧美98| 亚洲一区二区三区四区在线 | 色国产综合视频| 中文字幕欧美日本乱码一线二线| 三级精品在线观看| 欧美性xxxxxxxx| 中文字幕日韩av资源站| 国产在线观看一区二区| 亚洲人成影院在线观看| 懂色av噜噜一区二区三区av| 精品国产乱码久久| 免费成人性网站| 欧美一级片在线看| 强制捆绑调教一区二区| 欧美精选在线播放| 亚洲高清视频在线| 欧美日韩电影在线播放| 亚洲成人综合视频| 欧美日韩精品欧美日韩精品| 亚洲一级在线观看| 欧美日韩激情一区二区| 天堂资源在线中文精品| 6080日韩午夜伦伦午夜伦| 免费在线观看日韩欧美| 久久综合资源网| 国产aⅴ精品一区二区三区色成熟| 国产亚洲自拍一区| 成人黄色777网| 亚洲午夜免费视频| 欧美xxxx老人做受| 成人永久看片免费视频天堂| 亚洲三级电影全部在线观看高清| 色综合久久天天| 日韩有码一区二区三区| 久久久精品人体av艺术| 日本高清不卡一区| 麻豆成人91精品二区三区| 久久精品水蜜桃av综合天堂| 91女人视频在线观看| 日韩电影一区二区三区四区| 2019国产精品| 在线一区二区视频| 激情综合色播五月| 亚洲美女在线一区| 久久久久久影视| 56国语精品自产拍在线观看| 豆国产96在线|亚洲| 麻豆久久久久久久|