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

📄 bombersprites.c

📁 一个炸弹人游戏的源代码(win32 application)
💻 C
字号:
//Load the sprites
void LoadSprites ()
{
  FILE          *SSFFile;
  unsigned char RGBPal [256][3];
  int           DAC;

  //Assign memory to sprite buffer
  SpriteBuf = (char *)malloc (64000);

  //Load graphics data from file
  SSFFile = fopen ("BOMBER0.SSF", "rb");
  fread (SpriteBuf, 7, 1, SSFFile);
  fread (SpriteBuf, 320, 200, SSFFile);
  fread (RGBPal, 3, 256, SSFFile);
  fclose (SSFFile);

  //Convert palette
  for (DAC = 0; DAC < 256; DAC++) {
    RGBPal [DAC][0] <<= 2;
    RGBPal [DAC][1] <<= 2;
    RGBPal [DAC][2] <<= 2;
    Palette [DAC] = (RGBPal [DAC][0]) +
                    (RGBPal [DAC][1] << 8) +
                    (RGBPal [DAC][2] << 16);
  }
}

//Load the sprites
void LoadBlocks ()
{
  FILE          *SSFFile;
  unsigned char Pixel;
  unsigned char RGBPal [256][3];
  int           DAC, o1, o2;
  char          *RawBuf;

  //Assign memory to sprite buffer
  RawBuf = (char *)malloc (64000);
  BlocksBuf = (char *)malloc (192000);

  //Load graphics data from file
  SSFFile = fopen ("BOMBER1.SSF", "rb");
  fread (RawBuf, 7, 1, SSFFile);
  fread (RawBuf, 320, 200, SSFFile);
  fread (RGBPal, 3, 256, SSFFile);
  fclose (SSFFile);

  //Convert palette
  for (DAC = 0; DAC < 256; DAC++) {
    RGBPal [DAC][0] <<= 2;
    RGBPal [DAC][1] <<= 2;
    RGBPal [DAC][2] <<= 2;
    Palette [DAC] = (RGBPal [DAC][0]) +
                    (RGBPal [DAC][1] << 8) +
                    (RGBPal [DAC][2] << 16);
  }

  //Save as 24bit data
  o2 = 0;
  for (o1 = 0; o1 < 64000; o1++) {
    Pixel = RawBuf [o1];
    BlocksBuf [o2++] = RGBPal [Pixel][2];
    BlocksBuf [o2++] = RGBPal [Pixel][1];
    BlocksBuf [o2++] = RGBPal [Pixel][0];
  }
}

//This reads a pixel from the sprite buffer
unsigned char ReadPixel (int x, int y)
{
  return SpriteBuf [(y << 8) + (y << 6) + x];
}

void Blit (int x, int y, int x1, int y1, int w, int h)
{
  int   yt;

  x *= 3;
  x1 *= 3;
  w *= 3;
  //Do blits
  for (yt = 0; yt < h; yt++)
    memcpy ((char *)TargetData + 221136 - (y + yt) * 816 + x,
            (char *)BlocksBuf + (y1 + yt) * 960 + x1,
            w);

}

//This draws a sprite onto the device context
void DrawBlock (int x, int y, int x1, int y1)
{
  int   yt;

  //Convert coordinates
  x *= 48;
  y <<= 4;
  x1 *= 48;
  y1 <<= 4;

  //Draw each pixel
  for (yt = 0; yt < 16; yt++)
    memcpy ((char *)TargetData + 221136 - (y + yt) * 816 + x,
            (char *)BlocksBuf + (y1 + yt) * 960 + x1,
            48);
}

//This draws a transparent sprite onto the device context
void DrawTSprite (int x, int y, int x1, int y1, int xs, int ys)
{
  int           xt, yt;
  unsigned char c;

  for (xt = 0; xt < xs; xt++) for (yt = 0; yt < ys; yt++) {
    c = ReadPixel (x1 + xt, y1 + yt);
    if (c) SetPixel (MainDC, x + xt, y + yt, Palette [c]);
  }
}

⌨️ 快捷键说明

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