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

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

?? gd23-04.cpp

?? 游戲開發(fā)數(shù)據(jù)結構-Data.Structures.for.Game.Programmers
?? CPP
?? 第 1 頁 / 共 2 頁
字號:
// ============================================================================
//  GD23-04.cpp
//  A-Star Pathfinding Demo
// ============================================================================
#include "SDLGUI.h"
#include <stdlib.h>
#include <time.h>
#include "Array2D.h"
#include "Queue.h"
#include "Heap.h"

// ============================================================================
//  Global Constants
// ============================================================================
const char PROGRAM_NAME[]   = "A* Pathfinding Graphical Demonstration";
const int WIDTH             = 800;
const int HEIGHT            = 600;
const int ITEMS             = 32;
const int ARIAL             = 0;
const int MAPX              = 32;
const int MAPY              = 20;


const int QUEUESIZE = 1024;
const int DIRTABLE[8][2] = { { 0, -1 },
                           { 1, 0 },
                           { 0, 1 },
                           { -1, 0 },
                           { 1, -1 },
                           { 1, 1 },
                           { -1, 1 },
                           { -1, -1 } };

const float DISTTABLE[8] = { 1.0f, 1.0f, 1.0f, 1.0f,
                             1.414214f, 1.414214f, 1.414214f, 1.414214f };

// ============================================================================
//  classes
// ============================================================================
class Cell
{
public:
    // is the cell marked or in the queue?
    bool m_marked;
    bool m_inQueue;

    // what is the distance from this cell to the starting cell?
    float m_distance;

    // the previous node in the path.
    int m_lastx;
    int m_lasty;


    // is the cell passable?
    bool m_passable;

    // what is the "cost" of travelling into this cell?
    float m_weight;
};


enum COMMAND
{
    ENQUEUE,
    DEQUEUE,
    CHANGEPOINTER
};

class Command
{
public:
    COMMAND c;
    int x;
    int y;
    int newx;
    int newy;
};

class Coordinate
{
public:
    int x;
    int y;
    float heuristic;
};


// ============================================================================
//  Global Variables
// ============================================================================
SDLGUI* g_gui;

SDL_Surface* g_blackbox = 0;
SDL_Surface* g_redbox = 0;
SDL_Surface* g_greenbox = 0;
SDL_Surface* g_bluebox = 0;
SDL_Surface* g_wallbox = 0;
SDL_Surface* g_start = 0;
SDL_Surface* g_goal = 0;

Array2D<Cell> g_map( MAPX, MAPY );

int g_startx = -1, 
    g_starty = -1;
int g_goalx = -1, 
    g_goaly = -1;
int g_currentx = -1,
    g_currenty = -1;

bool g_processing = false;
bool g_done = false;

bool g_mousedown = false;
bool g_walldraw = false;
float g_weight = 1.0f;

int g_timer;
int g_timeLength = 100;

LQueue<Command> g_queue;


