⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tank041.c

📁 通过c语言编写的坦克大战游戏
💻 C
📖 第 1 页 / 共 5 页
字号:
/*2005-06-13 DJGPP DOS版完成*/
/*2005-07-11 用DEV C++移植到XP下*/

#include <stdlib.h>
#include <stdio.h>
#include <dos.h>
#include <math.h>
#include <time.h>

#include "allegro.h"
#include "graph.c"
#include "2Dmath.c"
#include "camera.c"
#include "adage.c"


#define NPC_max_num 20   /*NPC的最大数*/
#define BB_max_num 80   /*子弹的最大数*/
#define BAO_max_num 80   /*爆炸的最大数*/

#define player_area 13  /*玩家的身体半径范围*/

#define random(num)   (rand() % (num))   /*定义random函数*/

#define ENEMY_SUM 10 /*敌人数量*/
#define FRIEND_SUM 8 /*朋友数量*/

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void MOVE_TO3(int oa,float *PX,float *PY,int D);  /*移动到*/

void GB_PERSON(float X1,float Y1,int a,int kind);   /*绘制数学角色*/

int ask_round(int a,int oa);   /*得到旋转方向*/

int ASK_MAP_AB(int x,int y,int bx,int by,int L,int N);      /* 得到 x y 在 MAP 上的位置 */

void ER_NPC(int x,int y,int n);  /*显示NPC数值*/

void GB_BMP_BB(float X1,float Y1,int Warhead_number);   /*绘制子弹*/

void GB_MATH_BB(float X1,float Y1);   /*绘制数学模式子弹*/


void DISPLAY_B_MAP(float X,float Y);        /*绘制背景层地图*/

void load_file(char filename[],int *SNAME);       /* 读取文件 数据载入SNAME指向的数组*/


void DISPLAY_MAP_UNIT_PIC(int PX,int PY,int n, BITMAP *source); /*绘制单元图片函数*/

void ASK_PIC_DXDY(int n,int *DX,int *DY); /*查找图片元素偏移位置*/

void GB_opx(float x,float y);   /*绘制玩家目标点*/

void GB_BMP_CAR(float X, float Y, int angle1, int angle2, int ID);   /*绘制车辆*/

void GB_BAO(float X,float Y,int BMP_X,int BMP_Y,int fram,int Bao_number);      /*显示爆炸*/


void Xa(int *aa,int *oaa,int X_SPEED); /*改变角度 当前角 目标角 旋转速度*/

void load_config_file(char filename[]);       /* 读取配置文件 */

void DISPLAY_NPC_HP(float X1,float Y1,float HP,float MAX_HP,int color);   /*显示NPC的HP*/
void DISPLAY_BUILD_HP(float X1,float Y1,float HP,float MAX_HP,int color);  /*显示建筑的HP*/

int Xrand(int A,int B);      /*随机数发生器A—B*/

void GB_GUANG_BIAO(float X,float Y,int BMP_X,int BMP_Y,int fram,int Bao_number);      /*显示光标*/

void ASK_BMP_DXDY(int angle, int *DX, int *DY ,int BMP_X,int BMP_Y, int fram); /*根据角度和帧数求出贴图偏移坐标*/



int NPC_CAN_SEE(int n1,int n2);  /*判断n1可以看见n2*/
void display_SEE(int n);

void Alert(float x,float y);   /*显示惊叹号!*/

void rand_pianyi_xy(float *x,int wanwei); /*随机偏移坐标*/

void LEI_DA(int px,int py);  /*显示雷达*/

void GB_JLS_BMP(float X,float Y,int BMP_X,int BMP_Y,int fram);      /*显示降落伞*/

void GB_BOMB_ALERT(float x,float y,int kind);   /*显示炸弹警告!*/

void GB_PLANE(float x,float y, int kind);   /*显示飞机*/

void GB_GoodsBox(float X,float Y,int kind);      /*显示箱子*/

void GB_BMP_BUILD(float X, float Y, int angle1, int ID);    /*绘制贴图 建筑物*/

void display_sum_n(int x,int y,int ii);      /*显示单位数*/

int TimeDelayUnit(float t);  /*时间中断判断*/

void GB_TIME(int x,int y,int TimeM,int TimeS);  /*显示时间*/

void RAND_NPC_AB(int n); /*随机得出NPC的AB 屏幕边缘*/

void INIT_PLAYER_ID(int n,int ID);  /*初始化游戏单位 赋予ID*/

void INIT_PLAYER(int n); /*初始化NPC的其他属性*/

void INIT_PLANE(int n,int BOMB_X,int BOMB_Y,int BOMB_MAX_N,int BOMB_kind,int PLANE_kind);  /*初始化飞机*/

void INIT_A_BB(int x,int y,int opx,int opy,int weapon_number,int NPC_number);  /* 初始化一个子弹 坐标X,坐标Y,目标点X,目标点Y,武器编号,NPC的名字*/

void INIT_A_BAO(int x,int y,int weapon_number);  /* 初始化一个爆炸 坐标X,坐标Y,武器编号*/

void load_weapon_file(char filename[]);       /* 读取武器配置文件 */
void load_unit_file(char filename[]);       /* 读取单位配置文件 */

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

 /*定义角色结构*/
 struct _PLAYER {

                int LIVE;

                float X1;      /*屏幕坐标*/
                float Y1;
                float X0;
                float Y0;

                int MAP_A;        /*MAP坐标*/
                int MAP_B;
                int MAP_A0;
                int MAP_B0;

                int angle[2];         /*角度*/
                int o_angle[2];        /*目标角度*/

                int X_SPEED;     /*旋转速度*/



                int kind;      /*玩家种类 团队*/
                int ID;        /*身份编号*/

                int forward;     /*前进*/
                int backward;    /*后退*/

                int Alert;        /*警报*/
                int A_TIME;

                int player_XROF; /*射速 时间记数*/
                int fire;         /*射击*/

                int move; /*移动坐标*/




                float opx;           /*目标点x*/
                float opy;           /*目标点y*/


                int HP;           /*HP*/
                int MAX_HP;

                int weapon_number; /*武器编号*/





                int whither_x; /*目的地x*/
                int whither_y; /*目的地y*/
                int whether_have_whither; /*是否到达目的地*/


                int Armor;                /*装甲属性 无0   轻1   重2*/

                int Speed;                /*移动速度 慢1 普通2 快3*/

                int kill;


               };


 struct _PLAYER PLAYER[NPC_max_num];     /*定义玩家*/





 /*定义游戏单位结构 常量*/
 struct GAME_UNIT{
                   int MAX_HP; /*最大HP*/
                   int ID;     /*ID编号*/
                   int Armor;  /*装甲属性 无0   轻1   重2*/
                   int Speed;  /*移动速度 慢1 普通2 快3*/
                   int weapon_number; /*武器*/
                   int X_SPEED; /*旋转速度*/
                   char Name[30]; /*名称*/

                 };

 struct GAME_UNIT UNIT[12];      /*游戏单位*/










 /*定义子弹结构*/
 struct bullet {
                int RUN;               /*是否运行 */
                float PX;              /*当前坐标X*/
                float PY;              /*当前坐标Y*/
                float opx;           /*目标点x*/
                float opy;           /*目标点y*/

                int oa;


                int weapon_number;
                int Speed;
                int Warhead_number; /*弹头贴图编号*/

                int NPC_number;

               };

 struct bullet BB[BB_max_num];      /*玩家子弹*/



 /*定义爆炸结构*/
 struct explode {
                 int LIVE;
                 float x;              /*当前坐标X*/
                 float y;              /*当前坐标Y*/

                 int nonce_fram;   /*当前帧号*/
                 int fram_time;    /*每帧记时*/

                 int BAO_MAX_fram;  /*最大帧数*/

                 int weapon_number; /*武器编号*/

                 int Bao_number;  /*图片编号*/
                 int BMP_X;       /*单位图片大小*/
                 int BMP_Y;



                };

 struct explode BAO[BAO_max_num]; /*爆炸*/



 /*定义爆炸贴图结构*/
 struct _BAO_BMP
 {

 int BAO_fram_time; /*爆炸每帧的时间*/
 int BAO_MAX_fram;  /*最大帧数*/
 int BMP_X;  /*每帧的图象大小*/
 int BMP_Y;

 };

 struct _BAO_BMP BAO_BMP[8];




 struct  _weapon
        {

         int MAX_Damage[3]; /*最大杀伤值*/
         int MIN_Damage[3]; /*最小杀伤值*/

         int Bao_range; /*杀伤范围*/
         int ROF; /*射速*/
         int Speed; /*移动速度*/
         int Reload; /*装填时间*/
         int Warhead_number; /*弹头贴图编号*/
         int Bao_number; /*爆炸贴图编号*/
         char Name[30]; /*名称*/

        };

