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

📄 se_game.h

📁 又是一个游戏
💻 H
字号:
void wprint(long x,long y,char *s,int a)
{
    int i;char c[40];
    TextOut(hdcm,x,y,c,i=wsprintf(c,s,a));
}

void printsec()
{
    wprint(0,0, "Airship_Speed=%d",(int)(PLANE_SP*10));
    wprint(0,12,"Airship_Size=%d",PLANE_L);                
    wprint(0,24,"Meteor_Quantity=%d",STAR_NUM);
    wprint(0,36,"Meteor_Max_Speed=%d",(int)(STAR_SMX*10));
    wprint(0,48,"Meteor_Min_Speed=%d",(int)(STAR_SMN*10));
    wprint(0,60,"Meteor_Type=%d",type);
}

void newstar(int i,float *x,float *y,float *xa,float *ya,float min,float max,int s)
{
    if(s)
    {
        switch((int)(rand()*4.0/RAND_MAX))
        {case 1:  x[i]=0.0; 
                  y[i]=rand()*(WIN_Y-1)/RND_MAX;break;
         case 2:  x[i]=WIN_X-7;
                  y[i]=rand()*(WIN_Y-1)/RND_MAX;break;
         case 3:  y[i]=0.0;
                  x[i]=rand()*(WIN_X-1)/RND_MAX;break;
         default: y[i]=WIN_Y-7;
                  x[i]=rand()*(WIN_X-1)/RND_MAX;
        }
    }
    else
    {
        x[i]=rand()*(WIN_X-6.0)/RND_MAX;
        y[i]=rand()*(WIN_Y-6.0)/RND_MAX;
    }
    xa[i]=(rand()*(max-min))/RND_MAX+min;
    ya[i]=(rand()*(max-min))/RND_MAX+min;
    if (rand()>RND_MAX/2) xa[i]=-xa[i];
    if (rand()>RND_MAX/2) ya[i]=-ya[i];
}

void initgame()
{
    int i;
    srand((unsigned)time(NULL));
    hdc=GetDC(hwnd);
    hdcm=CreateCompatibleDC(hdc);                  
    hbm =CreateCompatibleBitmap(hdc,WIN_X,WIN_Y);  
    SelectObject(hdcm,hbm);
    hb =GetStockObject(BLACK_BRUSH);
    SetBkMode(hdcm,TRANSPARENT);
    SetBkColor(hdcm,RGB(0,0,0));
    rect.left=rect.top=0;
    rect.right=WIN_X; rect.bottom=WIN_Y;
    for(i=0;i<12;i++) mk[i]-=3;
    hfc=CreateFont(20,10,0,0,400,0,0,0,
                   DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,
                   CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
                   DEFAULT_PITCH, "Comic Sans MS"      );
    hft=CreateFont(40,20,0,0,400,0,0,0,
                   DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,
                   CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
                   DEFAULT_PITCH, "Comic Sans MS"      );
    hfs=GetStockObject(SYSTEM_FONT);
    FillRect(hdcm,&rect,hb);
    playgame=0; show=0; type=0; ccc='Q';
}

void newgame()
{
    int i;
    hfp=CreateFont(PLANE_L,PLANE_L,900,0,400,0,0,0,
                   SYMBOL_CHARSET, OUT_DEFAULT_PRECIS,
                   CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
                   DEFAULT_PITCH, "Wingdings"          );
    FillRect(hdcm,&rect,hb);
    SelectObject(hdcm,hfp);
    x=(WIN_X-PLANE_L)/2; y=WIN_Y/2; xa=0; ya=0;
    for(i=0;i<BKS_NUM;i++) 
        newstar(i,bx,by,bxa,bya,BKS_SMX,BKS_SMN,0);
    for(i=0;i<STAR_NUM;i++)
        newstar(i,gx,gy,gxa,gya,STAR_SMX,STAR_SMN,1);
    playgame=1; hit=0;
    timeold=time(NULL);
}

void endgame()
{int i;
 char timestr[20]; 
 i=wsprintf(timestr,"Time:%3ld sec",time(NULL)-timeold);
 SelectObject(hdcm,hfc);
 SetTextColor(hdcm,RGB(255,32,32));
 TextOut(hdcm,(WIN_X-140)/2,140,timestr,i);
 SelectObject(hdcm,hfp);
 DeleteObject(hfp);
 playgame=0;
}

void drawgame()
{
    int i;long col;
    FillRect(hdcm,&rect,hb);
    for(i=0;i<BKS_NUM;i++)
    {
          SetPixel(hdcm,bx[i],by[i],BKS_C);
          bx[i]+=bxa[i]; by[i]+=bya[i];
          if (bx[i]<0||bx[i]>WIN_X-6||by[i]<0||by[i]>WIN_Y-6) 
              newstar(i,bx,by,bxa,bya,BKS_SMX,BKS_SMN,1);
    }
    SetTextColor(hdcm,PLANE_C);
    TextOut(hdcm,x,y,&ccc,1);
    x+=xa;y+=ya;
    if (x<-4) x=-4;
    if (x>WIN_X-PLANE_L) x=WIN_X-PLANE_L;
    if (y<PLANE_L) y=PLANE_L;
    if (y>WIN_Y-4) y=WIN_Y-4;
    for(i=0;i<STAR_NUM;i++)
    {
          if(GetPixel(hdcm,gx[i],gy[i])==PLANE_C)
          {         col=RGB(255,0,0);hit=1; }
          else      col=STAR_C;
          SetPixel(hdcm,gx[i],  gy[i],col);
          SetPixel(hdcm,gx[i]-1,gy[i],col);
          SetPixel(hdcm,gx[i]+1,gy[i],col);
          SetPixel(hdcm,gx[i],gy[i]-1,col);
          SetPixel(hdcm,gx[i],gy[i]+1,col);
          gx[i]+=gxa[i]; gy[i]+=gya[i];
          if (gx[i]<0||gx[i]>WIN_X-6) 
              if (type)
                  newstar(i,gx,gy,gxa,gya,STAR_SMX,STAR_SMN,1);
              else gxa[i]=-gxa[i];
          if (gy[i]<0||gy[i]>WIN_Y-6) 
              if (type)
                  newstar(i,gx,gy,gxa,gya,STAR_SMX,STAR_SMN,1);
              else gya[i]=-gya[i];
    }          
    BitBlt(hdc,0,0,WIN_X,WIN_Y,hdcm,0,0,SRCCOPY);
    if(hit) endgame();
    sleep(SLEEP);
}

void exitgame()
{
 DeleteObject(hfc);
 DeleteObject(hft);
 DeleteObject(hfs);
 DeleteObject(hb);
 DeleteObject(hbm);
 ReleaseDC(hwnd,hdcm);
 ReleaseDC(hwnd,hdc);
}

⌨️ 快捷键说明

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