// ============================================================================
//  Drawing
// ============================================================================
void DrawMap()
{
    int x;
    int y;

    SDL_Surface* color;
    SDL_Color col;
    Cell cell;

    for( y = 0; y < MAPY; y++ )
    {
        for( x = 0; x < MAPX; x++ )
        {
            // get the cell
            cell = g_map.Get( x, y );

            // get the color of the cell
            if( x == g_currentx && y == g_currenty )
                color = g_redbox;
            else if( cell.m_inQueue == true )
                color = g_greenbox;
            else if( cell.m_marked == true )
                color = g_bluebox;
            else if( cell.m_passable == false )
                color = g_wallbox;
            else
                color = g_blackbox;
                
            // blit the cell
            col.r = 255 - (cell.m_weight - 1) * 28;
            col.g = 255 - (cell.m_weight - 1) * 28;
            col.b = 255 - (cell.m_weight - 1) * 28;

            g_gui->Box( x * 24, y * 24, 24, 24, col );
            g_gui->Blit( color, x * 24, y * 24 );
        }
    }

    // go through again and draw the pointer lines
    for( y = 0; y < MAPY; y++ )
    {
        for( x = 0; x < MAPX; x++ )
        {
            // get the cell
            cell = g_map.Get( x, y );
            // if the cell has a pointer, draw the line
            if( cell.m_lastx != -1 && cell.m_lasty != -1 )
            {
                g_gui->Line( x * 24 + 12, 
                             y * 24 + 12, 
                             cell.m_lastx * 24 + 12, 
                             cell.m_lasty * 24 + 12,
                             BLACK );
            }
        }
    }

    if( g_startx != -1 && g_starty != -1 )
        g_gui->Blit( g_start, g_startx * 24, g_starty * 24 );
    if( g_goalx != -1 && g_goaly != -1 )
        g_gui->Blit( g_goal, g_goalx * 24, g_goaly * 24 );

    if( g_done == true )
    {
        x = g_goalx;
        y = g_goaly;

        // make sure there was a path
        if( g_map.Get( x, y ).m_lastx != -1 )
        {
            while( x != g_startx || y != g_starty )
            {
                cell = g_map.Get( x, y );
                g_gui->Line( x * 24 + 12, 
                             y * 24 + 12, 
                             cell.m_lastx * 24 + 12, 
                             cell.m_lasty * 24 + 12,
                             RED );
                g_gui->Line( x * 24 + 12, 
                             y * 24 + 13, 
                             cell.m_lastx * 24 + 12, 
                             cell.m_lasty * 24 + 13,
                             RED );
                g_gui->Line( x * 24 + 12, 
                             y * 24 + 11, 
                             cell.m_lastx * 24 + 12, 
                             cell.m_lasty * 24 + 11,
                             RED );
                x = cell.m_lastx;
                y = cell.m_lasty;
            }
        }
    }

    // draw the color square
    col.r = 255 - (g_weight - 1) * 28;
    col.g = 255 - (g_weight - 1) * 28;
    col.b = 255 - (g_weight - 1) * 28;
    g_gui->Box( WIDTH - 50, HEIGHT - 50, 50, 50, BLACK );
    g_gui->Box( WIDTH - 49, HEIGHT - 49, 48, 48, col );
}





// ============================================================================
//  Other Algorithms
// ============================================================================
void Clear()
{
    int x;
    int y;

    for( y = 0; y < MAPY; y++ )
    {
        for( x = 0; x < MAPX; x++ )
        {
            g_map.Get( x, y ).m_weight = 1.0f;
            g_map.Get( x, y ).m_passable = true;
        }
    }
}

void ClearMarks()
{
    int x;
    int y;

    for( y = 0; y < MAPY; y++ )
    {
        for( x = 0; x < MAPX; x++ )
        {
            g_map.Get( x, y ).m_marked = false;
            g_map.Get( x, y ).m_inQueue = false;
            g_map.Get( x, y ).m_lastx = -1;
            g_map.Get( x, y ).m_lasty = -1;
        }
    }
}

int CompareCoordinatesDescending( Coordinate left, Coordinate right )
{
    if( left.heuristic < right.heuristic )
        return 1;
    if( left.heuristic > right.heuristic )
        return -1;
    return 0;
}


void ClearCells( Array2D<Cell>& p_map )
{
    int x;
    int y;

    for( x = 0; x < p_map.Width(); x++ )
    {
        for( y = 0; y < p_map.Height(); y++ )
        {
            p_map.Get( x, y ).m_marked = false;
            p_map.Get( x, y ).m_inQueue = false;
            p_map.Get( x, y ).m_distance = 0.0f;
            p_map.Get( x, y ).m_lastx = -1;
            p_map.Get( x, y ).m_lasty= -1;
        }
    }
}


float CellDistance( int x1, int y1, int x2, int y2 )
{
    int dx = x1 - x2;
    int dy = y1 - y2;

    dx = dx * dx;
    dy = dy * dy;

    return (float)sqrt( (double)dx + (double)dy );
}



float AStarHeuristic( int x, int y, int gx, int gy, int dir )
{
    x = x + DIRTABLE[dir][0];
    y = y + DIRTABLE[dir][1];

    return CellDistance( x, y, gx, gy );
}


