| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1264 人关注过本帖
标题:c语言小游戏,请教大神!
取消只看楼主 加入收藏
C语小菜
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2011-12-29
收藏
 问题点数:0 回复次数:0 
c语言小游戏,请教大神!
#include "Conio.h"
#include "graphics.h"
#include "stdlib.h"
#include "time.h"
#include "bios.h"
#define closegr closegraph
#define VK_LEFT  0x4b00
#define VK_RIGHT 0x4d00
#define VK_DOWN  0x5000
#define VK_UP    0x4800
#define VK_ESC   0x011b


char duo64K[]={
/* 以下是 '躲' 的 64点阵楷体_GB2312 字模,512 byte */
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x70,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x38,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x3C,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x78,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x70,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x60,0x00,0x00,0x0E,0x00,0x00,
  0x00,0x00,0xE0,0x00,0x00,0x3F,0x00,0x00,
  0x00,0x00,0xC0,0x00,0x7F,0xFF,0x80,0x00,
  0x00,0x00,0x80,0x00,0x78,0x1E,0x00,0x00,
  0x00,0x01,0x00,0x00,0x70,0x0C,0x00,0x00,
  0x00,0x00,0x07,0x00,0x30,0x0C,0x00,0x00,
  0x00,0x02,0x3F,0x80,0x30,0x0C,0x00,0x00,
  0x00,0x7F,0x03,0xC0,0x30,0x0C,0x00,0x00,
  0x00,0x30,0x03,0x80,0x30,0x0C,0x00,0x00,
  0x00,0x30,0x03,0x80,0x30,0x0C,0x00,0x00,
  0x00,0x30,0x03,0x80,0x30,0x08,0x00,0x00,
  0x00,0x30,0x03,0x80,0x30,0x08,0x00,0x00,
  0x00,0x30,0x03,0x80,0x60,0x0C,0x00,0x00,
  0x00,0x33,0xC3,0x00,0x60,0x0C,0x00,0x00,
  0x00,0x3E,0x03,0x00,0x60,0x0E,0x08,0x00,
  0x00,0x30,0x03,0x00,0xC0,0x0F,0xFC,0x00,
  0x00,0x10,0x03,0x00,0xC0,0x07,0xFC,0x00,
  0x00,0x10,0x03,0x01,0x80,0x00,0xC0,0x00,
  0x00,0x10,0x03,0x01,0x03,0x00,0x00,0x00,
  0x00,0x11,0xC3,0x00,0x03,0x80,0x00,0x00,
  0x00,0x1F,0x83,0x00,0x01,0x80,0x00,0x00,
  0x00,0x10,0x03,0x00,0x01,0x80,0x00,0x00,
  0x00,0x10,0x03,0x00,0x01,0x80,0x00,0x00,
  0x00,0x10,0x03,0x00,0x01,0x83,0xFF,0x80,
  0x00,0x10,0x03,0x00,0x01,0xFF,0xFF,0xC0,
  0x00,0x10,0x03,0x00,0x0F,0xC0,0x00,0x00,
  0x00,0x10,0x3F,0x03,0xFB,0x80,0x00,0x00,
  0x00,0x13,0xFB,0x3F,0x03,0xC0,0x00,0x00,
  0x00,0x7F,0xF3,0x00,0x07,0xA0,0x00,0x00,
  0x4F,0xF8,0x63,0x00,0x05,0x90,0x00,0x00,
  0x7F,0xC0,0xE3,0x00,0x0D,0x88,0x00,0x00,
  0x1E,0x01,0xC3,0x00,0x09,0x86,0x00,0x00,
  0x00,0x01,0x83,0x00,0x19,0x83,0x00,0x00,
  0x00,0x03,0x03,0x00,0x31,0x83,0x80,0x00,
  0x00,0x07,0x03,0x00,0x31,0x81,0xE0,0x00,
  0x00,0x0E,0x03,0x00,0x61,0x80,0xF0,0x00,
  0x00,0x0C,0x03,0x00,0xC1,0x80,0x7C,0x00,
  0x00,0x18,0x03,0x00,0x81,0x80,0x3F,0x00,
  0x00,0x30,0x03,0x01,0x01,0x80,0x1F,0xC0,
  0x00,0x60,0x03,0x02,0x01,0x80,0x0F,0xF0,
  0x00,0xC0,0x03,0x04,0x01,0x80,0x07,0xFC,
  0x01,0x00,0x03,0x00,0x01,0x80,0x03,0xFC,
  0x02,0x00,0x03,0x00,0x01,0x80,0x00,0x00,
  0x08,0x00,0x07,0x00,0x01,0x80,0x00,0x00,
  0x00,0x00,0x87,0x00,0x01,0x80,0x00,0x00,
  0x00,0x00,0x7F,0x00,0x01,0x80,0x00,0x00,
  0x00,0x00,0x3E,0x00,0x01,0x80,0x00,0x00,
  0x00,0x00,0x1E,0x00,0x01,0x80,0x00,0x00,
  0x00,0x00,0x0E,0x00,0x01,0x80,0x00,0x00,
  0x00,0x00,0x0C,0x00,0x01,0x80,0x00,0x00,
  0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};

