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

? 歡迎來(lái)到蟲(chóng)蟲(chóng)下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲(chóng)蟲(chóng)下載站

?? gd23-04.cpp

?? 游戲開(kāi)發(fā)數(shù)據(jù)結(jié)構(gòu)-Data.Structures.for.Game.Programmers
?? CPP
?? 第 1 頁(yè) / 共 2 頁(yè)
字號(hào):
// ============================================================================
//  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() && 

?? 快捷鍵說(shuō)明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
裸体歌舞表演一区二区| 丁香五精品蜜臀久久久久99网站 | 久久久久久夜精品精品免费| 99国产精品久久久久久久久久| 免费视频最近日韩| 一区二区在线观看视频| 国产日韩v精品一区二区| 欧美三级电影一区| 99视频在线精品| 国产一区二区三区在线观看免费视频| 一级特黄大欧美久久久| 国产精品萝li| 精品久久99ma| 欧美日韩另类国产亚洲欧美一级| 99精品久久99久久久久| 国产精品1024| 久久超级碰视频| 日本欧美一区二区| 亚洲成人精品在线观看| 亚洲男人的天堂在线观看| 欧美国产乱子伦| 26uuu亚洲| 日韩欧美三级在线| 一区二区三区四区av| 国产欧美一区二区在线| 欧美精品一区二区久久婷婷| 欧美一区二区三区啪啪| 欧美影视一区在线| 在线中文字幕一区| 欧美中文字幕一二三区视频| 91老司机福利 在线| 91免费版在线| 色诱视频网站一区| 91丨porny丨在线| 99精品热视频| 91亚洲精华国产精华精华液| 不卡欧美aaaaa| 成+人+亚洲+综合天堂| 懂色av噜噜一区二区三区av| 成人涩涩免费视频| eeuss鲁片一区二区三区在线观看| 国产成人三级在线观看| 成人妖精视频yjsp地址| 国产精品夜夜爽| 成人久久18免费网站麻豆| 成人精品小蝌蚪| 97精品视频在线观看自产线路二| 91在线高清观看| 欧美在线视频全部完| 欧美日韩亚洲综合| 777色狠狠一区二区三区| 欧美一区二区三区四区在线观看| 欧美一级片在线看| 久久久99久久精品欧美| 国产清纯白嫩初高生在线观看91| 国产精品久久免费看| 中文字幕一区二区三区不卡在线| 一区二区三区产品免费精品久久75| 亚洲永久精品国产| 欧美精选在线播放| 精品久久久久久久久久久院品网| 久久久久久免费| 亚洲欧美偷拍三级| 日韩精品欧美成人高清一区二区| 免费日韩伦理电影| 成人蜜臀av电影| 欧美性色黄大片| 精品国产亚洲一区二区三区在线观看| 国产三级三级三级精品8ⅰ区| 国产精品久久久久久一区二区三区| 亚洲自拍另类综合| 精品一区二区三区影院在线午夜| 成人美女在线视频| 欧美区一区二区三区| 欧美精品一区二区三区四区 | 亚洲精品伦理在线| 石原莉奈一区二区三区在线观看| 国产在线精品一区二区| av在线综合网| 欧美一级专区免费大片| 国产精品成人免费| 日韩电影一区二区三区| 成人av动漫在线| 91精品综合久久久久久| 中文字幕欧美日韩一区| 亚洲成人自拍偷拍| 成人一级片网址| 91精选在线观看| 亚洲欧洲国产日本综合| 久久丁香综合五月国产三级网站 | 精品日韩欧美在线| 玉米视频成人免费看| 国产一区二区成人久久免费影院 | 一区二区三区四区在线播放| 蜜桃久久精品一区二区| 日本电影欧美片| 久久精品人人做人人爽人人| 天堂精品中文字幕在线| 91在线精品一区二区| 精品国产一区二区精华| 亚洲国产精品久久艾草纯爱| 成人教育av在线| 2020国产精品久久精品美国| 亚洲成人福利片| 91在线国内视频| 国产丝袜在线精品| 麻豆精品久久久| 欧美日韩一区 二区 三区 久久精品| 国产精品午夜春色av| 激情综合网av| 日韩亚洲欧美综合| 亚洲第一会所有码转帖| 日本精品免费观看高清观看| 日本一区二区免费在线| 精品一区在线看| 日韩视频永久免费| 日韩国产在线观看一区| 色噜噜狠狠色综合中国 | 美国毛片一区二区三区| 欧美午夜理伦三级在线观看| 国产精品久久久久久久岛一牛影视 | 亚洲成人动漫精品| 91精彩视频在线| 亚洲欧美日韩国产一区二区三区| 成人黄色综合网站| 欧美激情中文不卡| 岛国精品在线观看| 国产欧美综合在线| 高清不卡在线观看| 国产午夜精品一区二区三区视频 | 成人av免费观看| 中文字幕精品在线不卡| 国产a视频精品免费观看| 国产午夜精品理论片a级大结局 | 国产在线视视频有精品| 精品免费国产二区三区| 国产在线不卡一区| 国产呦精品一区二区三区网站| 日韩视频免费观看高清完整版 | 日韩激情av在线| 欧美久久久久免费| 日韩影院在线观看| 日韩一区二区三区三四区视频在线观看 | 精品不卡在线视频| 国产一区二区剧情av在线| 精品福利一区二区三区免费视频| 蜜臀va亚洲va欧美va天堂| 欧美成人女星排行榜| 久久国产尿小便嘘嘘| 久久只精品国产| av一二三不卡影片| 亚洲三级在线免费| 欧美精三区欧美精三区| 久久福利视频一区二区| 欧美激情一区二区三区不卡| 99热这里都是精品| 亚洲一区二区三区四区不卡| 欧美一区二区三区喷汁尤物| 国产精品亚洲人在线观看| 中文字幕亚洲在| 欧美理论在线播放| 国产精品亚洲一区二区三区在线 | 国产精品免费av| 色悠悠久久综合| 日本亚洲天堂网| 亚洲国产精品精华液ab| 欧美伊人久久大香线蕉综合69 | wwwwww.欧美系列| 99re视频这里只有精品| 五月激情综合婷婷| 久久精品亚洲一区二区三区浴池| 色综合久久中文字幕| 日本美女视频一区二区| 中文字幕不卡的av| 欧美亚男人的天堂| 国产精品一区二区免费不卡 | 国产精品美女久久久久久久久| 欧美午夜影院一区| 国产一区二区三区电影在线观看| 亚洲乱码国产乱码精品精小说| 日韩欧美亚洲国产精品字幕久久久| www.欧美亚洲| 蜜臀av一级做a爰片久久| 最新国产の精品合集bt伙计| 欧美一区二区三区男人的天堂| 97精品视频在线观看自产线路二 | 日本高清不卡aⅴ免费网站| 免费看欧美女人艹b| 亚洲欧洲精品成人久久奇米网 | 亚洲激情网站免费观看| 久久众筹精品私拍模特| 欧美乱妇一区二区三区不卡视频| 国产成人av福利| 日本视频免费一区| 亚洲精品亚洲人成人网在线播放| 国产喂奶挤奶一区二区三区| 91麻豆精品国产综合久久久久久| 95精品视频在线| 国产盗摄精品一区二区三区在线| 日韩不卡一区二区三区|