void PathAStar( Array2D<Cell>& p_map, 
                           int p_x, int p_y, 
                           int p_gx, int p_gy )
{
    Command com;
    Coordinate c;
    int x, y;
    int ax, ay;
    int dir;
    float distance;

    Heap<Coordinate> queue( QUEUESIZE, CompareCoordinatesDescending );

    // clear the cells first.
    ClearCells( p_map );
    
    // enqueue the starting cell in the queue
    c.x = p_x;
    c.y = p_y;
    queue.Enqueue( c );

    com.c = ENQUEUE;
    com.x = p_x;
    com.y = p_y;
    g_queue.Enqueue( com );

    // start the main loop
    while( queue.m_count != 0 )
    {
        // pull the first cell off the queue and process it.
        x = queue.Item().x;
        y = queue.Item().y;
        queue.Dequeue();

        com.c = DEQUEUE;
        com.x = x;
        com.y = y;
        g_queue.Enqueue( com );

        // make sure the node isn't already marked. If it is, do
        // nothing.
        if( p_map.Get( x, y ).m_marked == false )
        {
            // mark the cell as it is pulled off the queue.
            p_map.Get( x, y ).m_marked = true;

            // quit out if the goal has been reached.
            if( x == p_gx && y == p_gy )
                break;

            // loop through each direction.
            for( dir = 0; dir < 8; dir++ )
            {
                // retrieve the coordinates of the current adjacent cell
                ax = x + DIRTABLE[dir][0];
                ay = y + DIRTABLE[dir][1];

                // check to see if the adjacent cell is a valid index, 
                // passable, and not marked.
                if( ax >= 0 && ax < p_map.Width() && 

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美亚洲国产bt| 欧美激情一区二区三区四区| 欧美日韩在线一区二区| 这里是久久伊人| 欧美不卡在线视频| 中文字幕第一页久久| 一区二区欧美视频| 免费成人在线网站| 国产精品一二三四| 91一区一区三区| 欧美日韩国产免费一区二区| 亚洲6080在线| 国产在线不卡一卡二卡三卡四卡| 99re这里都是精品| 欧美一级搡bbbb搡bbbb| 久久久不卡网国产精品一区| 亚洲精品国产无套在线观| 午夜精品久久久久久久| 国产精品一区一区三区| 91国偷自产一区二区三区观看| 欧美一区二区三区视频| 国产精品免费人成网站| 视频一区在线播放| 高清成人在线观看| 欧美美女网站色| 国产精品欧美一级免费| 日韩精品成人一区二区在线| 成人免费电影视频| 日韩免费观看2025年上映的电影| 中文字幕制服丝袜成人av| 日韩av电影天堂| 99精品久久99久久久久| 精品久久久久久久久久久久包黑料| 日韩理论电影院| 精品制服美女丁香| 欧美日韩中文一区| 亚洲国产精品99久久久久久久久| 男人的天堂亚洲一区| 91老师片黄在线观看| 久久久www成人免费无遮挡大片| 亚洲一区二区三区在线| 成人黄色av电影| 欧美一区二区视频观看视频| 亚洲激情在线播放| 懂色av噜噜一区二区三区av| 自拍偷拍亚洲欧美日韩| 欧美日韩三级视频| 免费欧美高清视频| 91行情网站电视在线观看高清版| 国产日韩精品一区| 久久国产日韩欧美精品| 欧美日韩你懂得| 99久久久无码国产精品| 26uuu欧美日本| 日本免费在线视频不卡一不卡二| 91色视频在线| 国产精品欧美经典| 懂色av一区二区夜夜嗨| 亚洲精品一区二区三区在线观看| 亚洲不卡在线观看| 在线视频一区二区三| 成人欧美一区二区三区视频网页| 国产精品正在播放| 精品久久久久久亚洲综合网 | 一二三区精品福利视频| 懂色av一区二区夜夜嗨| 国产亚洲一区二区三区四区 | 日韩一区二区高清| 一区二区三区四区乱视频| proumb性欧美在线观看| 中文字幕成人网| 成人白浆超碰人人人人| 欧美国产丝袜视频| 成人18精品视频| 中文字幕久久午夜不卡| 成人免费看视频| 日本一区二区不卡视频| 国产成人aaaa| 国产精品久久久久影院亚瑟| 成人小视频免费在线观看| 国产拍揄自揄精品视频麻豆| 国产高清不卡一区| 国产免费观看久久| 成a人片亚洲日本久久| 国产精品不卡在线观看| 91色视频在线| 亚洲网友自拍偷拍| 欧美片网站yy| 蜜桃av一区二区三区电影| 欧美一区二区成人| 精品亚洲免费视频| 久久精品亚洲一区二区三区浴池| 国产一区二区三区电影在线观看| 国产欧美一区在线| www.综合网.com| 亚洲综合清纯丝袜自拍| 欧美精品丝袜久久久中文字幕| 蜜臀av一级做a爰片久久| 欧美哺乳videos| 国产很黄免费观看久久| 成人欧美一区二区三区视频网页| 在线看不卡av| 蜜臀91精品一区二区三区 | 国产真实精品久久二三区| 国产视频一区二区在线| 91免费在线看| 日韩电影免费在线| 精品1区2区在线观看| 成人av在线资源| 亚洲第一成人在线| www久久精品| 99re热这里只有精品视频| 亚洲国产综合视频在线观看| 日韩一区二区在线观看视频播放| 国产老妇另类xxxxx| 亚洲欧洲日韩在线| 7777女厕盗摄久久久| 国产另类ts人妖一区二区| 亚洲欧美另类久久久精品 | 美女网站在线免费欧美精品| 久久精品视频网| 色999日韩国产欧美一区二区| 日韩精品三区四区| 国产亚洲精品久| 欧美日韩一本到| 国产高清久久久| 天天做天天摸天天爽国产一区| 久久香蕉国产线看观看99| 色婷婷狠狠综合| 韩国三级电影一区二区| 亚洲精品高清视频在线观看| 3d动漫精品啪啪一区二区竹菊| 丰满少妇在线播放bd日韩电影| 亚洲国产日韩在线一区模特 | 成人免费高清视频| 日韩成人免费看| 国产精品国产三级国产| 91精品国产欧美一区二区 | 亚洲黄色片在线观看| 欧美成人福利视频| 91国产成人在线| 国产精品18久久久久久久久 | 色综合婷婷久久| 精品一区二区在线免费观看| 一区二区三区日本| 国产欧美精品一区二区色综合| 欧美人牲a欧美精品| 99精品视频在线免费观看| 国内精品第一页| 午夜欧美在线一二页| 亚洲欧美怡红院| 国产午夜一区二区三区| 欧美一区二区日韩| 在线观看国产日韩| 成人动漫一区二区在线| 国内精品写真在线观看| 五月天久久比比资源色| 亚洲精品久久嫩草网站秘色| 国产精品美女www爽爽爽| 日韩欧美电影一二三| 欧美日韩国产成人在线91| 91浏览器打开| 成人性视频免费网站| 国产一区二区精品久久99| 日本午夜一本久久久综合| 亚洲午夜久久久久中文字幕久| 亚洲视频在线一区| 国产精品三级av| 国产性天天综合网| 久久婷婷久久一区二区三区| 日韩欧美一级精品久久| 正在播放一区二区| 欧美日韩亚洲国产综合| 欧美自拍偷拍一区| 色综合久久久久综合99| av电影天堂一区二区在线| 国产成人在线影院| 国产乱码精品一区二区三区忘忧草| 久久国产视频网| 狠狠色狠狠色综合系列| 久久99深爱久久99精品| 美日韩一区二区| 日本不卡在线视频| 午夜精彩视频在线观看不卡| 亚洲国产综合人成综合网站| 亚洲狠狠爱一区二区三区| 亚洲成人黄色影院| 亚洲电影中文字幕在线观看| 亚洲国产视频网站| 天天亚洲美女在线视频| 天堂午夜影视日韩欧美一区二区| 午夜精品在线看| 日韩综合小视频| 日韩二区三区在线观看| 久久精品国产澳门| 国内精品久久久久影院色| 国产一区欧美二区| 国产91精品一区二区麻豆网站| 国产91精品一区二区麻豆网站 | 国产精品乱子久久久久|