struct _weapon weapon[8]; /*武器*/






 /*定义光标结构*/
 struct _GUANG_BIAO {
                 int LIVE;
                 float x;              /*当前坐标X*/
                 float y;              /*当前坐标Y*/

                 int nonce_fram;   /*当前帧号*/
                 int fram_time;    /*每帧记时*/
                 int fram_MAX_time;

                 int MAX_fram;  /*最大帧数*/


                 int number;  /*图片编号*/
                 int BMP_X;       /*单位图片大小*/
                 int BMP_Y;

                };

 struct _GUANG_BIAO GUANG_BIAO; /*光标*/




 /*定义降落伞结构*/
 struct _ballute {
                 int LIVE;
                 float x;              /*当前坐标X*/
                 float y;              /*当前坐标Y*/


                 int nonce_fram;   /*当前帧号*/
                 int fram_time;    /*每帧记时*/
                 int fram_MAX_time;

                 int MAX_fram;  /*最大帧数*/


                 int kind; /*炸弹1 物品HP2*/
                 };

  struct _ballute JIANG_LUO_SAN[15]; /*降落伞*/







 /*定义飞机结构*/
 struct _plane {
                 int LIVE;
                 float x;              /*当前坐标X*/
                 float y;              /*当前坐标Y*/


                 int BOMB_XROF;
                 int BOMB_XROF_MAX_TIME;

                 int BOMB_FIRE;
                 int BOMB_N;
                 int BOMB_MAX_N;

                 int BOMB_X,BOMB_Y;

                 int BOMB_kind;

                 int kind; /*轰炸机1  运输机 2*/

                 };

  struct _plane PLANE[3]; /*飞机*/










   /*定义箱子结构*/
 struct COLOR_BOX {
                   int LIVE;
                   float x;            /*当前坐标X*/
                   float y;            /*当前坐标Y*/
                   int MAP_A;
                   int MAP_B;

                   int kind;           /*类型*/

                  };

 struct COLOR_BOX GOODS_BOX[3];      /*箱子*/








 int mickeyx = 0;   /*鼠标移动偏移量*/
 int mickeyy = 0;


 int MX,MY;  /*鼠标屏幕坐标转换为地图相对坐标*/

 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

/*贴图文件*/
BITMAP *bmp;

BITMAP *TANK_01;
BITMAP *TANK_02;
BITMAP *TANK_03;
BITMAP *TANK_04;

BITMAP *BUILD_01;

BITMAP *BBD_01; /*BB弹*/
BITMAP *BBD_02; /*BB弹*/

BITMAP *BAO_01;
BITMAP *BAO_02;
BITMAP *BAO_03;
BITMAP *BAO_04;
BITMAP *BAO_05;
BITMAP *BAO_06;
BITMAP *BAO_07;


BITMAP *bmp_mouse;

BITMAP *CURSOR_01; /*光标*/

BITMAP *map001;

BITMAP *alert_bmp;

BITMAP *LEI_DA_shadow;

BITMAP *COVER; /*封面*/
BITMAP *COVER2; /*封底*/

BITMAP *COVER_YUAN;

BITMAP *JLS_BMP; /*降落伞*/

BITMAP *BOMB_ALERT;
BITMAP *BOMB_ALERT2;

BITMAP *PLANE_BMP;
BITMAP *PLANE_shadow;

BITMAP *GoodsBox; /*箱子*/

BITMAP *image_01;  /*用做封面过度*/

BITMAP *bmp_score; /*数字*/

BITMAP *button_bmp;
BITMAP *earth_map_bmp;
BITMAP *failed_bmp;
BITMAP *succeed_bmp;

PALLETE pallete;   /*贴图文件的调色板*/

 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/


/*声音*/

SAMPLE *BAO_SOUND_04;
SAMPLE *BAO_SOUND_05;


SAMPLE *_30mm_fire;
SAMPLE *gun_fire;
SAMPLE *tank_fire;

SAMPLE *YiHa;
SAMPLE *Wheee;

SAMPLE *yes_sir_sound_02;

SAMPLE *eat_sound;

SAMPLE *start_music;
SAMPLE *start_sound;



SAMPLE *unit_ready;
SAMPLE *unit_lost;


SAMPLE *yes_sir_sound;
SAMPLE *ok_sound;
SAMPLE *yeah_sound;
SAMPLE *move_out_sound;
SAMPLE *roger_sound;

SAMPLE *A_BOMB_sound;

SAMPLE *reinfor_sound;

SAMPLE *alert01_sound;
SAMPLE *alert02_sound;

SAMPLE *bomb_attack_sound;


SAMPLE *gameover_sound;

SAMPLE *win_sound;
SAMPLE *failed_sound;

SAMPLE *win_sound2;
SAMPLE *failed_sound2;


int pan = 128; /*左右声道 (pan) 位置*/
int pitch = 1000; /*采样声音时的频率*/


 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

int GAME_SPEED;

int GAME_MAX_TIME_M=1;/*游戏总时间*/

int display_NPC_HP;

int display_LEI_DA=1;


int display_mode; /*显示模式*/

 int MAP_X0=0;  /*地图坐标*/
 int MAP_Y0=0;


 int MAP0[30][30]; /*Z 障碍地图*/
 int MAP1[30][30]; /*B 背景地图*/


 int MAP_A_MAX=30; /*地图AB最大格子数*/
 int MAP_B_MAX=30;


 int display_math_player=0;


 int A_BOMB_LIVE=0;
 int A_BOMB_LIGHT_COLOR=225;





 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/



main()
{

 int END=0;


 int n,i,j,k,cc,pp;  /*临时的 无意义*/
 float ii,jj;       /*临时的 无意义*/
 int ZA;

 int mb=0;  /*鼠标键按过 判断抬起*/

 int MAX_Damage,MIN_Damage; /*最大最小伤害*/

 /*struct time t;   系统时间*/
 int R;           /*由当前系统时间产生真正的随机数种子*/



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -