最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C++基于easyx實現(xiàn)迷宮游戲

 更新時間:2022年05月11日 13:01:50   作者:Object_in_java  
這篇文章主要為大家詳細介紹了C++基于easyx實現(xiàn)迷宮游戲,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了C++基于easyx實現(xiàn)迷宮游戲的具體代碼,供大家參考,具體內(nèi)容如下

/*走迷宮*/
#define _CRT_SECURE_NO_DEPRECATEd
#define _CRT_SECURE_NO_WARNINGS

#include<graphics.h>
#include<conio.h>
#include<Windows.h>
#include<stdio.h>
#define LEFT?? ??? ??? ?0//方向
#define RIGHT?? ??? ??? ?1
#define UP?? ??? ??? ?0//由于當前素材只有左右二個方向,所以上下共用了左右方向
#define DOWN?? ??? ??? ?1

#define ROAD 0//地圖元素類型
#define WALL 1

#define ENTERX 1//入口 ?x列,y行
#define ENTERY 0

#define OUTX 11 //出口 x列,y行
#define OUTY 8

#define HUMANWIDTH?? ??? ?75
#define HUMANHEIGHT?? ??? ?130

#define WIDTH?? ??? ??? ?12//地圖大小
#define HEIGHT?? ??? ??? ?10

IMAGE img_human;
IMAGE img_human_mask;
IMAGE img_wall;
IMAGE img_road;

int moveNum[2] = { 0 };//當前動作序號
int direction;//上下左右四個方向
int human_witdh;
int human_height;
int x, y;//x列數(shù),y行數(shù)

int map[HEIGHT][WIDTH] = {//地圖
?? ?{ 1,1,1,1,1,1,1,1,1,1,1,1 },
?? ?{ 0,0,0,1,1,1,1,1,1,1,1,1 },
?? ?{ 1,1,0,1,1,1,1,0,1,1,1,1 },
?? ?{ 1,1,0,0,1,1,1,0,1,1,1,1 },
?? ?{ 1,1,1,0,1,1,1,0,1,1,1,1 },
?? ?{ 1,1,1,0,1,1,1,0,1,1,1,1 },
?? ?{ 1,1,1,0,1,1,1,0,1,1,1,1 },
?? ?{ 1,1,1,0,0,0,0,0,0,0,1,1 },
?? ?{ 1,1,1,1,1,1,1,1,1,0,0,0 },
?? ?{ 1,1,1,1,1,1,1,1,1,1,1,1 },
};

void showbk() {//繪制背景
?? ?for (int j = 0; j < WIDTH; j++)
?? ??? ?for (int i = 0; i < HEIGHT; i++)
?? ??? ??? ?if (map[i][j] == WALL)
?? ??? ??? ??? ?putimage(j * img_wall.getwidth(), i * img_wall.getheight(), img_wall.getwidth(), img_wall.getheight(), &img_wall, 0, 0, SRCCOPY);
?? ??? ??? ?else putimage(j * img_wall.getwidth(), i * img_wall.getheight(), img_wall.getwidth(), img_wall.getheight(), &img_road, 0, 0, SRCCOPY);

}
void start()//初始化
{
?? ?loadimage(&img_wall, _T(".\\walls.gif"));
?? ?initgraph(img_wall.getwidth() * WIDTH, img_wall.getheight() * HEIGHT);
?? ?loadimage(&img_human, _T(".\\行走素材圖.jpg"));
?? ?loadimage(&img_human_mask,_T( ".\\行走素材圖mask.jpg"));

?? ?human_witdh = 75;//img_human.getwidth()/4;
?? ?human_height = 130;//img_human.getheight()/2;
?? ??? ??? ??? ??? ? ? //putimage(x,y,HUMANWIDTH,HUMANHEIGHT,&img_human,0,0);
?? ?loadimage(&img_road, _T(".\\road.gif"));
?? ?x = 0;
?? ?y = 1;

}