char fei64K[]={
/* 以下是 '飞' 的 64点阵楷体_GB2312 字模,512 byte */
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,
  0x00,0x00,0x00,0x01,0xE0,0x00,0x00,0x00,
  0x00,0x00,0x00,0x07,0xF0,0x00,0x00,0x00,
  0x00,0x00,0x00,0x3F,0xF0,0x00,0x00,0x00,
  0x00,0x00,0x01,0xF9,0xE0,0x00,0x00,0x00,
  0x00,0x00,0x1F,0x81,0xE0,0x00,0x00,0x00,
  0x00,0x0F,0xFC,0x01,0xC0,0x00,0x00,0x00,
  0x03,0xFF,0xE0,0x01,0xC0,0x00,0x00,0x00,
  0x01,0xFC,0x00,0x01,0xC0,0x0C,0x00,0x00,
  0x00,0x00,0x00,0x01,0xC0,0x06,0x00,0x00,
  0x00,0x00,0x00,0x01,0x80,0x0F,0x00,0x00,
  0x00,0x00,0x00,0x03,0x80,0x0F,0x80,0x00,
  0x00,0x00,0x00,0x03,0x80,0x1F,0x00,0x00,
  0x00,0x00,0x00,0x03,0x80,0x3E,0x00,0x00,
  0x00,0x00,0x00,0x03,0x80,0x78,0x00,0x00,
  0x00,0x00,0x00,0x03,0x80,0xE0,0x00,0x00,
  0x00,0x00,0x00,0x03,0x03,0x80,0x00,0x00,
  0x00,0x00,0x00,0x03,0x06,0x00,0x00,0x00,
  0x00,0x00,0x00,0x03,0x18,0x00,0x00,0x00,
  0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,
  0x00,0x00,0x00,0x03,0xE0,0x00,0x00,0x00,
  0x00,0x00,0x00,0x03,0x3C,0x00,0x00,0x00,
  0x00,0x00,0x00,0x03,0x0F,0x80,0x00,0x00,
  0x00,0x00,0x00,0x03,0x07,0xE0,0x00,0x00,
  0x00,0x00,0x00,0x03,0x01,0xF0,0x00,0x00,
  0x00,0x00,0x00,0x03,0x00,0xFC,0x00,0x00,
  0x00,0x00,0x00,0x03,0x00,0x3E,0x00,0x00,
  0x00,0x00,0x00,0x03,0x80,0x0E,0x00,0x00,
  0x00,0x00,0x00,0x03,0x80,0x06,0x00,0x00,
  0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,
  0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,
  0x00,0x00,0x00,0x01,0xC0,0x00,0x00,0x00,
  0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,
  0x00,0x00,0x00,0x00,0xE0,0x00,0x00,0x00,
  0x00,0x00,0x00,0x00,0xE0,0x00,0x00,0x00,
  0x00,0x00,0x00,0x00,0x70,0x00,0x04,0x00,
  0x00,0x00,0x00,0x00,0x70,0x00,0x04,0x00,
  0x00,0x00,0x00,0x00,0x38,0x00,0x0C,0x00,
  0x00,0x00,0x00,0x00,0x1C,0x00,0x0C,0x00,
  0x00,0x00,0x00,0x00,0x0E,0x00,0x0C,0x00,
  0x00,0x00,0x00,0x00,0x0F,0x80,0x0C,0x00,
  0x00,0x00,0x00,0x00,0x07,0xC0,0x1C,0x00,
  0x00,0x00,0x00,0x00,0x01,0xF0,0x1C,0x00,
  0x00,0x00,0x00,0x00,0x00,0xFE,0x3C,0x00,
  0x00,0x00,0x00,0x00,0x00,0x7F,0xFC,0x00,
  0x00,0x00,0x00,0x00,0x00,0x1F,0xFC,0x00,
  0x00,0x00,0x00,0x00,0x00,0x07,0xFE,0x00,
  0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x00,
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};

char ji64K[]={
/* 以下是 '机' 的 64点阵楷体_GB2312 字模,512 byte */
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x70,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x78,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x78,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x70,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x70,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x70,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x70,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x70,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x30,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x30,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x30,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x30,0x00,0x00,0x1E,0x00,0x00,
  0x00,0x00,0x30,0x00,0xC1,0xFF,0x00,0x00,
  0x00,0x00,0x30,0x00,0xFF,0xFF,0x00,0x00,
  0x00,0x00,0x30,0x00,0x70,0x1E,0x00,0x00,
  0x00,0x00,0x20,0x60,0x70,0x1C,0x00,0x00,
  0x00,0x00,0x3F,0xF0,0x70,0x1C,0x00,0x00,
  0x00,0x00,0xFF,0xE0,0x70,0x1C,0x00,0x00,
  0x00,0x0F,0xFF,0x00,0x70,0x18,0x00,0x00,
  0x00,0xFF,0xE0,0x00,0x70,0x18,0x00,0x00,
  0x0F,0xF8,0x60,0x00,0x70,0x18,0x00,0x00,
  0x00,0x00,0x60,0x00,0x70,0x18,0x00,0x00,
  0x00,0x00,0xE0,0x00,0x70,0x18,0x00,0x00,
  0x00,0x00,0xE0,0x00,0x60,0x18,0x00,0x00,
  0x00,0x01,0xE0,0x00,0x60,0x30,0x00,0x00,
  0x00,0x01,0xE0,0x00,0x60,0x30,0x00,0x00,
  0x00,0x03,0xE0,0x00,0x60,0x30,0x00,0x00,
  0x00,0x03,0x3F,0x00,0x60,0x30,0x00,0x00,
  0x00,0x07,0x27,0x80,0x60,0x30,0x00,0x00,
  0x00,0x06,0x63,0xC0,0x60,0x30,0x00,0x00,
  0x00,0x0E,0x61,0xC0,0x60,0x30,0x00,0x00,
  0x00,0x1C,0x60,0x40,0xE0,0x30,0x00,0x00,
  0x00,0x18,0x60,0x00,0xC0,0x30,0x00,0x00,
  0x00,0x30,0x60,0x00,0xC0,0x30,0x00,0x10,
  0x00,0x70,0x60,0x00,0xC0,0x30,0x00,0x10,
  0x00,0x60,0x60,0x01,0x80,0x30,0x00,0x10,
  0x00,0xC0,0x60,0x01,0x80,0x30,0x00,0x10,
  0x01,0x80,0x60,0x01,0x80,0x18,0x00,0x30,
  0x03,0x00,0x60,0x03,0x00,0x18,0x00,0x30,
  0x06,0x00,0x60,0x03,0x00,0x1C,0x00,0x38,
  0x04,0x00,0x60,0x06,0x00,0x0E,0x00,0x38,
  0x08,0x00,0x60,0x04,0x00,0x0F,0x00,0x38,
  0x00,0x00,0x60,0x0C,0x00,0x07,0x80,0x7C,
  0x00,0x00,0x60,0x18,0x00,0x03,0xFF,0xFC,
  0x00,0x00,0x60,0x10,0x00,0x01,0xFF,0xFC,
  0x00,0x00,0xE0,0x20,0x00,0x00,0x7F,0xF8,
  0x00,0x00,0xE0,0x40,0x00,0x00,0x07,0x80,
  0x00,0x00,0xE0,0x80,0x00,0x00,0x00,0x00,
  0x00,0x00,0xE0,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0xE0,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x60,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x60,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x60,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x60,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};

    void drawmat(char *mat,int matsize,int x,int y,int color)

{int i,j,k,n;
 n=(matsize-1)/8+1;
 for(j=0;j<matsize;j++)
  for(i=0;i<n;i++)
   for(k=0;k<8;k++)
    if(mat[j*n+i]&(0x80>>k))
     putpixel(x+i*8+k,y+j,color);
}

int x=300,y=460;

struct plane{
    int x;
    int y;
    int c;
    int color;
    int time;
}a[20];

struct bullet{
    int x;
    int y;
    int yes;
}b[40],bb[20];

