📄 bb010.c
字号:
/*打星星游戏 作者SZK8888 制作日期:03-10-26 */
/*鼠标控制方向 鼠标左键和空格键开火 (纯属无聊的射击游戏)*/
#include <stdlib.h>
#include <stdio.h>
#include <graphics.h>
#include <dos.h>
#include <math.h>
#include <time.h>
#include "KEY.c"
#include "mouse3.c"
#define PI 3.1415927
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void VGA_RESET();
void set_color(int color,int R,int G,int B);
void GB_PERSON(int X1,int Y1,int a,int COLOR); /*绘制角色*/
int Round(float x); /*四舍五入*/
void TimeDelay(unsigned long microsec); /*延时函数 传入微秒数*/
void MOVE_TO3(int oa,float *PX,float *PY,int D); /*移动到*/
void TRANSFORM(char filename[],int *NAME); /*把图象文件置入数组*/
void GB_TBF(int x,int y,int *NAME); /*显示*/
int TimeDelayUnit(float t);
int Xrand(int A,int B); /*随机数发生器A—B*/
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
main()
{
int END=0; /*游戏结束*/
int E_FIRE_ATTACK=90;
int n,i,j;
/*定义角色结构*/
struct PERSON {
int LIVE;
float X1; /*屏幕坐标*/
float Y1;
float X0;
float Y0;
int a; /*角度*/
int a0;
int COLOR;
int reload;
int move;
int fire;
};
struct PERSON MAN; /*定义玩家*/
/*定义子弹结构*/
struct BB{
int RUN; /*是否运行 */
float PX; /*当前坐标X*/
float PY; /*当前坐标Y*/
int oa; /*目标角度 */
int LB; /*运行周期 */
int MAX_LB;
};
struct BB MB[30]; /*玩家子弹*/
struct BB SB[30];
struct blast{
int RUN; /*是否运行 */
float PX; /*当前坐标X*/
float PY; /*当前坐标Y*/
int D_time;
/*运行周期 */
int MAX_D_time;
};
struct blast BBB[30];
int STAR[30][30];
int BLAST[30][30];
int mx0; /* 鼠标原来的位置 */
struct time t; /*系统时间*/
int R;
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
VGA_RESET(); /*图形初始化*/
InstallKeyboard(); /*键盘中断初始化*/
initmouse(); /* 鼠标初始化 */
setmousexy(320,240); /* 设置鼠标位置 */
srand(Xrand(31,72456));
gettime(&t); /*取系统时间*/
R=t.ti_hund; /*R=毫秒*/
srand(R); /*产生真正的随机数种子*/
/*+++++++++++++++++++++GAME 开始+++++++++++++++++++++++++++++*/
/*+++++++++++++++++++++初始化玩家++++++++++++++++++++++++++++*/
MAN.LIVE=1;
MAN.X1=320;
MAN.Y1=460;
MAN.X0=MAN.X1;
MAN.Y0=MAN.Y1;
MAN.a=270;
MAN.a0=MAN.a;
MAN.COLOR=9;
MAN.reload=0;
MAN.move=0;
MAN.fire=0;
/*+++++++++++++++++++++初始化子弹++++++++++++++++++++++++++++*/
for(n=0;n<30;n++) /*玩家子弹初始化*/
{
MB[n].RUN=0;
MB[n].MAX_LB=2;
MB[n].LB=MB[n].MAX_LB;
}
for(n=0;n<30;n++) /*子弹初始化*/
{
SB[n].RUN=0;
SB[n].MAX_LB=10;
SB[n].LB=SB[n].MAX_LB;
}
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
for(n=0;n<30;n++) /*初始化*/
{
BBB[n].RUN=0;
BBB[n].MAX_D_time=20;
BBB[n].D_time=BBB[n].MAX_D_time;
}
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
TRANSFORM("STAR.TBF",&STAR[0][0]);
TRANSFORM("BZ.TBF",&BLAST[0][0]);
GB_PERSON(MAN.X1,MAN.Y1,MAN.a,9);
/*大循环开始*/
while(END!=1)
{
/*++++++++++++++++++++++++子弹飞行++++++++++++++++++++++++++++*/
/*玩家的子弹*/
for(n=0;n<30;n++)
{
if(MB[n].RUN==1)
{
if(MB[n].LB<=0)
{
setfillstyle(1,0);
bar(MB[n].PX,MB[n].PY,MB[n].PX+1,MB[n].PY+1);
MOVE_TO3(MB[n].oa,&MB[n].PX,&MB[n].PY,10);
setfillstyle(1,14);
bar(MB[n].PX,MB[n].PY,MB[n].PX+1,MB[n].PY+1);
MB[n].LB=MB[n].MAX_LB;
}
if(MB[n].PX<=40||MB[n].PX>=600||MB[n].PY<=40)
{ /*子弹碰墙 消失*/
setfillstyle(1,0);
bar(MB[n].PX,MB[n].PY,MB[n].PX+1,MB[n].PY+1);
MB[n].RUN=0;
}
MB[n].LB--; /*延时*/
}
}
/*子弹*/
for(n=0;n<30;n++)
{
if(SB[n].RUN==1)
{
if(SB[n].LB<=0)
{
setfillstyle(1,0);
bar(SB[n].PX,SB[n].PY,SB[n].PX+29,SB[n].PY+29);
MOVE_TO3(SB[n].oa,&SB[n].PX,&SB[n].PY,10);
GB_TBF(SB[n].PX,SB[n].PY,&STAR[0][0]);
SB[n].LB=SB[n].MAX_LB;
}
if(SB[n].PY>=400)
{ /*子弹碰墙 消失*/
setfillstyle(1,0);
bar(SB[n].PX,SB[n].PY,SB[n].PX+29,SB[n].PY+29);
SB[n].RUN=0;
}
SB[n].LB--; /*延时*/
}
}
/*++++++++++++++++++++++++接触TOUCH++++++++++++++++++++++++++++*/
/*玩家的子弹与敌人接触*/
for(n=0;n<30;n++)
{
if(MB[n].RUN==1){
for(i=0;i<30;i++)
{
if(SB[i].RUN==1){
if(SB[i].PX<=MB[n].PX /*接触的范围*/
&&
SB[i].PX+29>=MB[n].PX
&&
SB[i].PY<=MB[n].PY
&&
SB[i].PY+29>=MB[n].PY
)
{
MB[n].RUN=0;
setfillstyle(1,0);
bar(MB[n].PX,MB[n].PY,MB[n].PX+1,MB[n].PY+1);
SB[i].RUN=0;
setfillstyle(1,0);
bar(SB[i].PX,SB[i].PY,SB[i].PX+29,SB[i].PY+29);
for(j=0;j<30;j++)
{
if(BBB[j].RUN==0)
{
BBB[j].D_time=BBB[j].MAX_D_time;
BBB[j].PX=SB[i].PX;
BBB[j].PY=SB[i].PY;
BBB[j].RUN=1;
break;
}
}
i=30;
}
}
}/*for i*/
}
}
/*++++++++++++++*/
/*爆炸*/
for(n=0;n<30;n++)
{
if(BBB[n].RUN==1)
{
GB_TBF(BBB[n].PX,BBB[n].PY,&BLAST[0][0]);
BBB[n].D_time--;
if(BBB[n].D_time<=0)
{ /*消失*/
setfillstyle(1,0);
bar(BBB[n].PX,BBB[n].PY,BBB[n].PX+29,BBB[n].PY+29);
BBB[n].RUN=0;
}
}
}
if(TimeDelayUnit(0.5))
{
/*电脑开火*/
E_FIRE_ATTACK=random(100);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -