#include "graphics.h"
#include "stdio.h"
#include "math.h"
#include "conio.h"
#include<time.h>
//操作提醒函数
void remind()
{
setbkcolor(GREEN);
setbkmode(TRANSPARENT);
setfont(50,0, _T("宋体"));
setcolor(BLUE);
outtextxy(500, 100, _T("*
向左移-----A"));
outtextxy(500, 170, _T("*
向右移-----D"));
outtextxy(450, 240, _T("*增 加 发射角度-----W"));
outtextxy(450, 310, _T("*缩 小 发射角度-----S"));
outtextxy(460, 380, _T("*
发 射 炮 弹------J"));
setcolor(RED);
outtextxy(480, 450, _T("*
退出游戏------E"));
}
//小人函数
void man(int x,int y){
int r=10;
y=y+5;
x=x-15;
setcolor(BLACK);
circle(x,y,r);
line(x,y+8,x,y+25);
line(x,y+8,x+10,y+22);
line(x,y+8,x-10,y+22);
line(x,y+25,x+13,y+50);
line(x,y+25,x-13,y+50);
}
//背景函数
void background(){
float H=190;
float S=1;
float L=0.7f;
for(int j=0;j<730;j++)
{
L+=0.0008f;
H+=50;
setcolor(HSLtoRGB(H,S,L));
line(0,j,1366,j);
}
setfillstyle(BROWN);
bar(0,730,1366,768);
bar(145,700,170,730);
/*
for(j=580;j>-10;j--)
{
setcolor(WHITE);
setfillstyle(RED);
cleardevice();
fillellipse(1000,j,28,32);
//circle(100,j,30);
line(100,j+30,100,j+70);
//floodfill(100, j,WHITE);
delay(2);
}*/
}
//目标物函数
void goalbar(int x){
setfillstyle(RED);
setcolor(WHITE);
fillellipse(1000,300,28,32);
/*setfillstyle(BLACK);
circle(x,710,30);*/
}
//小球函数
void ball(int x,int y){
int r1=8;
int r2=8;
setcolor(BLACK);
setfillstyle(BLACK);
fillellipse(x,y,r1,r2);
}
//计分函数
void score(int x){
char s[10];
setbkmode(TRANSPARENT);
setfont(50,0, _T("微软雅黑"));
outtextxy(500, 20,_T("SCORE:"));
sprintf(s, "%d", x);
outtextrect(650,20,800,100,s);
}
//次数函数
void life(int x){
char s[5];
setbkmode(TRANSPARENT);
setfont(50,0, _T("微软雅黑"));
outtextxy(530,70,_T("LIFE:"));
sprintf(s, "%d", x);
outtextrect(630,70,800,100,s);
}
//打印“great”函数
void great(int x){
setbkmode(TRANSPARENT);
setfont(70,0, _T("微软雅黑"));
setcolor(RED);
outtextxy(x-80, 400, _T("Great!"));
}
//打印未打中字样函数
void lose(int x,int anyx){
if(x==0){
setbkmode(TRANSPARENT);
setfont(60,0, _T("微软雅黑"));
setcolor(BLUE);
outtextxy(anyx-80, 500, _T("Oh! No!"));
}
if(x==1){
setbkmode(TRANSPARENT);
setfont(60,0, _T("微软雅黑"));
setcolor(BLUE);
outtextxy(anyx-80, 500, _T("Hi! Boy!"));
}
}
void Balloon(){
int j;
/*for(j=580;j>10;j--){BeginBatchDraw();
setfillstyle(MAGENTA);
setcolor(WHITE);
cleardevice();
circle(100,j,30);
floodfill(100, j,WHITE);
delay(2);
//fillellipse(1050,j,28,32);
}
EndBatchDraw();*/
}
void Zhujm(int startx,int starty,int realx,int realy,int anyx,int s,int l){
BeginBatchDraw();
background();
Balloon();
ball(startx,starty);
man(realx,realy);
setcolor(BLACK);
line(startx,starty,realx,realy);
goalbar(anyx);
score(s);
life(l);
EndBatchDraw();
}
void countl(double i,int *x,int y,double sin,double cos,int startx,int starty,int realx,int realy,int anyx,int s,int l){
for (i=0;;i=i+0.10){
*x=(int)ceil(startx+220*cos*(i+1));
y=(int)ceil(starty-(220*sin*(i+1)-25*(i+1)*(i+1)/2));
if(*x>=1000)break;
BeginBatchDraw();
background();
Balloon();
ball(*x,y);
man(realx,realy);
goalbar(anyx);
score(s);
life(l);
EndBatchDraw();
delay(0);
}
}
int main(){
setinitmode(INIT_NOBORDER);
char a,k[10];
int x,y,startx,starty,rr,realx,realy,anyx,s,l;
double i,cos,sin;
s=0;
l=10;
realx=50;
realy=475;
startx=realx+30;
starty=realy-30;
initgraph(1366,768);
//delay(1000);title();delay(1500);
cleardevice();
delay(800);
remind();
while(!kbhit())
{
//setfont(50,0, _T("微软雅黑"));
setcolor(RED);
outtextxy(500, 600, _T("按任意键开始游戏"));
delay(200);
setfillstyle(GREEN);
bar(500,600,900,650);
delay(200);
}
a=getch();
//游戏界面
while(l!=0){
anyx=180+random(1000);
Zhujm(startx,starty,realx,realy,anyx,s,l);
rr=(startx-realx)*(startx-realx)+(starty-realy)*(starty-realy);
a=getch();
while(a!='e'){
while(a!='k'){
//按键控制
//BeginBatchDraw();
if(realy>=265&&realy<=680&&a=='w'){
realy=realy-3;
starty=starty-3;
Zhujm(startx,starty,realx,realy,anyx,s,l);
}
if(realy>=262&&realy<=677&&(a=='s')){
realy=realy+3;
starty=starty+3;
Zhujm(startx,starty,realx,realy,anyx,s,l);
}
if(startx>=(realx+30)&&startx<=(realx+42)&&(a=='a')){
startx=startx-1;
starty=int(realy-sqrt(rr-(startx-realx)*(startx-realx)));
Zhujm(startx,starty,realx,realy,anyx,s,l);
}
if(startx>=(realx+29)&&startx<=(realx+41)&&(a=='d')){
startx=startx+1;
starty=int(realy-sqrt(rr-(startx-realx)*(startx-realx)));
Zhujm(startx,starty,realx,realy,anyx,s,l);
}
a=getch();
if(a=='e')break;
//EndBatchDraw();
}
if(a=='e')break;
sin=(realy-starty)/sqrt(rr);
cos=(startx-realx)/sqrt(rr);
//小球运行
countl(i,&x,y,sin,cos,startx,starty,realx,realy,anyx,s,l);
/*if(x>=(anyx-13)&&x<=(anyx+33)){
Zhujm(startx,starty,realx,realy,anyx,s,l);
great(x);
for(i=10;i<35;i=i+2){
setcolor(RED);
setfillstyle(RED);
fillellipse(x,720,(int)i,(int)i);
delay(0);
}
delay(1000);
if(s%100==0&&s!=0)
l=l+1;
s=s+50;
anyx=180+random(1000);
Zhujm(startx,starty,realx,realy,anyx,s,l);
}*/
if(y>=200&&y<=1000){
Zhujm(startx,starty,realx,realy,anyx,s,l);
great(y);
for(i=10;i<35;i=i+2){
setcolor(RED);
setfillstyle(RED);
fillellipse(y,720,(int)i,(int)i);
delay(10);
}
delay(1000);
if(s%100==0&&s!=0)
l=l+1;
s=s+50;
//anyx=180+random(1000);
Zhujm(startx,starty,realx,realy,anyx,s,l);
}
//未命中目标
else {
lose(random(2),x);
delay(1000);
l=l-1;
Zhujm(startx,starty,realx,realy,anyx,s,l);
}
//}
//判断是否结束
if(l==0){
background();
setfont(350,0, _T("微软雅黑"));
setcolor(RED);
sprintf(k, "%d", s);
outtextxy(460,200,k);
setfont(50,0, _T("微软雅黑"));
setcolor(BLUE);
outtextxy(560, 550, _T("按任意键继续"));
outtextxy(560, 600, _T(" 按 E 键退出"));
l=10;
s=0;
a=getch();
break;
}
else a=getch();
}
if(a=='e')break;
}
closegraph();
// 关闭图形界面
return 0;
}
怎样才能打中气球?才注册的账号,请见谅