C++三体星战小游戏

这篇具有很好参考价值的文章主要介绍了C++三体星战小游戏。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

物理小游戏,懒得 写注释。
游戏代码文章来源地址https://www.toymoban.com/news/detail-675580.html

#include<bits/stdc++.h>
#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
using namespace std;
int toint(double a){return ((int)(a*10+5))/10;}
int rand(int a){return rand()%a;}
void SlowDisplay(int x,char *p){while(1){if(*p!=0) printf("%c",*p++);else break;Sleep(x);}}
void Setpos(double x,double y){COORD pos;pos.X=toint(y*2),pos.Y=toint(x);SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);}
void Color(int a){
    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_RED|FOREGROUND_GREEN);
    if(a==-3) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED);

    if(a==0) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
    if(a==1) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_RED);
    if(a==2) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_INTENSITY|BACKGROUND_RED);
    if(a==3) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_INTENSITY|BACKGROUND_RED|BACKGROUND_GREEN);
    if(a==4) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_INTENSITY|BACKGROUND_RED|BACKGROUND_GREEN|BACKGROUND_BLUE);

    if(a==5) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_RED|BACKGROUND_BLUE);
    if(a==6) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_BLUE);
}   
struct node{int what;double x,y,vx,vy,r,m;bool life;int gun,master=-1;}Sun[1000001];
int b,T,m[41][41],n[41][41],m2[41][41],n2[41][41],dif[11],Speed=10,Ba,Hotguntime,Hotguntimemax=10,Blood,Score;
double Speedmax,Speedless,Speedmore=1,Balljump=-0.7,Fire=0.08;
void Push(int a,int b){
    if(Sun[a].master==b||Sun[b].master==a) return;
    if(Sun[a].life==0||Sun[b].life==0) return;
    if(Sun[a].what==3||Sun[b].what==3) return;
    if(Sun[a].what==4||Sun[b].what==4) return;
    double Ax=Sun[a].x-Sun[b].x,Ay=Sun[a].y-Sun[b].y,Dis=sqrt(Ax*Ax+Ay*Ay)*1.0,fDis=sqrt((Sun[a].vx-Sun[b].vx)*(Sun[a].vx-Sun[b].vx)+(Sun[a].vy-Sun[b].vy)*(Sun[a].vy-Sun[b].vy));
    if(Dis==0) return;if(abs(Ay)<=0.0001) Ay=0.0001;
    if(Sun[a].what==2||Sun[b].what==2) int c;
    else if(Dis<=Sun[a].r+Sun[b].r+fDis){
        double Vx=(Sun[a].vx+Sun[b].vx)/2.0,Vy=(Sun[a].vy+Sun[b].vy)/2.0,aX=(Sun[a].x+Sun[b].x+Sun[a].vx+Sun[b].vx)/2.0,aY=(Sun[a].y+Sun[b].y+Sun[a].vy+Sun[b].vy)/2.0;
        Sun[a].vx=Sun[b].vx=Vx,Sun[a].vy=Sun[b].vy=Vy;Sun[a].x=aX-(Ax/Dis)/2.0,Sun[b].x=aX+(Ax/Dis)/2.0;Sun[a].y=aY-(Ay/Dis)/2.0,Sun[b].y=aY+(Ay/Dis)/2.0;
        return;
    }
    double ac=Sun[a].m*Sun[b].m/(Dis*Dis)*1.0,afx=0,afy=0,d=abs(Ax/Ay*1.0);
    afy=sqrt(ac/(1+d*d))*1.0,afx=sqrt(ac/(1+d*d))*d*1.0;
    if(Ax>0) afx*=-1;if(Ay>0) afy*=-1;
#define A Sun[a].vx+=afx/Sun[a].m*Speedless,Sun[a].vx=max(-Speedmax,min(Speedmax,Sun[a].vx)),Sun[a].vy+=afy/Sun[a].m*Speedless,Sun[a].vy=max(-Speedmax,min(Speedmax,Sun[a].vy))
#define B Sun[b].vx-=afx/Sun[b].m*Speedless,Sun[b].vx=max(-Speedmax,min(Speedmax,Sun[b].vx)),Sun[b].vy-=afy/Sun[b].m*Speedless,Sun[b].vy=max(-Speedmax,min(Speedmax,Sun[b].vy))
    Speedmax=0.1,Speedless=0.01; 
    if(Sun[a].what==2&&Sun[b].what==2) Speedmax=3.0;
    if(Sun[a].what==0) {Speedless=0.008;Speedmax=1.0; A;}
    else if(Sun[a].what==1) {A; if(Sun[b].what==1) B;}
    else if(Sun[a].what==2) {Speedless=0.8;B;if(Sun[b].what==2) A;}
    else {A;B;}
}
int Painting[41][41]={{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0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0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,2,9,9,9,9,9,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,3,9,9,9,9,9,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,4,9,9,9,9,9,9,9,9,9,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},};
void Paint(int a);
void Move(int a){
    Blood=10000000;
    memset(m,0,sizeof(m));
    memset(m2,0,sizeof(m2));
    #define ix toint(Sun[i].x/1.0)
    #define iy toint(Sun[i].y/1.0)
    #define jx toint(Sun[j].x/1.0)
    #define jy toint(Sun[j].y/1.0)
    if(Sun[0].life==1){
    Sun[0].x+=Sun[0].vx/Speedmore;Sun[0].y+=Sun[0].vy/Speedmore;
    if(Sun[0].x>40) Sun[0].x=40,Sun[0].vx=0;if(Sun[0].x<0) Sun[0].x=0,Sun[0].vx=0;if(Sun[0].y>40) Sun[0].y=40,Sun[0].vy=0;if(Sun[0].y<0) Sun[0].y=0,Sun[0].vy=0;}

    for(int i=0;i<=b;i++) for(int j=i+1;j<=b;j++) Push(i,j);
    for(int i=0;i<=b;i++) for(int j=0;j<=b;j++)
    {
        if(i==j||Sun[i].life==0||Sun[j].life==0) continue;
    if(Sun[i].what==4&&(Sun[j].what>=100&&Sun[j].what<200)) {if(abs(ix-jx)<1&&abs(iy-jy)<1) Ba--,Sun[i].life=Sun[j].life=0,Score+=10;}

        if(Sun[i].what==203&&Sun[i].master!=j&&Sun[j].what<200) if(abs(ix-jx)<2&&abs(iy-jy)<2) Sun[j].vx-=Sun[i].vx/10.0,Sun[j].vy-=Sun[i].vy/10.0,Sun[i].life=0;
        if(Sun[i].what==204&&Sun[i].master!=j&&Sun[j].what<200) if(abs(ix-jx)<2&&abs(iy-jy)<2) Sun[j].vx+=Sun[i].vx/10.0,Sun[j].vy+=Sun[i].vy/10.0,Sun[i].life=0;

    }
    int i=0;
    if(m[ix][iy]>0&&m[ix][iy]<100)
    {
        if(m[ix][iy]<=1) Blood-=1;
        else if(m[ix][iy]<=4) Blood-=2;
        else if(m[ix][iy]<=10) Blood-=3;
        else if(m[ix][iy]>10&&m[ix][iy]<100) Blood-=4;
    }
    for(int i=1;i<=b;i++){
        if(Sun[i].life==0) continue;
        Sun[i].x+=Sun[i].vx/Speedmore;Sun[i].y+=Sun[i].vy/Speedmore;
        Balljump=-0.7;
        if(Sun[i].what==3) Balljump=-1;
        if(Sun[i].what==4) Balljump=-1;
        if(Sun[i].x>40) Sun[i].x=40,Sun[i].vx*=Balljump;
        if(Sun[i].x<0) Sun[i].x=0,Sun[i].vx*=Balljump;if(Sun[i].y>40) Sun[i].y=40,Sun[i].vy*=Balljump;if(Sun[i].y<0) Sun[i].y=0,Sun[i].vy*=Balljump;
        if(Sun[i].what==1) {m[ix][iy]+=2;int R;R=rand(3);if(R==0&&ix<40) m[ix+1][iy]++;R=rand(3);if(R==0&&ix>0) m[ix-1][iy]++;R=rand(3);if(R==0&&iy<40) m[ix][iy+1]++;R=rand(3);if(R==0&&iy>0) m[ix][iy-1]++;}
        if(Sun[i].what==2) {m[ix][iy]+=2;if(ix<40) m[ix+1][iy]+=10;if(ix>0) m[ix-1][iy]+=10;if(iy<40) m[ix][iy+1]+=10;if(iy>0) m[ix][iy-1]+=10;if(ix<40&&iy<40) m[ix+1][iy+1]+=4;if(ix<40&&iy>0) m[ix+1][iy-1]+=4;if(ix>0&&iy<40) m[ix-1][iy+1]+=4;if(ix>0&&iy>0) m[ix-1][iy-1]+=4;m[ix][iy]=10086;} 
        if(Sun[i].what==3) {if(abs(ix-Sun[0].x)<1&&abs(iy-Sun[0].y)<1) Ba--,Sun[i].life=0;else m2[ix][iy]=2;}
        if(Sun[i].what==4) {m2[ix][iy]=2;}
        if(Sun[i].what>=100&&Sun[i].what<300)
        {
            if(Sun[i].x==0||Sun[i].y==0||Sun[i].x==40||Sun[i].y==40||(abs(Sun[i].vx)<=0.5&&abs(Sun[i].vy)<=0.5)) Sun[i].life=0;
            if(Sun[i].what==203||Sun[i].what==204) {m[ix][iy]=Sun[i].what;if(ix<40) m[ix+1][iy]=Sun[i].what;if(ix>0) m[ix-1][iy]=Sun[i].what;if(iy<40) m[ix][iy+1]=Sun[i].what;if(iy>0) m[ix][iy-1]=Sun[i].what;}
            else m2[ix][iy]=Sun[i].what;
        } 
    }
    if(Sun[0].life==1) m2[toint(Sun[0].x/1.0)][toint(Sun[0].y/1.0)]=1;
    Paint(a);
}
void Paint(int a){
for(int i=0;i<=40;i++) for(int j=0;j<=40;j++){
    if(a==0&&Painting[i][j]!=0) continue;

    if(m2[i][j]!=n2[i][j]){n2[i][j]=m2[i][j];n[i][j]=0;Setpos(i,j);
    if(m2[i][j]==0) Color(0),cout<<"  ";
    else if(m2[i][j]==1) Color(-1),cout<<"●";
    else if(m2[i][j]==2) Color(-3),cout<<"◎";
    else if(m2[i][j]==101) Color(-1),cout<<"☉";
    else if(m2[i][j]==102) Color(3),cout<<"  ";
    continue;}
    if(m[i][j]!=n[i][j]){n[i][j]=m[i][j];n2[i][j]=0;Setpos(i,j);
    if(m[i][j]>=10086) Color(4),cout<<"●";
    else if(m[i][j]==203) Color(5),cout<<"  ";
    else if(m[i][j]==204) Color(6),cout<<"  ";
    else if(m[i][j]==0) Color(0),cout<<"  ";else if(m[i][j]<=1) Color(1),cout<<"  ";else if(m[i][j]<=4) Color(2),cout<<"  ";else if(m[i][j]<=10) Color(3),cout<<"  ";else if(m[i][j]>10&&m[i][j]<100) Color(4),cout<<"  ";
    else Color(0),cout<<"?!";}Color(0);
    }
}
void RandStart(int a) {for(int i=1;i<=a;i++) {b++;Sun[b].x=rand(41),Sun[b].y=rand(41);Sun[b].vx=(rand(41)-20)/10.0,Sun[b].vy=(rand(41)-20)/10.0,Sun[b].m=1,Sun[b].r=1,Sun[b].life=1,Sun[b].what=1;}}
void CornerStart(int a) {for(int i=1;i<=a;i++) {b++;int k=rand(4);if(k==0||k==2) Sun[b].x=rand(41);else Sun[b].y=rand(41);if(k==0) Sun[b].y=0;if(k==1) Sun[b].x=0;if(k==2) Sun[b].y=40;if(k==3) Sun[b].x=40;Sun[b].vx=(rand(41)-20)/10.0,Sun[b].vy=(rand(41)-20)/10.0,Sun[b].m=1,Sun[b].r=1,Sun[b].life=1,Sun[b].what=1;}}
void SunStart(int x,int y,int r,int vx,int vy) {
b++;Sun[b].x=x,Sun[b].y=y;Sun[b].vx=vx,Sun[b].vy=vy,Sun[b].m=1000,Sun[b].r=1,Sun[b].life=1,Sun[b].what=2;
for(int i=x-r;i<=x+r;i++) for(int j=y-r;j<=y+r;j++){b++;Sun[b].x=i,Sun[b].y=j;Sun[b].vx=(rand(41)-20)/100.0+vx,Sun[b].vy=(rand(41)-20)/100.0+vy,Sun[b].m=1,Sun[b].r=1,Sun[b].life=1,Sun[b].what=1;}
for(float i=(int)(x-r/2)-0.5;i<=(int)(x+r/2)+0.5;i++) for(float j=(int)(y-r/2)-0.5;j<=(int)(y+r/2)+0.5;j++){b++;Sun[b].x=i,Sun[b].y=j;Sun[b].vx=(rand(41)-20)/100.0+vx,Sun[b].vy=(rand(41)-20)/100.0+vy,Sun[b].m=1,Sun[b].r=1,Sun[b].life=1,Sun[b].what=1;}
}
void Shoot(int a,bool q)
{
    double Sunavx=Sun[a].vx,Sunavy=Sun[a].vy;
    if(Sun[a].vx==0&&Sun[a].vy==0) Sunavx=-1;if(Sun[a].vy==0) Sunavy=0.001;
    if(Sun[a].gun>=1&&Sun[a].gun<=4)
    {
        b++;Sun[b].x=Sun[a].x,Sun[b].y=Sun[a].y;double ac;
        if(Sun[a].gun==1) ac=3.0; 
        if(Sun[a].gun>=2&&Sun[a].gun<=4) ac=7.0;
        double d=abs(Sunavx/Sunavy*1.0);Sun[b].vy=sqrt(ac/(1+d*d))*1.0,Sun[b].vx=sqrt(ac/(1+d*d))*d*1.0;
        if(Sunavx>0) Sun[b].vx*=-1;if(Sunavy>0) Sun[b].vy*=-1;if(q==1) Sun[b].vx*=-1,Sun[b].vy*=-1;Sun[b].life=1;
        Sun[b].master=a;
        int bb=b;
        if(Sun[a].gun==1||Sun[a].gun==2) Sun[b].what=100+Sun[a].gun,Sun[b].m=1;
        if(Sun[a].gun==3||Sun[a].gun==4) Sun[b].what=200+Sun[a].gun,Sun[b].m=1;
        if(Sun[a].gun>=2&&Sun[a].gun<=4){
    double kx=Sun[bb].x,ky=Sun[bb].y;
    for(int j=1;j<=7;j++)
    {
    kx-=Sun[bb].vx/3.5,ky-=Sun[bb].vy/3.5;
    if(kx<0||ky<0||kx>40||ky>40) continue;
    b++,Sun[b].x=kx,Sun[b].y=ky,Sun[b].vx=Sun[bb].vx,Sun[b].vy=Sun[bb].vy,Sun[b].what=Sun[bb].what,Sun[b].master=a,Sun[b].life=1;
    }
        }
    }
}
void Start(){
    for(int i=0;i<=40;i++) for(int j=0;j<=40;j++){if(Painting[i][j]==1) Setpos(i,j),Color(-2),cout<<"■";if(Painting[i][j]==2) Setpos(i,j),Color(-2),cout<<"作者:蒟蒻一枚";if(Painting[i][j]==3) Setpos(i,j),Color(-2),cout<<"按 y 开始游戏!";if(Painting[i][j]==4) Setpos(i,j),Color(-2),cout<<"不要搞错成拼音输入法!";if(Painting[i][j]==5) Setpos(i,j),Color(-2),cout<<"Three-Body STAR WARs!";}
    for(int i=1;i<=3;i++) SunStart(rand(31)+5,rand(31)+5,5,(rand(101)-50)/10.0,(rand(101)-50)/10.0);
    T=0;
    while(1){
        T++;
        if(T%50==0) CornerStart(1);
        if(kbhit()){char g=_getch();if(g=='y') break; }
        Move(0);
        Sleep(Speed);
    }
    Color(0);system("cls");
    Setpos(10,10);SlowDisplay(30,"你想要教程吗?(y/n)");
    char g=_getch();if(g!='y') return;Setpos(10,10);SlowDisplay(30,"那我们开始。。。   ");Sleep(500);
    system("cls");
    Setpos(30,10);system("cls");

    memset(Sun,0,sizeof(Sun));memset(m,0,sizeof(m));memset(m2,0,sizeof(m2));
    Sun[0].x=Sun[0].y=20;Sun[0].life=1;Sun[0].m=10;
    T=0;
    int step=0;
    while(1){
        T++;
        if(T==2)
        {
        Setpos(10,10),SlowDisplay(30,"这是你的飞船,你可以用↑↓←→键来操纵它。");Sleep(500);
        Setpos(12,10),SlowDisplay(30,"在宇宙航行没有阻力,也就是说你的惯性会主导一切。");Sleep(500);
        Setpos(14,10),SlowDisplay(30,"当你撞到边界时,你的速度会减为零。");Sleep(1000); 
        Setpos(16,10),SlowDisplay(30,"试试看。");
        }
        if(T==200)
        {
        Setpos(10,10),SlowDisplay(30,"在宇宙航行时有两个小技巧:                ");
        Setpos(12,10),SlowDisplay(30,"1、不要太快。                                   ");
        Setpos(14,10),SlowDisplay(30,"2、有时转向比调头更有用。         ");Sleep(1000);
        Setpos(16,10),SlowDisplay(30,"接下来我们稍稍提高点难度!请到达所有靶位点!");Sleep(500);
        b++;Sun[b].x=rand(40),Sun[b].y=rand(40);Sun[b].vx=(rand(101)-50)/30.0,Sun[b].vy=(rand(101)-50)/30.0,Sun[b].life=1,Sun[b].what=3;Ba++;
        Move(1);Sleep(1000); 
        }
        if(Ba>0) Setpos(1,1),cout<<"剩余靶位点:"<<Ba<<' ';
        if(step>=1) Setpos(5,1),cout<<"Cooling time: "<<Hotguntime<<"    ";
        if(T>200&&Ba==0&&step==0) T=201,step=1,Setpos(1,1),cout<<"           ";
        if(T>300&&Ba==0&&step==1) T=201,step=2,Setpos(1,1),cout<<"           ";
        if(T==202&&step==1)
        {
        Setpos(10,10),SlowDisplay(30,"做的好!看来是时候给你装备初始武器了。");
        Setpos(12,10),SlowDisplay(50,"。。。 星际电磁轨道炮 已装备。");
        Setpos(14,10),SlowDisplay(30,"按下w/s发射子弹!                         ");
        Sun[0].gun=1;Hotguntime=0;
        }
        if(T==300&&step==1)
        {
        Setpos(16,10),SlowDisplay(30,"来吧!请击毁所有靶位点!");Sleep(500);
        b++;Sun[b].x=rand(40),Sun[b].y=rand(40);Sun[b].vx=(rand(101)-50)/30.0,Sun[b].vy=(rand(101)-50)/30.0,Sun[b].life=1,Sun[b].what=4;Ba++;
        Move(1);Sleep(1000); Ba=1;
        }
        if(T==202&&step==2)
        {
        Setpos(10,10),SlowDisplay(30,"太阳什么的你也看到过了。               ");
        Setpos(12,10),SlowDisplay(30,"其旁缠绕着的火会扣你的血。      ");
        Setpos(14,10),SlowDisplay(30,"打靶位点可以积10分,发射子弹-1分,分数达到20通关,简单吧!");Sleep(1000); 
        Setpos(16,10),SlowDisplay(60,"让 我 们  开 始  吧!!!");Sleep(1000); 
        system("cls");return; 
        }
        double v=sqrt(Sun[0].vx*Sun[0].vx+Sun[0].vy*Sun[0].vy);
        if(GetAsyncKeyState(VK_UP)&0x8000) {if(Sun[0].vx>=0) Sun[0].vx-=2*Fire;else if(v<4) Sun[0].vx-=Fire;}
        else if(GetAsyncKeyState(VK_DOWN)&0x8000) {if(Sun[0].vx<=0) Sun[0].vx+=2*Fire;else if(v<4) Sun[0].vx+=Fire;}
        if(GetAsyncKeyState(VK_LEFT)&0x8000) {if(Sun[0].vy>=0) Sun[0].vy-=2*Fire;else if(v<4) Sun[0].vy-=Fire;}
        else if(GetAsyncKeyState(VK_RIGHT)&0x8000) {if(Sun[0].vy<=0) Sun[0].vy+=2*Fire;else if(v<4) Sun[0].vy+=Fire;}

        if(Hotguntime>0) Hotguntime--;
        if(kbhit()){
        char g=_getch();
        if(Hotguntime==0&&g=='s')
        {
            if(abs(Sun[0].vx)>=0.01) Sun[0].vx*=0.7;
            if(abs(Sun[0].vy)>=0.01) Sun[0].vy*=0.7;
            Shoot(0,0);
            Hotguntime=Hotguntimemax;
        }
        if(Hotguntime==0&&g=='w')
        {
            if(abs(Sun[0].vx)<=2) Sun[0].vx*=1.2;
            if(abs(Sun[0].vy)<=2) Sun[0].vy*=1.2;
            Shoot(0,1);
            Hotguntime=Hotguntimemax;
        }
        }
        Move(1);
        Sleep(Speed);
    }
}
int main()
{
    system("mode con cols=82 lines=43");
    CONSOLE_CURSOR_INFO cursor_info={1,0};
    SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursor_info);
    srand((unsigned)time(NULL));
    Y:
    Start();
    memset(Sun,0,sizeof(Sun));memset(m,0,sizeof(m));memset(m2,0,sizeof(m2));
    YY:system("cls");
    Setpos(10,10),SlowDisplay(30,"选难度吧,几个太阳?(0~10,回车确定)");
    int i=10;while(dif[i]!=1&&i>=0){i--;}
    Setpos(12,10);
    if(i==-1) printf("推荐难度:0个太阳。");
    else if(i<10) printf("加油,推荐难度:%d个太阳。",i+1);
    else if(i==10) printf("你通关了!随便选吧!",i);

    Setpos(15,10);
    int p;cin>>p;
    if(p<0||p>10) {SlowDisplay(150,"输入错误!"),Sleep(1000);goto YY;}
    for(int i=1;i<=p;i++) SunStart(rand(31)+5,rand(31)+5,5,(rand(101)-50)/10.0,(rand(101)-50)/10.0);
    Sun[0].x=Sun[0].y=5;Sun[0].vx=0.1;Sun[0].life=1;Sun[0].m=10;
    T=0;
    Sun[0].gun=1;
    Blood=100;
    Score=0;Ba=0;
    for(int i=1;i<=10;i++) {b++;Sun[b].x=rand(40),Sun[b].y=rand(40);Sun[b].vx=(rand(101)-50)/30.0,Sun[b].vy=(rand(101)-50)/30.0,Sun[b].life=1,Sun[b].what=4;Ba++;}
    while(Blood>0&&Score<100){
        Setpos(1,1),cout<<"Blood: "<<Blood<<"    ";
        Setpos(3,1),cout<<"Score: "<<Score<<"    ";
        Setpos(5,1),cout<<"Cooling time: "<<Hotguntime<<"    ";
        T++;
        if(T==1) Sleep(1000);
        if(T%50==0) CornerStart(1);
        if(T%30==0&&Ba<5) {b++;Sun[b].x=rand(40),Sun[b].y=rand(40);Sun[b].vx=(rand(101)-50)/30.0,Sun[b].vy=(rand(101)-50)/30.0,Sun[b].life=1,Sun[b].what=4;Ba++;}
        if(T%40==0&&Blood<100) Blood++;

        double v=sqrt(Sun[0].vx*Sun[0].vx+Sun[0].vy*Sun[0].vy);
        if(GetAsyncKeyState(VK_UP)&0x8000) {if(Sun[0].vx>=0) Sun[0].vx-=2*Fire;else if(v<4) Sun[0].vx-=Fire;}
        else if(GetAsyncKeyState(VK_DOWN)&0x8000) {if(Sun[0].vx<=0) Sun[0].vx+=2*Fire;else if(v<4) Sun[0].vx+=Fire;}
        if(GetAsyncKeyState(VK_LEFT)&0x8000) {if(Sun[0].vy>=0) Sun[0].vy-=2*Fire;else if(v<4) Sun[0].vy-=Fire;}
        else if(GetAsyncKeyState(VK_RIGHT)&0x8000) {if(Sun[0].vy<=0) Sun[0].vy+=2*Fire;else if(v<4) Sun[0].vy+=Fire;}

        if(Hotguntime>0) Hotguntime--;
        if(kbhit()){
        char g=_getch();
        if(Hotguntime==0&&g=='s')
        {
            if(abs(Sun[0].vx)>=0.01) Sun[0].vx*=0.7;
            if(abs(Sun[0].vy)>=0.01) Sun[0].vy*=0.7;
            Shoot(0,0);
            Score=max(Score-1,0);
            Hotguntime=Hotguntimemax;
        }
        if(Hotguntime==0&&g=='w')
        {
            if(abs(Sun[0].vx)<=2) Sun[0].vx*=1.2;
            if(abs(Sun[0].vy)<=2) Sun[0].vy*=1.2;
            Shoot(0,1);
            Score=max(Score-1,0);
            Hotguntime=Hotguntimemax;
        }
        }Move(1);
        Sleep(Speed);
    }
    system("cls");
    if(Score<20) Setpos(10,10),SlowDisplay(150,"Sorry,你死了。"); 
    else Setpos(10,10),SlowDisplay(10,"赢了!快去挑战下一个难度吧!"),dif[p]=1; 
    Sleep(1000); 
    goto Y;
    return 0;
}

