#include<stdio.h>
#include<graphics.h>
#include<easyx.h>
#include<conio.h>
#include<time.h>
#include <windows.h>
#include<stdlib.h>
#define NUMBER 80
void SCREEN(char c);/*出场屏幕控制*/
void initializtion1(char c);/*第一部分初始化*/
void initializtion2(char c);/*第二部分初始化*/
void CHART(char c);/*绘制计分器*/
void PAINTPLANE1(char c);/*绘制我方飞机函数1-WHITE*/
void PAINTPLANE2(char c);/*绘制我方飞机函数2-BLACK*/
void KEYB(char c);/*我方飞机按键控制*/
void BULL(char c);/*我方飞机子弹绘制*/
void ENEMY(char c);/*敌方飞机与子弹的绘制*/
void BULL2(char c);/*BOSS出现后我方子弹的绘制*/
void BOSS(char c);/*BOSS的绘制*/
void SCREENB(char c);/*BOSS出场屏幕控制*/
void DESTINYBAR(char c);/*生命方块*/
void SPEEDBAR(char c);/*速度方块*/
void KSCREEN(char c);/*必杀技效果*/
int destiny,score,x,y,i,j,k,n,f,p,q,spx,spy,zuobiao,DX,DY,boss,num,SX1,SY1,SX2,SY2,z1,z2,dx1,dx2,ATTACK;
int X[NUMBER],Y[NUMBER],N[NUMBER][NUMBER],M[NUMBER][NUMBER],DESTINY[NUMBER];/*敌方飞机的横纵坐标,敌方飞机子弹的横纵坐标,敌方飞机的生命*/
bool first[NUMBER],FIRST[NUMBER][NUMBER],Q,PLANE[NUMBER],ENERMYS[NUMBER],S1,S2;/*碰撞检测中用于检测是否第一次相遇*/
char jieguo[NUMBER],shengming[NUMBER],hengxiang[NUMBER],zongxiang[NUMBER];
int Nb[NUMBER],Mb[NUMBER];/*BOSS出现时屏幕子弹*/
int main(void)
{
initgraph(1000,600);
char c;
c=0;
SCREEN(c);
initializtion1(c);
loop:
initializtion2(c);
while(1) /*未出现BOSS时的主函数*/
{
if(destiny<=0)
break;
if(score>=3000)
break;
PAINTPLANE1(c);
ENEMY(c);
CHART(c);
if(kbhit())
{
c=getch();
if(c!='j'&&c!='k')
{
PAINTPLANE2(c);
KEYB(c);
PAINTPLANE1(c);
}
if(c=='j')
BULL(c);
if((score>=500)&&(score<3000))
{
if(c=='k')
{
KSCREEN(c);
goto loop;
}
}
}
DESTINYBAR(c);
SPEEDBAR(c);
if((f==n)||((zuobiao+f)==n))
{
cleardevice();
CHART(c);
PAINTPLANE1(c);
goto loop;
}
Sleep(50);
}
if(score>=3000) /*出现BOSS时的主函数*/
{
SCREENB(c);
while(1)
{
BOSS(c);
if(boss<=0)
{
score+=2000;
settextcolor(RED);
settextstyle(50, 0, "黑体");
outtextxy(250,250,"YOU WIN!");
sprintf(jieguo,"%d",score);
outtextxy(250,310,"最后得分:");
sprintf(shengming,"%d",destiny);
outtextxy(250,370,jieguo);
Sleep(3000);
settextstyle(20, 0, "黑体");
outtextxy(700,550,"按任意键退出......");
Sleep(500);
getch();
exit(0);
}
if(destiny<=0)
break;
PAINTPLANE1(c);
if(kbhit())
{
c=getch();
if(c!='j'&&c!='k')
{
PAINTPLANE2(c);
KEYB(c);
PAINTPLANE1(c);
}
if(c=='j')
BULL2(c);
}
DESTINYBAR(c);
Sleep(50);
}
}
if(destiny<=0)
{
cleardevice();
settextcolor(RED);
settextstyle(50, 0, "黑体");
outtextxy(250,250,"GAME OVER!");
sprintf(jieguo,"%d",score);
outtextxy(250,310,"最后得分:");
sprintf(shengming,"%d",destiny);
outtextxy(250,370,jieguo);
}
Sleep(3000);
settextstyle(20, 0, "黑体");
outtextxy(700,550,"按任意键退出......");
Sleep(500);
getch();
closegraph();
}
void SCREEN(char c)
{
for(i=0;i<240;i+=5)
{
settextstyle(40, 0, "黑体");
settextcolor(RGB(i,i,i));
outtextxy(250,200,"BEGIN!");
outtextxy(250,250,"真正的勇士是无所畏惧的!");
settextstyle(20, 0, "黑体");
outtextxy(250,310,"按键说明:w,s,a,d 上下左右;");
outtextxy(250,340,"攻击说明:j:攻击; k:必杀技(积分-300,屏幕内所有敌机全部死亡)");
outtextxy(250,370,"游戏中随机会有生命方块下落,如果碰到会增加随机生命值");
outtextxy(700,500,"按任意键开始......");
Sleep(50);
}
getch();
cleardevice();
}
void CHART(char c)
{
setcolor(WHITE);
setfillcolor(WHITE); /*计分器*/
line(800,0,800,600);
settextstyle(20, 0, "黑体");
outtextxy(810,0,"目前得分:");
sprintf(jieguo,"%d",score);
outtextxy(910,0,jieguo);
if(destiny<1000)
{
outtextxy(810,50,"生命值:");
sprintf(shengming," %d",destiny);
outtextxy(880,50,shengming);
}
else
{
outtextxy(810,50,"生命值:");
sprintf(shengming,"%d",destiny);
outtextxy(880,50,shengming);
}
outtextxy(810,100,"横向速度:");
sprintf(hengxiang,"%d",spx);
outtextxy(890,100,hengxiang);
outtextxy(810,130,"纵向速度:");
sprintf(zongxiang,"%d",spy);
outtextxy(890,130,zongxiang);
}
void initializtion1(char c)
{
x=500;
z1=100;
z2=200;
S1=true;
S2=true;
num=0;
y=490;
spx=10;
spy=5;
DX=280;
DY=100;
q=0;
srand(time(NULL));
destiny=3000;
boss=5000;
for(i=0;i<=15;i++)
{
Nb[i]=rand()%700+50;
Mb[i]=rand()%300+10;
}
}
void initializtion2(char c)
{
if(q<=4)
q++;
else
q=rand()%3;
zuobiao=0;
n=rand()%2+2*q;
p=rand()%1+q;
f=0;
CHART(c);
for(i=0;i<n;i++) /*继续初始化坐标*/
{
X[i]=rand()%500+200;
Y[i]=0;
DESTINY[i]=300;
first[i]=false;
PLANE[i]=false;
ENERMYS[i]=false;
for(j=0;j<p;j++)
{
N[i][j]=X[i]+15;
M[i][j]=Y[i]+25;
FIRST[i][j]=false;
}
}
}
void PAINTPLANE1(char c)
{
setfillcolor(WHITE);
solidrectangle(x,y-10,x+20,y);
solidrectangle(x+30,y-10,x+50,y);
solidrectangle(x+10,y-20,x+40,y-10);
solidrectangle(x+20,y-30,x+30,y-20);
}
void PAINTPLANE2(char c)
{
setfillcolor(BLACK);
solidrectangle(x,y-10,x+20,y);
solidrectangle(x+30,y-10,x+50,y);
solidrectangle(x+10,y-20,x+40,y-10);
solidrectangle(x+20,y-30,x+30,y-20);
}
void KEYB(char c)
{
if(c=='d'&& x<740)
x=x+spx;
if(c=='a' && x>10)
x=x-spx;
if(c=='w' && y>30)
y=y-spy;
if(c=='s' && y<590)
y=y+spy;
}
void BULL(char c) /*BOSS出现前发射的子弹参数*/
{
int n,m,i;
n=x+25;
m=y-35;
setcolor(WHITE);
setfillcolor(WHITE);
solidcircle(n,m,5);
for(i=0;i<41;i++)
{
setfillcolor(BLACK);
solidcircle(n,m,5);
m=m-15;
setfillcolor(WHITE);
solidcircle(n,m,5);
if(score<=3000)
{
for(j=0;j<15;j++)
{
if(((n+5)>=X[j])&&((n-5)<=X[j]+30)&&((m-5)<=Y[j]+20)&&((m+5)>=Y[j]))
DESTINY[j]-=50;
}
}
Sleep(1);
}
}
void KSCREEN(char c)
{
printf("\a\a");
score-=500;
settextstyle(80, 0, "黑体");
for(i=0;i<255;i+=5)
{
settextcolor(RGB(i,0,0));
outtextxy(200,200,"BOOM!");
Sleep(20);
}
for(k=255;k>=0;k-=5)
{
settextcolor(RGB(k,0,0));
outtextxy(200,200,"BOOM!");
setfillcolor(RGB(k,0,0));
for(i=0;i<n;i++)
{
if(first[i]==false)
{
solidrectangle(X[i],Y[i],X[i]+10,Y[i]+10);
solidrectangle(X[i]+20,Y[i],X[i]+30,Y[i]+10);
solidrectangle(X[i]+10,Y[i]+10,X[i]+20,Y[i]+20);
}
for(j=0;j<p;j++)
solidcircle(N[i][j],M[i][j],5);
}
Sleep(50);
}
cleardevice();
}
void ENEMY(char c) /*敌军飞机,子弹的绘制*/
{
for(i=0;i<n;i++)
{
if(DESTINY[i]<=0)
{
setfillcolor(BLACK);
solidrectangle(X[i],Y[i],X[i]+10,Y[i]+10);
solidrectangle(X[i]+20,Y[i],X[i]+30,Y[i]+10);
solidrectangle(X[i]+10,Y[i]+10,X[i]+20,Y[i]+20);
if(first[i]==false)
{
score+=100;
f++;
first[i]=true;
CHART(c);
}
continue;
}
setfillcolor(BLACK);
solidrectangle(X[i],Y[i],X[i]+10,Y[i]+10);
solidrectangle(X[i]
评论0