void drawbullet(int color,int x,int y){
       setcolor(color);
       circle(x,y,2);
  }

void drawplane(int color,int fx,int x,int y){
    setcolor(color);
    switch(fx){
    case 1:
    line(x-8,y,x+8,y);
    line(x,y-2,x,y+8);
    line(x-4,y+8,x+4,y+8);
    break;
    case 2:
    line(x-6,y,x+6,y);
    line(x,y-6,x,y+4);
    line(x-2,y-6,x+2,y-6);
    break;
    }
    }


void initzm(){
    int i;
    for(i=0;i<20;i++){
        a[i].x=rand()%620+10;
        a[i].y=rand()%400*(-1);
        a[i].c=rand()%26;
        a[i].color=rand()%15+1;
        a[i].time=0;
    }
}

void initbullet(){
      int i;
      for(i=0;i<40;i++){
          b[i].x=-50;
          b[i].y=-100;
          b[i].yes=0;
      }
      for(i=0;i<20;i++){
          bb[i].x=-50;
          bb[i].y=-100;
          bb[i].yes=0;
      }
}




void initgr(void)
{
  int gd = DETECT, gm = 0;
  registerbgidriver(EGAVGA_driver);
  initgraph(&gd, &gm, "");
}

int main(void){
    int i,j,key;
    int isgame=1;
    int x=640,x1=640;
    char *c;
    char *tt;
    srand(time(NULL));
    initgr();
    while(isgame){
    drawmat(duo64K,64,140,100,5);
  drawmat(fei64K,64,x,100,0);
  drawmat(ji64K,64,x1,100,0);

  if(x>240){x-=10;}
      if(x==240&&x1>360){x1-=10;}
  drawmat(fei64K,64,x,100,4);
  drawmat(ji64K,64,x1,100,9);
    delay(10000);
    if(x1<=360){

   setcolor(BLACK);
   setfillstyle(SOLID_FILL,BLACK);
     bar(0,0,640,480);
     isgame=0;
     }

   }
    initzm();
    initbullet();

       for(;;){

           drawplane(BLACK,1,x,y);
       for(i=0;i<40;i++){
         if(b[i].yes)
         drawbullet(BLACK,b[i].x,b[i].y);
       }
       for(i=0;i<20;i++){
         if(bb[i].yes)
         drawbullet(BLACK,bb[i].x,bb[i].y);
       }
       for(i=0;i<20;i++){
         drawplane(BLACK,2,a[i].x,a[i].y);
        }
       if(bioskey(1)){
         key=bioskey(0);
         switch(key){
            case VK_LEFT:
                if(x>10)
                x-=10;
            break;
            case VK_RIGHT:
                if(x<630)
                x+=10;
            break;
            case VK_UP:
                y-=10;
            break;
            case VK_DOWN:
                if(y<470)
                y+=10;
            break;

                    }



     }


       for(i=0;i<20;i++){
          a[i].y+=6;
          a[i].time++;
           if(a[i].time%30==0){
              for(j=0;j<40;j++){
                if(b[j].yes==0){
                   b[j].x=a[i].x;
                   b[j].y=a[i].y;
                   b[j].yes=1;
                   break;
                }
            }
        }

        if(a[i].y>480){
        a[i].x=rand()%620+10;
        a[i].y=rand()%400*(-1);
        a[i].c=rand()%26;
        a[i].color=rand()%15+1;
        a[i].time=0;
        }
    }

       for(i=0;i<40;i++){
          if(b[i].yes)
          b[i].y+=20;
          if(b[i].y>490)
          b[i].yes=0;
    }


    for(i=0;i<20;i++){
        drawplane(a[i].color,2,a[i].x,a[i].y);
    }
    for(i=0;i<20;i++){
        if(bb[i].yes)
        drawbullet(YELLOW,bb[i].x,bb[i].y);
     }
    for(i=0;i<40;i++){
        if(b[i].yes)
        drawbullet(5,b[i].x,b[i].y);
     }
     drawplane(YELLOW,1,x,y);
     delay(3000);
    }
 
   

  getch();
  closegr();
  return 0;
}

一个C语言的小游戏,但是死亡的判定和计时不知道写。所以请教下大神

[ 本帖最后由 C语小菜 于 2012-1-2 22:45 编辑 ]
搜索更多相关主题的帖子: 小游戏 c语言 include 
2012-01-02 22:07
快速回复:c语言小游戏,请教大神!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.026426 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved