IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 游戏开发 -> c++ 小游戏 NO 8 地图游戏(有2个逆天bug,难得修护) -> 正文阅读

[游戏开发]c++ 小游戏 NO 8 地图游戏(有2个逆天bug,难得修护)

下一张有惊喜:

string grass[1] = { "                                                                                                                           " };
string soil[30];
string bullet[1] = { "▂" };
int SoilHieght[9] = { 2,2,2,10,20,7,7,7,7 };
Sprite Grass[9], Soil[9], Bullet[10005], bhp, rhp;
bool flag[10005], gameover;
int blueHP, redHP;
Sprite letin(Sprite a)
{
	a.x = max(a.x, 0); a.x = min(a.x, 27);
	a.y = max(a.y, 0); a.y = min(a.y, 117);
	return a;
}
int NowBackgroundColor(Sprite a)
{
	for (int i = 0; i <= 8; i++)
	{
		if (CheckCollision(Soil[i], a)) return 96;
		if (a.height == 1 && CheckCollision(Grass[i], a)) return 32;
	}
	return 224;
}
int jemian()
{
	HindCursor();
	system("mode con cols=120 lines=30");

	for (int i = 0; i < 30; i++) soil[i] = grass[0];
	Grass[0] = NewSprite(grass, 12, 1, 32, 6, 52);
	Grass[1] = NewSprite(grass, 12, 1, 32, 11, 18);
	Grass[2] = NewSprite(grass, 12, 1, 32, 11, 91);
	Grass[3] = NewSprite(grass, 15, 1, 32, 18, 50);
	Grass[4] = NewSprite(grass, 53, 1, 32, 9, 34);
	Grass[5] = NewSprite(grass, 32, 1, 32, 14, 14);
	Grass[6] = NewSprite(grass, 38, 1, 32, 14, 70);
	Grass[7] = NewSprite(grass, 34, 1, 32, 22, 14);
	Grass[8] = NewSprite(grass, 41, 1, 32, 22, 67);
	color(224);
	for (int i = 0; i <= 30; i++)
		for (int j = 0; j < 119; j++) printf(" ");
	for (int i = 0; i <= 8; i++)
	{
		Soil[i] = NewSprite(soil, Grass[i].width, SoilHieght[i], 96, Grass[i].x + 1, Grass[i].y);
		Soil[i].Draw();
	}
	for (int i = 0; i <= 8; i++) Grass[i].Draw();

	string player[2] = { "●", "■" };
	string HP[1] = { "■■■■■■■■■■" };
	Sprite red = NewSprite(player, 2, 2, 4 | 224, 4, 54);
	Sprite blue = NewSprite(player, 2, 2, 1 | 224, 4, 57);
	bhp = NewSprite(HP, 20, 1, 1 | 224, 0, 3);
	rhp = NewSprite(HP, 20, 1, 4 | 224, 0, 97);

	int bluejump = 0, redjump = 0;
	bool bluejumping = false, redjumping = false;
	int tbluejump = 0, tredjump = 0;
	int bulleti = 0, tbluebullet = 0, tredbullet = 0;
	int bhps = 5, rhps = 5;
	blueHP = 50; redHP = 50; gameover = false;
	memset(flag, 0, sizeof(flag));

	red.Draw(); blue.Draw();
	bhp.Draw(); rhp.Draw();
	color(0 | 224);
	gotoxy(0, 1); printf("%d", bhps);
	gotoxy(0, 118); printf("%d", rhps);
	while (1)
	{
		bool bluemove = false;
		int bnx = blue.x, bny = blue.y, rnx = red.x, rny = red.y;
		Sprite b = NewSprite(player, 2, 2, 1 | 224, bnx, bny);
		Sprite r = NewSprite(player, 2, 2, 4 | 224, rnx, rny);

		color(224);
		for (int i = 0; i < 3; i++)
		{
			if (CheckCollision(blue, Soil[0]) || CheckCollision(blue, Grass[0]) || 
				CheckCollision(red, Soil[0]) || CheckCollision(red, Grass[0]))
			{
				gotoxy(6 + i, 51); printf(" ");
				gotoxy(6 + i, 64); printf(" ");
			}
			if (CheckCollision(blue, Soil[1]) || CheckCollision(blue, Grass[1]) || 
				CheckCollision(red, Soil[1]) || CheckCollision(red, Grass[1]))
			{
				gotoxy(11 + i, 17); printf(" ");
				gotoxy(11 + i, 30); printf(" ");
			}
			if (CheckCollision(blue, Soil[2]) || CheckCollision(blue, Grass[2]) || 
				CheckCollision(red, Soil[2]) || CheckCollision(red, Grass[2]))
			{
				gotoxy(11 + i, 90); printf(" ");
				gotoxy(11 + i, 103); printf(" ");
			}
		}
		for (int i = 0; i < 5; i++)
			if (CheckCollision(blue, Soil[4]) || CheckCollision(blue, Grass[4]) || 
				CheckCollision(red, Soil[4]) || CheckCollision(red, Grass[4]))
			{
				gotoxy(9 + i, 33); printf(" ");
				gotoxy(9 + i, 87); printf(" ");
			}
		/*
		for (int i = 0; i < 7; i++)
		{
			if (CheckCollision(blue, Soil[5]) || CheckCollision(blue, Grass[5]))
				gotoxy(14 + i, 12); printf(" ");
			if (CheckCollision(blue, Soil[6]) || CheckCollision(blue, Grass[6]))
				gotoxy(14 + i, 108); printf(" ");
			if (CheckCollision(blue, Soil[7]) || CheckCollision(blue, Grass[7]))
				gotoxy(22 + i, 12); printf(" ");
			if (CheckCollision(blue, Soil[8]) || CheckCollision(blue, Soil[8]))
				gotoxy(22 + i, 108); printf(" ");
		}*/
		blue.Draw(); red.Draw();
		if (KEY_DOWN(VK_LEFT))
		{
			int COLOR = NowBackgroundColor(b);
			blue.direction = -1;
			color(COLOR);
			blue.Clean();
			blue.y--;
			blue.Color = 1 | COLOR;
			blue = letin(blue);
			blue.Draw(); red.Draw();
		}
		if (KEY_DOWN(VK_RIGHT))
		{
			int COLOR = NowBackgroundColor(b);
			blue.direction = 1;
			blue.Color = 1 | COLOR;
			color(COLOR);
			blue.Clean();
			blue.y++;
			blue = letin(blue);
			blue.Draw(); red.Draw();
		}
		if (KEY_DOWN(VK_UP))
			if (bluejumping == false)
			{
				tbluejump = -1;
				bluejump = 0;
				bluejumping = true;
			}
		if (bluejumping)
		{
			int COLOR = NowBackgroundColor(blue);
			blue.Color = 1 | COLOR;
			color(COLOR);
			blue.Clean();
			if (tbluejump != -2)
			{
				blue.x += tbluejump;
				bluejump += tbluejump;
			}
			for (int i = 0; i <= 8; i++)
				if (blue.x == Grass[i].x - 2 && blue.y >= Grass[i].y - 1 && blue.y + blue.width <= Grass[i].y + Grass[i].width + 1)
				{
					tbluejump = 0;
					bluejumping = false;
					break;
				}
			blue = letin(blue);
			blue.Draw(); red.Draw();
			if (bluejump == -5) tbluejump = 1;
		}
		else
		{
			int j;
			for (j = 0; j <= 8; j++)
				if (blue.x == Grass[j].x - 2 && blue.y >= Grass[j].y - 1 && blue.y + blue.width <= Grass[j].y + Grass[j].width + 1)
					break;
			if (j == 9)
			{
				int COLOR = NowBackgroundColor(b);
				color(COLOR);
				blue.Clean();
				blue.x++;
				blue.Color = 1 | COLOR;
				blue.Draw(); red.Draw();
			}
		}
		if (KEY_DOWN(0x58))
		{
			if (!tbluebullet)
			{
				Bullet[++bulleti] = NewSprite(bullet, 2, 1, 0 | 224, blue.x, blue.y + blue.direction * 2);
				Bullet[bulleti].direction = blue.direction;
				Bullet[bulleti].Draw();
				tbluebullet = 1;
			}
		}
		if (blue.x >= 26)
		{
			if (blueHP % 10 == 0) blueHP -= 10;
			else blueHP -= blueHP % 10;
			bhp.width = 0;
		}
		if (KEY_DOWN(0x41))
		{
			int COLOR = NowBackgroundColor(r);
			color(COLOR);
			red.Clean();
			red.y--; red.direction = -1;
			red.Color = 4 | COLOR;
			red = letin(red);
			blue.Draw(); red.Draw();
		}
		if (KEY_DOWN(0x44))
		{
			int COLOR = NowBackgroundColor(r);
			color(COLOR);
			red.Clean();
			red.y++; red.direction = 1;
			red.Color = 4 | COLOR;
			red = letin(red);
			blue.Draw(); red.Draw();
		}
		if (KEY_DOWN(0x57))
			if (redjumping == false)
			{
				tredjump = -1;
				redjump = 0;
				redjumping = true;
			}
		if (redjumping)
		{
			int COLOR = NowBackgroundColor(red);
			red.Color = 4 | COLOR;
			color(COLOR);
			red.Clean();
			if (tredjump != -2)
			{
				red.x += tredjump;
				redjump += tredjump;
			}
			for (int i = 0; i <= 8; i++)
				if (red.x == Grass[i].x - 2 && red.y >= Grass[i].y - 1 && red.y + red.width <= Grass[i].y + Grass[i].width + 1)
				{
					tredjump = 0;
					redjumping = false;
					break;
				}
			red = letin(red);
			blue.Draw(); red.Draw();
			if (redjump == -5) tredjump = 1;
		}
		else
		{
			int j;
			for (j = 0; j <= 8; j++)
				if (red.x == Grass[j].x - 2 && red.y >= Grass[j].y - 1 && red.y + red.width <= Grass[j].y + Grass[j].width + 1)
					break;
			if (j == 9)
			{
				int COLOR = NowBackgroundColor(r);
				color(COLOR);
				red.Clean();
				red.x++;
				red.Color = 4 | COLOR;
				blue.Draw(); red.Draw();
			}
		}
		if (KEY_DOWN(0x59))
		{
			if (!tredbullet)
			{
				Bullet[++bulleti] = NewSprite(bullet, 2, 1, 0 | 224, red.x, red.y + red.direction * 2);
				Bullet[bulleti].direction = red.direction;
				Bullet[bulleti].Draw();
				tredbullet = 1;
			}
		}
		if (red.x >= 28)
		{
			if (redHP % 10 == 0) redHP -= 10;
			else redHP -= redHP % 10;
			rhp.width = 0;
		}

		if (tbluebullet)
		{
			if (tbluebullet == 15) tbluebullet = 0;
			else tbluebullet++;
		}
		if (tredbullet)
		{
			if (tredbullet == 15) tredbullet = 0;
			else tredbullet++;
		}
		for (int i = 0; i <= 8; i++) Grass[i].Draw();
		for (int i = 1; i <= bulleti; i++)
		{	
			if (flag[i]) continue;
			int COLOR = NowBackgroundColor(Bullet[i]);
			color(0 | COLOR);
			Bullet[i].Clean();
			Bullet[i].y += Bullet[i].direction * 2;
			COLOR = NowBackgroundColor(Bullet[i]);
			Bullet[i].Color = 0 | COLOR;
			Bullet[i].Draw();
			if (Bullet[i].y <= 1 || Bullet[i].y >= 117 || 
				CheckCollision(Bullet[i], blue) || CheckCollision(Bullet[i], red))
			{
				Bullet[i].Clean();
				if (CheckCollision(Bullet[i], blue))
				{
					blueHP--;
					color(224);
					bhp.Clean();
					bhp.width -= 2;
					bhp.Draw();
					
					int COLOR = NowBackgroundColor(blue);
					blue.Color = 1 | COLOR;
					color(COLOR);
					blue.Clean();
					blue.y += Bullet[i].direction * 3;
					blue = letin(blue);
					blue.Draw(); red.Draw();
				}
				if (CheckCollision(Bullet[i], red))
				{
					redHP--;
					color(224);
					rhp.Clean();
					rhp.width -= 2;
					rhp.y += 2;
					rhp.Draw();
					
					int COLOR = NowBackgroundColor(red);
					red.Color = 4 | COLOR;
					color(COLOR);
					red.Clean();
					red.y += Bullet[i].direction * 3;
					red = letin(red);
					blue.Draw(); red.Draw();
				}
				Bullet[i].x = 0; Bullet[i].y = 0;
				flag[i] = true;
				continue;
			}
		}
		if (blueHP % 10 == 0 && bhp.width <= 0)
		{
			bhps--;
			bhp.width = 20;
			gotoxy(0, 1); color(0 | 224);  printf("%d", bhps);
			bhp.Draw();
			int COLOR = NowBackgroundColor(blue);
			blue.Color = 1 | 224;
			color(COLOR);
			blue.Clean(); blue.x = 4; blue.y = 57;
			blue.Draw();
		}
		if (redHP % 10 == 0 && rhp.width <= 0)
		{
			rhps--;
			rhp.width = 20; rhp.y = 97;
			gotoxy(0, 118); color(0 | 224);  printf("%d", rhps);
			rhp.Draw();
			int COLOR = NowBackgroundColor(red);
			red.Color = 4 | 224;
			color(COLOR);
			red.Clean(); red.x = 4; red.y = 54;
			red.Draw();
		}
		if (redHP <= 0)
		{
			gotoxy(12, 53);
			color(1 | 96);
			printf("玩家1获胜!");
			gameover = true;
			break;
		}
		if (blueHP <= 0)
		{
			gotoxy(12, 53);
			color(4 | 96);
			printf("玩家2获胜!");
			gameover = true;
			break;
		}
		if (gameover) break;
		Sleep(25);
	}
	Button Exit = NewButton(14, 55, 0 | 96, "退出");
	while (1)
	{
		if (Preserve(Exit)) exit(0);
		Sleep(25);
	}
	return 0;
}

老规矩,1024赞不出教程。

?

?

  游戏开发 最新文章
6、英飞凌-AURIX-TC3XX: PWM实验之使用 GT
泛型自动装箱
CubeMax添加Rtthread操作系统 组件STM32F10
python多线程编程:如何优雅地关闭线程
数据类型隐式转换导致的阻塞
WebAPi实现多文件上传,并附带参数
from origin ‘null‘ has been blocked by
UE4 蓝图调用C++函数(附带项目工程)
Unity学习笔记(一)结构体的简单理解与应用
【Memory As a Programming Concept in C a
上一篇文章      下一篇文章      查看所有文章
加:2021-07-27 16:34:25  更:2021-07-27 16:35:24 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年4日历 -2024/4/30 17:35:33-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码