到了这里,关于C++三体星战小游戏的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • C++炸弹小游戏

    游戏效果 小人可以随便在一些元素(如石头,岩浆,水,宝石等)上跳跃,“地面”一直在上升,小人上升到顶部或者没有血的时候游戏结束(初始20点血),小人可以随意放炸弹,共有八种炸弹。但是被炸到或者碰到岩浆就要减一滴血,拿到宝石加一滴血。炸弹炸掉石头可

    2024年02月11日
    浏览(44)
  • 小游戏:人生中写的第一个小游戏——贪吃蛇(C语言)

            小编开了一个关于游戏的专栏,主要是运用easyx图形库进行的。        第一章:人生中写的第一个小游戏——贪吃蛇(C语言)         这个游戏的代码我在gitee上发布了,大家如果不嫌弃,可以进入这个网址进行查看和复制:https://gitee.com/rising-sun-1。      

    2024年02月09日
    浏览(57)
  • 贪吃蛇小游戏(C++)

    首先我们需要下载EasyX(具体的方法在EasyX专栏中有提到) easyX下载和绘制简单基本图形_小梁今天敲代码了吗的博客-CSDN博客 贪吃蛇这个游戏我们一定都玩过,玩家使用方向键操控一条“蛇”,蛇会朝着一个方向不断移动,玩家可以通过上下左右键改变其运动方向。同时屏幕

    2023年04月27日
    浏览(37)
  • c++制作小游戏2048

    完整代码来自于爱编程的柚子《【C语言/C++游戏项目】:2048小游戏,超详细教程教会你写这个小游戏。》 这个游戏用到了#include graphics.h,思路比较简单。 首先做出游戏页面,然后画出4*4的格子,利用map二维数组,依据数字{0,2,4,8,16,32,64,128,256,512,1024,2048}找到对应颜色在固定位

    2024年02月13日
    浏览(44)
  • c++小游戏:随机迷宫

    实现方法: c++游戏小技巧6:rand()+随机迷宫(3写法:BFS,DFS,并查集)_L(\\\'ω\\\')┘脏脏包└(\\\'ω\\\')」的博客-CSDN博客 总而言之,把三种代码生成编到了一起,加上拿手的主页面及优化 1.0版本就做好了 (注意,关于普通模式,请自备心梗的药)  1.0版本支持: 简单模式:DFS生成,岔路小,看

    2024年02月16日
    浏览(43)
  • C语言小游戏——扫雷

            结合前边我们所学的C语言知识,本期我们将使用C语言实现一个简单的小游戏——扫雷 目录 前言 总体框架设计 多文件分装程序 各功能模块化实现 初始化棋盘  棋盘打印 埋雷  判赢与排雷 游戏逻辑安排 总结         和三子棋相同,游戏开始时不需要任何判

    2024年02月06日
    浏览(48)
  • C语言:扫雷小游戏

    文接上一篇博文C语言:三子棋小游戏。本篇博文是使用C语言来实现扫雷小游戏的。这里不对扫雷的规则进行赘述。玩家通过键盘输入坐标来探雷。博主在实现扫雷之前从未看过扫雷实现的相关视频,所以这里实现的扫雷完全是博主的原生思路,具有逻辑性。下面详细介绍一

    2024年02月09日
    浏览(57)
  • C语言简易小游戏

    本篇博客将带领大家自己动手写一下一些C语言小游戏;以增加对于C语言的兴趣😀😀😀😀😀 首先呢我们先来简单介绍一下这个小游戏: 通常由两个人玩,一方出数字,一方猜。出数字的人要想好一个没有重复数字,不能让猜的人知道。猜的人就可以开始猜。 如正确答案为

    2024年02月07日
    浏览(38)
  • C语言扫雷小游戏

    扫雷的玩法:在一个9×9(初级)、16×16(中级)、16×30(高级)或自定义大小的方块矩阵中随机布置一定量的地雷(初级为10个,中级为40个,高级为99个),再由玩家逐个翻开方块,翻开的地方将显示周围八个雷的个数。以找出所有地雷为最终游戏目标。如果玩家翻开的方块

    2024年02月05日
    浏览(58)
  • 扫雷小游戏【C语言】

    目录 前言 一、基本实现逻辑 二、实现步骤 1. 我们希望在进入游戏时有一个菜单让我们选择 2. 我们希望可以重复的玩(一把玩完了还可以接着玩) 3. 采用多文件形式编程  4.要扫雷先得有棋盘(创建棋盘R*N) 5.初始化棋盘  6.打印棋盘 7.设置雷 8.排查雷 三、全部源码: 上期

    2024年02月11日
    浏览(57)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包