void updateWithoutInput()
{

}
void drawRole(int x0, int y0)//繪制前景
{
?? ?putimage((x - x0 / 4.0) * img_wall.getwidth() - 7,
?? ??? ?(y - y0 / 4.0) * img_wall.getheight() - 70,
?? ??? ?human_witdh, human_height, &img_human_mask, moveNum[direction] * human_witdh, direction * (human_height - 10), NOTSRCERASE);
?? ?putimage((x - x0 / 4.0) * img_wall.getwidth() - 7,
?? ??? ?(y - y0 / 4.0) * img_wall.getheight() - 70,
?? ??? ?human_witdh, human_height, &img_human, moveNum[direction] * human_witdh, direction * (human_height - 10), SRCINVERT);
}
void show(int x0, int y0)
{

?? ?showbk();
?? ?//clearrectangle(x,y,x+human_witdh,y+human_height);?? ?
?? ?//先顯示背景
?? ?//準備好遮罩MASK圖和源圖,三元光柵操作
?? ?drawRole(x0, y0);
?? ?FlushBatchDraw();
?? ?Sleep(50);
}
void readRecordFile()
{//讀取存檔
?? ?FILE* fp;
?? ?int temp;
?? ?fp = fopen(".\\record.dat", "r");
?? ?fscanf(fp, "%d %d", &x, &y);
?? ?fclose(fp);

}
void WriteRecordFile()
{//保存存檔
?? ?FILE* fp;
?? ?int temp;
?? ?fp = fopen(".\\record.dat", "w");
?? ?fprintf(fp, "%d %d ", x, y);
?? ?fclose(fp);
}
void updateWithInput()
{//增加過度
?? ?char input;
?? ?int olddirection = direction;
?? ?int oldx = x;
?? ?int oldy = y;
?? ?/******異步輸入檢測方向鍵狀態(tài)
?? ?if(GetAsyncKeyState(VK_LEFT)&0x8000) ?向左
?? ?if(GetAsyncKeyState(VK_RIGHT)&0x8000) ?向右
?? ?if(GetAsyncKeyState(VK_UP)&0x8000) ?向上
?? ?if(GetAsyncKeyState(VK_DOWN)&0x8000) ?向下
?? ?********/
?? ?if (_kbhit())
?? ?{

?? ??? ?input = _getch();
?? ??? ?switch (input)
?? ??? ?{
?? ??? ?case 'a':direction = LEFT;?? ??? ?if (map[y][x - 1] == ROAD) x--; moveNum[direction] = 0; break;
?? ??? ?case 'd':direction = RIGHT;?? ??? ?if (map[y][x + 1] == ROAD) x++; moveNum[direction] = 0; break;
?? ??? ?case 'w':direction = UP;?? ??? ?if (map[y - 1][x] == ROAD) y--; moveNum[direction] = 0; break;
?? ??? ?case 's':direction = DOWN;?? ??? ?if (map[y + 1][x] == ROAD) y++; moveNum[direction] = 0; break;
?? ??? ?case 'W':WriteRecordFile(); break;
?? ??? ?case 'R':readRecordFile(); break;
?? ??? ?}
?? ??? ?if (x != oldx || y != oldy)
?? ??? ??? ?for (int i = 4; i > 0; i--)
?? ??? ??? ?{//過渡動畫
?? ??? ??? ??? ?show((x - oldx) * i, (y - oldy) * i);
?? ??? ??? ??? ?moveNum[direction]++;//動作序號,一個完整動作分解為四個姿勢
?? ??? ??? ??? ?moveNum[direction] %= 4;
?? ??? ??? ?}
?? ?}
}


