Human.h
上传用户:kf1822
上传日期:2021-06-02
资源大小:2156k
文件大小:6k
源码类别:

游戏

开发平台:

Java

  1. /* 由于当前分辨率为640X350 因此画圆时Y坐标要参照比例 proportion*/
  2. #include <graphics.h>
  3. #include "AllBoard.h"
  4. typedef struct Human
  5. {
  6.     int x;
  7.     int y;
  8.     int life;     /* 生命 */
  9.     int diretion; /* 运动方向 0-向右 1-向左 */
  10.     int style    ;/* 状态标记 2-跳板上 1-刺上、0-平板上*/
  11.     int color[4];
  12.     int speed;    /* Human移动速度 */
  13.     int temp;     /* 标记量 标记Human当前在空中还是在板子上,
  14.                     以确认下落还是跟随板子上升 */
  15.     int isCarry;  /* 标记Human是否被板子承载着 */
  16.     int vx;
  17.     int vy;
  18.     int Dspeed;    /* Human下落速度 */
  19.     int time;     /* 用于触碰爆炸板子记时 */
  20. }Human;
  21. int liveStyle=0;
  22. int liveStyleE=0;  /* 弹板用的恢复生命标记 */
  23. void initHuman(Human *h,Board b)/* 初始化Human */
  24. {
  25.     h->x=b.x+45;           /* 让Human在游戏开始时处在第一块板子的中间出现 */
  26.     h->y=b.y-7;
  27.     h->vx=0;
  28.     h->life=10;
  29.     h->diretion=0;
  30.     h->speed=4;
  31.     h->style=0;
  32.     h->color[0]=15;
  33.     h->color[1]=5;
  34.     h->color[2]=5;
  35.     h->color[3]=5;
  36.     h->vy=-7;
  37.     h->time=0;
  38. }
  39. void drawHuman(Human h)/* 画Human */
  40. {
  41.     setcolor(h.color[0]);
  42.     setfillstyle(1,h.color[0]);    /*  画出来的Human的样子 */
  43.     fillellipse(h.x,h.y-4,2,2);        /*      O      */
  44.     setcolor(h.color[1]);
  45.     setfillstyle(1,h.color[1]);        /*             */
  46.     fillellipse(h.x+5,h.y,2,2);        /*  0       O  */
  47.     setcolor(h.color[2]);
  48.     setfillstyle(1,h.color[2]);        /*             */
  49.     fillellipse(h.x,h.y+4,2,2);        /*      0      */
  50.     setcolor(h.color[3]);
  51.     setfillstyle(1,h.color[3]);        /*             */
  52.     fillellipse(h.x-5,h.y,2,2);
  53. }
  54. void drawHuman1(Human h)
  55. {
  56.     h.y=h.y+1;
  57.     setcolor(h.color[0]);
  58.     setfillstyle(1,h.color[0]);    /*  画出来的Human1的样子 */
  59.     fillellipse(h.x+3,h.y-3,2,2);       /*             */
  60.     setcolor(h.color[1]);
  61.     setfillstyle(1,h.color[1]);         /*   0     0   */
  62.     fillellipse(h.x+3,h.y+3,2,2);       /*             */
  63.     setcolor(h.color[2]);
  64.     setfillstyle(1,h.color[2]);         /*   0     0   */
  65.     fillellipse(h.x-3,h.y+3,2,2);       /*             */
  66.     setcolor(h.color[3]);
  67.     setfillstyle(1,h.color[3]);         /*             */
  68.     fillellipse(h.x-3,h.y-3,2,2);    /* 让两个Human交替运动使其产生旋转效果 */
  69. }
  70. void rightHuman(Human *h)/* 右旋转 转换Human虚拟转动 */
  71. {
  72.     int temp;
  73.     temp=h->color[0];
  74.     h->color[0]=h->color[3];
  75.     h->color[3]=h->color[2];
  76.     h->color[2]=h->color[1];
  77.     h->color[1]=temp;
  78. }
  79. void leftHuman(Human *h)/* 左旋转 转换Human虚拟转动 */
  80. {
  81.     int temp;
  82.     temp=h->color[0];
  83.     h->color[0]=h->color[1];
  84.     h->color[1]=h->color[2];
  85.     h->color[2]=h->color[3];
  86.     h->color[3]=temp;
  87. }
  88. void moveHuman(Human *h)
  89. {
  90.     h->x=h->x+h->speed+h->vx;
  91. }
  92. int carryHuman(Human *h,Board b[],int n)  /* 扫描Human是否被承载着 */
  93. {
  94.     int i;
  95.     int j;
  96.     h->isCarry=0;
  97.     for(i=0;i<n;i++)
  98.     {
  99.         if(b[i].temp==4)      /* 如果是刺板则以 */
  100.         {
  101.             if(b[i].isShow==1 && h->x>=b[i].x && h->x<=b[i].x+90 && h->y+6>b[i].y+1 && h->y+6<b[i].y+5)   /* 判断Human的XY坐标是否在某板子的X坐标范围内 */
  102.             {
  103.                 h->isCarry=i+1;
  104.                 i=n;
  105.             }
  106.         }
  107.         else
  108.         {
  109.             if(b[i].isShow==1 && h->x>=b[i].x && h->x<=b[i].x+90 && h->y+6>b[i].y-2 && h->y+6<b[i].y+5)   /* 判断Human的XY坐标是否在某板子的X坐标范围内 */
  110.             {
  111.                 h->isCarry=i+1;                  /* 让h->isCarry不等于0 便与以后做判断*/
  112.                 i=n;
  113.             }
  114.         }
  115.     }
  116.     if(h->isCarry!=0)
  117.     {
  118.         switch(b[h->isCarry-1].temp)
  119.         {
  120.             case 0:
  121.                 h->vy=-1;
  122.                 h->y=b[h->isCarry-1].y-7;
  123.                 liveStyleE=0;
  124.                 if(liveStyle==0)
  125.                 {
  126.                     liveStyle=1;
  127.                     if(h->life<10)
  128.                         h->life++;
  129.                 }
  130.             break;
  131.             case 1:
  132.                 h->vy=-1;
  133.                 h->y=b[h->isCarry-1].y-7;
  134.                 if(b[h->isCarry-1].direct==1)
  135.                     h->vx=2;
  136.                 else
  137.                     h->vx=-2;
  138.                 h->time=0;
  139.                 liveStyleE=0;
  140.                 if(liveStyle==0)
  141.                 {
  142.                     liveStyle=1;
  143.                     if(h->life<10)
  144.                         h->life++;
  145.                 }
  146.             break;
  147.             case 2:
  148.                 b[h->isCarry-1].temp=5;
  149.                 h->vy=-28;
  150.                 h->time=0;
  151.                 if(liveStyleE==0)
  152.                 {
  153.                     liveStyleE=1;
  154.                     if(h->life<10)
  155.                         h->life++;
  156.                 }
  157.             break;
  158.             case 3:
  159.                 h->vy=-1;
  160.                 h->y=b[h->isCarry-1].y-7;
  161.                 h->time++;          /* 引发爆炸板子记时 */
  162.                 liveStyleE=0;
  163.                 if(liveStyle==0)
  164.                 {
  165.                     liveStyle=1;
  166.                     if(h->life<10)
  167.                         h->life++;
  168.                 }
  169.             break;
  170.             case 4:
  171.                 h->vy=-1;
  172.                 h->y=b[h->isCarry-1].y-3;
  173.                 h->time=0;
  174.                 liveStyleE=0;
  175.                 if(liveStyle==0)
  176.                 {
  177.                     h->life=h->life-3;
  178.                     liveStyle=1;
  179.                 }
  180.             break;
  181.         }
  182.     }
  183.     else
  184.     {
  185.         liveStyle=0;
  186.         h->time=0;
  187.         h->vx=0;
  188.         h->vy=5;
  189.     }
  190. }