pos機(jī)網(wǎng)站模板源碼,C++項(xiàng)目源碼——球球大作戰(zhàn)

 新聞資訊  |   2023-05-08 22:32  |  投稿人:pos機(jī)之家

網(wǎng)上有很多關(guān)于pos機(jī)網(wǎng)站模板源碼,C++項(xiàng)目源碼——球球大作戰(zhàn)的知識(shí),也有很多人為大家解答關(guān)于pos機(jī)網(wǎng)站模板源碼的問(wèn)題,今天pos機(jī)之家(www.tjfsxbj.com)為大家整理了關(guān)于這方面的知識(shí),讓我們一起來(lái)看下吧!

本文目錄一覽:

1、pos機(jī)網(wǎng)站模板源碼

pos機(jī)網(wǎng)站模板源碼

C/C++項(xiàng)目源碼——球球大作戰(zhàn)

這是一個(gè)球球大作戰(zhàn)的小程序,能夠運(yùn)行,需要下載一個(gè)easyx庫(kù)

初始產(chǎn)生一個(gè)小球,可以慢慢吃零食長(zhǎng)大

游戲沒(méi)有寫(xiě)完整,不能吃別的玩家(單機(jī)初始化產(chǎn)生的玩家)

有興趣可以自己嘗試寫(xiě)完。

歡迎大家交流

/*

開(kāi)發(fā)環(huán)境:vs2013+easyx

課程內(nèi)容:球球大作戰(zhàn)

*/

#include<stdio.h>

#include<math.h>

#include<graphics.h> //包含easyx圖形庫(kù)頭文件,如果沒(méi)有安裝,是包含不了的

#include<mmsystem.h>//多媒體設(shè)備接口頭文件

#pragma comment(lib,"winmm.lib")

#define WIN_width="360px",height="auto" />

#define WIN_HEIGHT 640

#define MAP_width="360px",height="auto" />

#define MAP_HEIGHT (WIN_HEIGHT*3)

#define FOOD_NUM 1000

#define AI_NUM 200

//地圖是一張圖 int temp;

IMAGE map(MAP_width="360px",height="auto" />

//食物,玩家,ai有什么屬性

struct Ball

{

int x;

int y;

int r;

DWORD color;//顏色

bool flag;//是否存在

};

struct Ball food[FOOD_NUM];

struct Ball player;

struct Ball ai[AI_NUM];

POINT g_CameraPos;//定義攝像機(jī)位置

void ChaseAlgortihm(struct Ball *chase, struct Ball run);

//求兩個(gè)球之間的距離

double DisTance(struct Ball b1, struct Ball b2)

{

return sqrt((double)(b1.x - b2.x)*(b1.x - b2.x) + (b1.y - b2.y)*(b1.y - b2.y));

}

void updatePos()

{

g_CameraPos.x = player.x - WIN_width="360px",height="auto" />

g_CameraPos.y = player.y - WIN_HEIGHT / 2;

//防止越界

if (g_CameraPos.x < 0) g_CameraPos.x = 0;

if (g_CameraPos.y < 0) g_CameraPos.y = 0;

if (g_CameraPos.x> MAP_width="360px",height="auto" />

if (g_CameraPos.y> MAP_HEIGHT - WIN_HEIGHT)g_CameraPos.y = MAP_HEIGHT - WIN_HEIGHT;

}

//初始化數(shù)據(jù)

void GameInit()

{

//設(shè)置隨機(jī)數(shù)種子

srand(GetTickCount());

//初始化食物

for (int i = 0; i < FOOD_NUM; i++)

{

//rand() 隨機(jī)生成一個(gè)整數(shù)

food[i].x = rand() % MAP_width="360px",height="auto" />

food[i].y = rand() % MAP_HEIGHT;

food[i].r = rand()%5+1;

food[i].flag = true;

food[i].color = RGB(rand() % 256, rand() % 256, rand() % 256);

}

//初始化玩家

player.x = rand() % MAP_width="360px",height="auto" />

player.y = rand() % MAP_HEIGHT;

player.flag = true;

player.color = RGB(rand() % 256, rand() % 256, rand() % 256);

player.r = rand() % 10 + 10;

//初始化ai

for (int i = 0; i < AI_NUM; i++)

{

ai[i].x = rand() % MAP_width="360px",height="auto" />

ai[i].y = rand() % MAP_HEIGHT;

ai[i].flag = true;

ai[i].r = rand() % 10 + 15;

ai[i].color = RGB(rand() % 256, rand() % 256, rand() % 256);

}

}

void GameDraw()

{

//播放背景音樂(lè) repeat重復(fù)播放 alias 取別名

mciSendString("open ./BallBGM.mp3 alias BGM", 0, 0, 0);

mciSendString("play BGM repeat", 0, 0, 0);

//設(shè)置工作區(qū)

SetWorkingImage(&map);

setbkcolor(WHITE);//設(shè)置背景顏色

cleardevice();//初始化窗口

//繪制食物

for (int i = 0; i < FOOD_NUM; i++)

{

if (food[i].flag)

{

setfillcolor(food[i].color);

fillcircle(food[i].x, food[i].y, food[i].r);

}

}

//繪制ai

for (int i = 0; i < AI_NUM; i++)

{

if (ai[i].flag)

{

setfillcolor(ai[i].color);

solidcircle(ai[i].x, ai[i].y, ai[i].r);

}

}

//繪制玩家

setfillcolor(player.color);

solidcircle(player.x, player.y, player.r);

SetWorkingImage();

updatePos();//更新攝像機(jī)位置

//把自定義的圖片繪制到窗口上

//putimage(0, 0, &map); 這樣貼圖不合適

//void putimage(int dstX, int dstY, int dstwidth="360px",height="auto" />

putimage(0, 0, WIN_width="360px",height="auto" />

}

//頑石老師移動(dòng)起來(lái)了,飄起來(lái)了

void PlayerMove(int speed)

{

//獲取鍵盤(pán)輸入 _getch();

if (GetAsyncKeyState(VK_UP))

{

player.y -= speed;

}

if (GetAsyncKeyState(VK_DOWN))

{

player.y += speed;

}

if (GetAsyncKeyState(VK_LEFT))

{

player.x -= speed;

}

if (GetAsyncKeyState(VK_RIGHT))

{

player.x += speed;

}

//作弊測(cè)試

if (GetAsyncKeyState(VK_SPACE))

{

player.r ++;

}

if (GetAsyncKeyState('A'))

{

player.r --;

}

}

//吃零食

void EatFood()

{

for (int i = 0; i < FOOD_NUM; i++)

{

if (food[i].flag && DisTance(player, food[i]) < player.r)

{

//如果能吃

food[i].flag = false;

player.r += food[i].r/4;

}

}

}

//AI移動(dòng)算法,追逐比自己半徑小的球

void AiMove()

{

//找到每一個(gè)人工智障

for (int i = 0; i < AI_NUM; i++)

{

//設(shè)置搜索范圍

int min_DISTANCE = MAP_width="360px",height="auto" />

int index=-1;

if (ai[i].flag)

{

//每一個(gè)都和后面的比較一下

for (int k = i + 1; k < AI_NUM; k++)

{

if (ai[i].r>ai[k].r &&ai[k].flag && DisTance(ai[i], ai[k]) < min_DISTANCE)

{

min_DISTANCE = DisTance(ai[i], ai[k]);

index = k;

}

}

}

//去追吧

if (index != -1)

{

ChaseAlgortihm(&ai[i], ai[index]);

}

else

{

ChaseAlgortihm(&ai[i], food[rand()%FOOD_NUM]);

}

}

}

//玩家吃AI,AI吃玩家

void EatAI()

{

//1,首先遍歷ai數(shù)組,然后判斷能否被吃

}

//Ai吃食物,AI吃ai

void AiEatFood()

{

}

int main()

{

//1,創(chuàng)建一個(gè)圖形窗口

initgraph(WIN_width="360px",height="auto" />

GameInit();

//游戲,要不斷地去處理,所以說(shuō)要循環(huán)

while (1)

{

GameDraw();

PlayerMove(5);

EatFood();

AiMove();

}

getchar();//防止程序閃退

return 0;

}

//追逐算法

void ChaseAlgortihm(struct Ball *chase, struct Ball run)

{

//已知逃跑者的坐標(biāo),那么,chase向run移動(dòng)是不是就可以了?

if (rand() % 2 == 0)

{

if (chase->x < run.x)

{

chase->x += 2;

}

else

{

chase->x -= 2;

}

}

else

{

if (chase->y < run.y)

{

chase->y += 2;

}

else

{

chase->y -= 2;

}

}

}

有興趣學(xué)習(xí)C/C++的小伙伴可以加群學(xué)習(xí):1083020561

以上就是關(guān)于pos機(jī)網(wǎng)站模板源碼,C++項(xiàng)目源碼——球球大作戰(zhàn)的知識(shí),后面我們會(huì)繼續(xù)為大家整理關(guān)于pos機(jī)網(wǎng)站模板源碼的知識(shí),希望能夠幫助到大家!

轉(zhuǎn)發(fā)請(qǐng)帶上網(wǎng)址:http://www.tjfsxbj.com/news/38863.html

你可能會(huì)喜歡:

版權(quán)聲明:本文內(nèi)容由互聯(lián)網(wǎng)用戶自發(fā)貢獻(xiàn),該文觀點(diǎn)僅代表作者本人。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如發(fā)現(xiàn)本站有涉嫌抄襲侵權(quán)/違法違規(guī)的內(nèi)容, 請(qǐng)發(fā)送郵件至 babsan@163.com 舉報(bào),一經(jīng)查實(shí),本站將立刻刪除。