int main()
{
?? ?start();
?? ?BeginBatchDraw();
?? ?while (1) {
?? ??? ?show(0, 0);
?? ??? ?Sleep(50);
?? ??? ?if (x == OUTX && y == OUTY)//到達了出口
?? ??? ?{
?? ??? ??? ?outtextxy(0, 0, _T("reach target!"));
?? ??? ??? ?Sleep(50);
?? ??? ??? ?break;
?? ??? ?}
?? ??? ?updateWithoutInput();
?? ??? ?updateWithInput();
?? ?}
?? ?EndBatchDraw();
?? ?_getch();
?? ?closegraph();
?? ?return 0;
}

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • C++中的字符串編碼處理方法

    C++中的字符串編碼處理方法

    這篇文章主要介紹了C++中的字符串編碼處理,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-05-05
  • C++實現(xiàn)簡單計算器

    C++實現(xiàn)簡單計算器

    這篇文章主要為大家詳細介紹了C++實現(xiàn)簡單計算器,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-05-05
  • C++實現(xiàn)猴子吃桃的示例代碼

    C++實現(xiàn)猴子吃桃的示例代碼

    這篇文章主要介紹了C++實現(xiàn)猴子吃桃的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-02-02
  • C++無鎖隊列的原理與實現(xiàn)示例

    C++無鎖隊列的原理與實現(xiàn)示例

    C++無鎖隊列是一種多線程編程技術(shù),它可以在不使用鎖的情況下實現(xiàn)線程安全的隊列,本文就來詳細的介紹一下C++無鎖隊列的原理與實現(xiàn)示例,具有一定的參考價值,感興趣的可以了解一下
    2024-01-01
  • c++用指針交換數(shù)組的實例講解

    c++用指針交換數(shù)組的實例講解

    下面小編就為大家分享一篇c++用指針交換數(shù)組的實例講解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2017-11-11
  • c++ 智能指針基礎(chǔ)詳解

    c++ 智能指針基礎(chǔ)詳解

    這篇文章主要介紹了c++ 智能指針基礎(chǔ)的相關(guān)資料,幫助大家更好的理解和學習使用c++,感興趣的朋友可以了解下
    2021-02-02
  • 全排列算法的非遞歸實現(xiàn)與遞歸實現(xiàn)的方法(C++)

    全排列算法的非遞歸實現(xiàn)與遞歸實現(xiàn)的方法(C++)

    本篇文章是對全排列算法的非遞歸實現(xiàn)與遞歸實現(xiàn)的方法進行了詳細的分析介紹,需要的朋友參考下
    2013-05-05
  • 使用UDP協(xié)議實現(xiàn)單詞翻譯服務(wù)器

    使用UDP協(xié)議實現(xiàn)單詞翻譯服務(wù)器

    這篇文章主要為大家詳細介紹了如何使用UDP協(xié)議實現(xiàn)英文單詞翻譯服務(wù)器,文中的示例代碼講解詳細,具有一定的學習價值,感興趣的小伙伴可以了解下
    2023-08-08
  • 為什么說C語言是永不過時的語言

    為什么說C語言是永不過時的語言

    時隔5年,C語言再次領(lǐng)先Java,榮登TIOBE編程語言排行榜第一,那么C語言為何不會過時?你需要掌握多少種語言呢,感興趣的朋友通過本文一起學習下吧
    2020-11-11
  • c++元編程模板函數(shù)重載匹配規(guī)則示例詳解

    c++元編程模板函數(shù)重載匹配規(guī)則示例詳解

    這篇文章主要為大家介紹了c++元編程模板函數(shù)重載匹配規(guī)則示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-01-01

最新評論

信阳市| 新邵县| 宜兰市| 吴旗县| 密山市| 仙居县| 雷山县| 梁平县| 庄河市| 开封县| 武隆县| 龙川县| 小金县| 柳州市| 同德县| 通江县| 青龙| 海城市| 丰县| 香港| 临漳县| 湾仔区| 黄梅县| 台州市| 榆林市| 沾化县| 阿拉善左旗| 澄城县| 铜梁县| 博乐市| 东阳市| 嵩明县| 万载县| 靖安县| 松潘县| 濉溪县| 阿合奇县| 闽侯县| 雅安市| 平凉市| 福安市|