c++ 小游戏 NO6 跑酷游戏

这是一篇关于使用C++编程语言制作跑酷小游戏的教程,内容包括游戏设计与实现的详细过程,期待164个赞来解锁完整教学。
摘要由CSDN通过智能技术生成

最后一章有惊喜: 

int ti(float a) {
	return ((int)(a*10+5))/10;
}
void Setpos(float x,float y) {
	COORD pos;
	pos.X=ti(y*4)/2;
	pos.Y=ti(x);
	SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
}
void Color(int a) {
	if(a==0) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
	if(a==1) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN|FOREGROUND_BLUE);
	if(a==2) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN);
	if(a==3) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_BLUE);
	if(a==4) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED);
	if(a==5) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN);
	if(a==6) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_BLUE);
	if(a==7) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
	if(a==8) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED);
	if(a==9) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_INTENSITY|BACKGROUND_GREEN|BACKGROUND_BLUE);
	if(a==10) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_INTENSITY|BACKGROUND_RED|BACKGROUND_BLUE);
	if(a==11) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED|FOREGROUND_BLUE);
	if(a==12) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED|FOREGROUND_GREEN);
	if(a==13) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY);
	if(a==14) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_GREEN|FOREGROUND_BLUE);
}
int Blomax,Ren,Exp,Expmax,Lv,Lvl,Ice,Drug,ar1,ar2,Tar1,Tar2,bl,br,Win,T,Tb,Sy,Up,Upt,Down,u1,u2,Kill,Killb,L,Ll[4],Li,D,Gd[10],Biao,Fire,Fir,Water,Thun,Wind,Magne,I[20][2],ib,Dis,Disb,Dis1,Disb1,Boss,Bblo,Bblomax,Bwhat1,Bwhat2,Bwhat3,Bgo1[10],Bgo2[10],Bgo3[10],Bbr,Bbl,Bl[4];
float X,Y,Vx,Vy,Ding,Blo,Hui,Bx1,By1,Bx2,By2,Bx3,By3,Bvx1,Bvy1,Bvx2,Bvy2,Bvx3,Bvy3,Bway[1001][2];
struct bullet {
	float x,y,vx,vy;
	int what;
	int a,t,How;
	int life;
	bool kill;
} B[100001];
void Map(int a,int b);
void Pan(int a,float x,float y,int b) {
	float Nox[4],Noy[4];
	Nox[0]=X,Noy[0]=Y;
	if(Down==1&&X==22) Nox[1]=X+1,Noy[1]=Y-0.5,Nox[2]=X-1,Noy[2]=Y-0.5;
	else if(Down==2) Nox[1]=X+1,Noy[1]=Y-0.5,Nox[2]=-10,Noy[2]=-10;
	else if(Down==1||X<18) Nox[1]=X-1,Noy[1]=Y-0.5,Nox[2]=-10,Noy[2]=-10;
	else Nox[1]=X+1,Noy[1]=Y-0.5,Nox[2]=X-1,Noy[2]=Y-0.5;
	for(int i=0; i<3; i++) {
		if(a==-1) {
			if(abs(x-Nox[i])+abs(y-Noy[i])<1.5) {
				if(B[b].what==-10)Exp+=2;
				if(B[b].what==-11)Exp+=1;
				B[b].life=0;
				if(B[b].life==0&&b==bl) bl++;
				Map(3,b);
				break;
			}
		}
		if(a==-2) {
			if(abs(x-Nox[i])+abs(y-Noy[i])<2.5) {
				if(B[b].what==-2)Exp+=20,Biao+=20;
				if(B[b].what==-3)Fire=1000000,Ice=10000000,Fir=10000000;
				if(B[b].what==-4)Water=10000000;
				if(B[b].what==-5) {
					Wind=10;
					Ding=10000000;
					Ice=10000000;
					if(Y<Ding-1)Vy=5;
					else Vy=0;
					if(Up>=1) Vx=-5;
					if(Down==2) Vx=5;
				}
				if(B[b].what==-6) {
					Thun=200;
					system("color 1F");
					Sleep(20);
					system("color 6F");
					Sleep(10);
					system("color 0F");
				}
				if(B[b].what==-7)Magne=300;
				if(B[b].what==-8)Ice=0,Drug=0,Blo=fmin((float)Blomax,Blo+20);
				if(B[b].what==-9)Exp=fmin((float)Expmax,Exp+20);
				B[b].life=0;
				if(B[b].life==0&&b==bl) bl++;
				Map(3,b);
				break;
			}
		}
	}
	if(Wind==0&&Thun==0&&(B[b].kill!=0||Killb>=15||Ren==1&&Killb>0)) return;
	for(int i=0; i<3; i++) {
		if((Wind>=1||Thun>=1)&&abs(x-Nox[i])+abs(y-Noy[i])<2.5) {
			if(B[b].what<98)Exp+=2;
			B[b].life=0;
			Map(3,b);
			break;
		}
		if(a==1) {
			if(abs(x-Nox[i])<0.5&&abs(y-Noy[i])<1) {
				if(B[b].what>=99)Blo-=10;
				if(B[b].what==14)Blo-=15,Ice=100,B[b].life=0;
				else if(B[b].what==15)Blo-=20,Ice=0,B[b].life=0;
				else if(B[b].what==17)Blo-=5,Drug=100,B[b].life=0;
				else if(B[b].what>=13&&B[b].what<=17)Blo-=10,B[b].life=0;
				else Blo-=15;
				B[b].kill=1,Killb=20;
				Kill=1;
				Map(3,b);
				break;
			}
		}
		if(a==2||a==6||a==8||a==9||a==10||a==11||a==12) {
			if(abs(x-Nox[i])+abs(y-Noy[i])<1.5) {
				if(a==2)Blo-=20;
				else if(a==8)Blo-=10;
				else Blo-=15;
				B[b].kill=1,Killb=20;
				Kill=1;
				if(a!=2) {
					B[b].life=0;
					if(B[b].life==0&&b==bl) bl++;
					Map(3,b);
					break;
				}
			}
		}
		if(a==4) {
			if((Wind>=1||Thun>=1)&&abs(x-Nox[i])<1.5&&Noy[i]-y<=0&&Noy[i]-y>=-8) {
				if(B[b].what<98)Exp+=2;
				B[b].life=0;
				Map(3,b);
				break;
			}
			if(abs(x-Nox[i])<1&&Noy[i]-y<=0&&Noy[i]-y>=-8) {
				Blo-=25,B[b].kill=1,Killb=20;
				Kill=1;
				Vy=-1;
				Y-=0.5;
				break;
			}
		}
	}
}
void Map(int a,int b) {
	Color(0);
	if(a==-1) {
		if(Boss==1||Boss==6) {
			if(Bwhat1==5) {
				if(ti(Bx1)==20)Setpos(Bx1,By1),cout<<"==";
				else Setpos(Bx1,By1),cout<<"  ";
			} else {
				Setpos(Bx1-1,By1-0.5),cout<<"    ";
				Setpos(Bx1,By1-1),cout<<"      ";
				Setpos(Bx1+1,By1-0.5),cout<<"    ";
				if(abs(ti(Bx1)-20)<=1)Setpos(20,By1-1),cout<<"======";
			}
		}
		if(Boss==2||Boss==6) {
			Setpos(Bx2-1,By2-1);
			cout<<"    ";
			Setpos(Bx2,By2-1);
			cout<<"      ";
			Setpos(Bx2+1,By2-1),cout<<"      ";
			Color(0);
			if(abs(ti(Bx2)-20)<=1)Setpos(20,By2-1),cout<<"======";
		}
		if(Boss==3||Boss==6) {
			Setpos(Bx3-1,By3-0.5);
			cout<<"     ";
			Setpos(Bx3,By3);
			cout<<"  ";
			Setpos(Bx3+1,By3-1),cout<<"      ";
			Color(0);
			if(abs(ti(Bx3)-20)<=1)Setpos(20,By3-1),cout<<"=======";
		}
		if(X<0)return;
		if(X>=17&&X<=19) {
			Setpos(X-1,Y);
			cout<<"  ";
			Setpos(X,Y-1);
			cout<<"   ";
			Setpos(X+1,Y-1),cout<<"   ";
		} else if(X<=23&&X>=21) {
			Setpos(X+1,Y);
			cout<<"  ";
			Setpos(X,Y-1);
			cout<<"   ";
			Setpos(X-1,Y-1),cout<<"    ";
		} else if(X>23) {
			Setpos(X,Y-1);
			cout<<"    ";
			Setpos(X-1,Y-0.5),cout<<"   ";
		} else if(X<17&&Upt!=0) {
			Setpos(X,Y-1);
			cout<<"    ";
			Setpos(X+1,Y-1.5),cout<<"    ";
		} else if(X<17) {
			Setpos(X,Y-1);
			cout<<"    ";
			Setpos(X+1,Y-0.5),cout<<"   ";
		}
		if(Thun>0) {
			Setpos(X-2,Y-1),cout<<"    ";
			Setpos(X+2,Y-1),cout<<"    ";
			Setpos(X,Y+2),cout<<"  ";
			Setpos(X,Y-2.5),cout<<"  ";
			Setpos(X-1,Y+1),cout<<"  ";
			Setpos(X+1,Y+1),cout<<"  ";
			Setpos(X-1,Y-2),cout<<"  ";
			Setpos(X+1,Y-2),cout<<"  ";
			Setpos(20,Y-2.5),cout<<"============";
		}
		if(Wind!=0) {
			Setpos(X+1,Y-5);
			cout<<"        ";
			Setpos(X,Y-5);
			cout<<"        ";
			Setpos(X-1,Y-5);
			cout<<"        ";
			Setpos(20,Y-5),cout<<"========";
		}
		if(Water!=0) {
			Setpos(X,Y-4);
			cout<<"       ";
			Setpos(X+2,Y-3.5);
			cout<<"     ";
			Setpos(X-2,Y-3.5);
			cout<<"     ";
			Setpos(X+1,Y-3.5);
			cout<<"     ";
			Setpos(X-1,Y-3.5);
			cout<<"     ";
			Setpos(20,Y-5),cout<<"========";
		}
		if(Fire!=0) {
			Setpos(X,Y+1),cout<<"  ";
			Setpos(X+1,Y),cout<<"  ";
			Setpos(X-1,Y-1),cout<<"  ";
			Setpos(20,Y-1);
			cout<<"======";
		}
	}
	if(a==0) {
		if(Boss==1||Boss==6) {
			if(Bwhat1==5)Color(5),Setpos(Bx1,By1),cout<<"█",Color(0);
			else if(Bwhat1==4&&Bgo1[1]>6&&Bgo1[1]<11)Color(4),Setpos(Bgo1[5]-1,Bgo1[6]),cout<<"︻",Setpos(Bgo1[5],Bgo1[6]-1),cout<<"【",Setpos(Bgo1[5],Bgo1[6]+1),cout<<"】",Setpos(Bgo1[5]+1,Bgo1[6]),cout<<"︼",Color(0);
			else {
				Setpos(Bx1-1,By1-0.5),Color(0),cout<<"●●";
				Setpos(Bx1,By1-1);
				if(Bwhat1==2&&Bgo1[1]<=5)Color(1);
				else if(Bwhat1==3&&Bgo1[1]<=5)Color(5);
				else if(Bwhat1==6&&Bgo1[1]<=5)Color(8);
				else Color(4);
				if(Bwhat1==4) Setpos(Bx1,By1-0.5),cout<<"██(";
				else cout<<")██(";
				Setpos(Bx1+1,By1-0.5),cout<<"……";
				Color(0);
			}
		}
		if(Boss==2||Boss==6) {
			Setpos(Bx2-1,By2-1);
			Color(0),cout<<"\\ ";
			Color(0);
			cout<<"●";
			Setpos(Bx2,By2-1);
			Color(3);
			cout<<"◥";
			Color(5),cout<<"JJJ";
			Color(0),cout<<">";
			Color(3);
			Setpos(Bx2+1,By2-1),cout<<"◢█◣";
			Color(0);
		}
		if(Boss==3||Boss==6) {
			Setpos(Bx3-1,By3-0.5);
			if(Bwhat3==3||Bwhat3==9) Color(1);
			else if(Bwhat3==4||Bwhat3==10) Color(4);
			else if(Bwhat3==5||Bwhat3==11) Color(5);
			if(Bwhat3==11)cout<<' ';
			else if(Bwhat3==6) Color(3);
			else Color(2);
			cout<<"●-";
			Setpos(Bx3,By3);
			if(Bwhat3==11)cout<<"/";
			else cout<<"┃";
			Color(0);
			Setpos(Bx3+1,By3-1),cout<<"●●●";
		}
		if(X<0)return;
		if(Ren==2) Color(12);
		if(Ren==3) Color(1);
		if(Ren==4) Color(3);
		if(Ren==5) Color(4);
		if(Ren==6) Color(2);
		if(Drug!=0&&T%5!=0) Color(11);
		if(Drug!=0&&T%5==0) Color(11);
		if(Ice!=0) Color(6);
		if(b==1) Color(8);
		if(Li!=0) Color(5);
		if(Ren==1&&Killb>0&&T%4<2) Color(13);
		if(Wind>0&&T%4<=1) Color(1);
		if(Wind>0&&T%4>=2) Color(0);
		if(Thun>0&&T%4<=1) Color(1);
		if(Thun>0&&T%4>=2) Color(6);
		if(X>=17&&X<=19) {
			Setpos(X-1,Y);
			cout<<"●";
			Setpos(X,Y-1);
			cout<<"━/";
			if(T%10<3) Setpos(X+1,Y-1),cout<<"┛╲";
			else if(T%10<6) Setpos(X+1,Y-1),cout<<"┦ ";
			else Setpos(X+1,Y-1),cout<<"╯>";
			if(Wind>0&&T%3==0) Setpos(X+1,Y-1),cout<<"┛╲";
			else if(Wind>0&&T%3==1) Setpos(X+1,Y-1),cout<<"┦ ";
			else if(Wind>0&&T%3==2)Setpos(X+1,Y-1),cout<<"╯>";
		} else if(X<=23&&X>=21) {
			Setpos(X+1,Y);
			cout<<"●";
			Setpos(X,Y-1);
			cout<<"━\\";
			if(T%10<3) Setpos(X-1,Y-1),cout<<"┓╱";
			else if(T%10<6) Setpos(X-1,Y-1),cout<<"┪ ";
			else Setpos(X-1,Y-1),cout<<"╮>";
			if(Wind>0&&T%3==0) Setpos(X-1,Y-1),cout<<"┓╱";
			else if(Wind>0&&T%3==1) Setpos(X-1,Y-1),cout<<"┪ ";
			else if(Wind>0&&T%3==2)Setpos(X-1,Y-1),cout<<"╮>";
		} else if(X>23) {
			Setpos(X,Y-1);
			cout<<"━ ●";
			Setpos(X-1,Y-0.5),cout<<"│>";
		} else if(X<17&&Upt!=0) {
			Setpos(X,Y-1);
			cout<<"━ ●";
			Setpos(X+1,Y-1.5),cout<<"╱ >";
		} else if(X<17) {
			Setpos(X,Y-1);
			cout<<"━ ●";
			Setpos(X+1,Y-0.5),cout<<"│>";
		}
		if(Thun>0) {
			Setpos(X-2,Y-1),cout<<"▄▄";
			Setpos(X+2,Y-1),cout<<"▄▄";
			Setpos(X,Y+2),cout<<"▌";
			Setpos(X,Y-2.5),cout<<"▌";
			Setpos(X-1,Y+1),cout<<"█";
			Setpos(X+1,Y+1),cout<<"█";
			Setpos(X-1,Y-2),cout<<"█";
			Setpos(X+1,Y-2),cout<<"█";
		}
		if(Magne>0&&T%7<2)Setpos(X,Y),Color(5),cout<<"★";
		if(Wind>1) {
			if(T%6<2)Color(1);
			else Color(0);
			if(T%8<=1) {
				Setpos(X+1,Y-5);
				cout<<"----  --";
				Setpos(X,Y-5);
				cout<<"-  --- -";
				Setpos(X-1,Y-5);
				cout<<"--- - --";
			} else if(T%8<=3) {
				Setpos(X+1,Y-5);
				cout<<"------  ";
				Setpos(X,Y-5);
				cout<<" --  ---";
				Setpos(X-1,Y-5);
				cout<<
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值