📄 rpg.h
字号:
RGB_color color[256];
int sx=190;
int my_things[5]={0,0,0,0,0};
int pause_game=0;
int pause_bar=0;
void Fade_Lights(void)
{
int pal_reg,index;
RGB_color color;
for(index=0;index<30;index++)
{
for(pal_reg=1;pal_reg<255;pal_reg++)
{
Get_Palette_Register(pal_reg,(RGB_color_ptr)&color);
if(color.red>5)color.red-=3;
else
color.red=0;
if(color.green>5)color.green-=3;
else
color.green=0;
if(color.blue>5)color.blue-=3;
else
color.blue=0;
Set_Palette_Register(pal_reg,(RGB_color_ptr)&color);
}
Delay(2);
}
}
char *date(void)
{
time_t t;
t = time(NULL);
return (ctime(&t));
}
void PCX_Grab_Bitmap_Screen(pcx_picture_ptr image,
sprite_ptr sprite,
int sprite_frame,
int grab_x, int grab_y)
{
// this function will grap a bitmap from the pcx frame buffer. it uses the
// convention that the 320x200 pixel matrix is sub divided into a smaller
// matrix of 12x8 adjacent squares each being a 24x24 pixel bitmap
// the caller sends the pcx picture along with the sprite to save the image
// into and the frame of the sprite. finally, the position of the bitmap
// that should be grabbed is sent
int x_off,y_off, x,y, index;
char far *sprite_data;
// first allocate the memory for the sprite in the sprite structure
sprite->frames[sprite_frame] = (char far *)malloc(SPRITE_WIDTH * SPRITE_HEIGHT);
// create an alias to the sprite frame for ease of access
sprite_data = sprite->frames[sprite_frame];
// now load the sprite data into the sprite frame array from the pcx picture
// we need to find which bitmap to scan, remember the pcx picture is really a
// 12x8 matrix of bitmaps where each bitmap is 24x24 pixels. note:0,0 is upper
// left bitmap and 11,7 is the lower right bitmap.
x_off = (SPRITE_WIDTH) * grab_x;
y_off = (SPRITE_HEIGHT) * grab_y ;
// compute starting y address
y_off = y_off * 320;
for (y=0; y<SPRITE_HEIGHT; y++)
{
for (x=0; x<SPRITE_WIDTH; x++)
{
// get the next byte of current row and place into next position in
// sprite frame data buffer
sprite_data[y*SPRITE_WIDTH + x] = video_buffer[y_off + x_off + x];
} // end for x
// move to next line of picture buffer
y_off+=320;
} // end for y
// increment number of frames
sprite->num_frames++;
// done!, let's bail!
} // end PCX_Grap_Bitmap
//////////////////////////////////////////////////////////////////////////////
void PCX_Load_Screen_Size(char *filename, pcx_picture_ptr image,int enable_palette,int height,int width,int x_begin,int y_begin)
{
// this function loads a pcx file into a picture structure, the actual image
// data for the pcx file is decompressed and expanded into a secondary buffer
// within the picture structure, the separate images can be grabbed from this
// buffer later. also the header and palette are loaded
FILE *fp;
int num_bytes,index,x,y;
unsigned int count;
unsigned char data;
char far *temp_buffer;
// open the file
fp = fopen(filename,"rb");
// load the header
temp_buffer = (char far *)image;
for (index=0; index<128; index++)
{
temp_buffer[index] = getc(fp);
} // end for index
// load the data and decompress into buffer
count=0;
while(count<=(unsigned int)width*height)
{
// get the first piece of data
data = getc(fp);
// is this a rle?
if (data>=192 && data<=255)
{
// how many bytes in run?
num_bytes = data-192;
// get the actual data for the run
data = getc(fp);
// replicate data in buffer num_bytes times
while(num_bytes-->0)
{
// image->buffer[count++] = data;
y=y_begin+count/width;
x=x_begin+count%width;
video_buffer[x+y*SCREEN_WIDTH]=data;
count++;
} // end while
} // end if rle
else
{
// actual data, just copy it into buffer at next location
//image->buffer[count++] = data;
y=y_begin+count/width;
x=x_begin+count%width;
video_buffer[x+y*SCREEN_WIDTH]=data;
count++;
} // end else not rle
} // end while
// move to end of file then back up 768 bytes i.e. to begining of palette
fseek(fp,-768L,SEEK_END);
// load the pallete into the palette
for (index=0; index<256; index++)
{
// get the red component
image->palette[index].red = (getc(fp) >> 2);
// get the green component
image->palette[index].green = (getc(fp) >> 2);
// get the blue component
image->palette[index].blue = (getc(fp) >> 2);
} // end for index
fclose(fp);
// change the palette to newly loaded palette if commanded to do so
if (enable_palette)
{
for (index=0; index<256; index++)
{
Set_Palette_Register(index,(RGB_color_ptr)&image->palette[index]);
} // end for index
} // end if change palette
} // end PCX_Load
void PCX_Grab_Bitmap_Size_Screen(pcx_picture_ptr image,
sprite_ptr sprite,
int sprite_frame,
int grab_x, int grab_y,int height,int width)
{
// this function will grap a bitmap from the pcx frame buffer. it uses the
// convention that the 320x200 pixel matrix is sub divided into a smaller
// matrix of 12x8 adjacent squares each being a 24x24 pixel bitmap
// the caller sends the pcx picture along with the sprite to save the image
// into and the frame of the sprite. finally, the position of the bitmap
// that should be grabbed is sent
int x_off,y_off, x,y, index;
char far *sprite_data;
// first allocate the memory for the sprite in the sprite structure
sprite->frames[sprite_frame] = (char far *)malloc(width * height);
// create an alias to the sprite frame for ease of access
sprite_data = sprite->frames[sprite_frame];
// now load the sprite data into the sprite frame array from the pcx picture
// we need to find which bitmap to scan, remember the pcx picture is really a
// 12x8 matrix of bitmaps where each bitmap is 24x24 pixels. note:0,0 is upper
// left bitmap and 11,7 is the lower right bitmap.
x_off = (width) * grab_x;
y_off = (height) * grab_y ;
// compute starting y address
y_off = y_off * 320;
for (y=0; y<height; y++)
{
for (x=0; x<width; x++)
{
// get the next byte of current row and place into next position in
// sprite frame data buffer
sprite_data[y*width + x] = video_buffer[y_off + x_off + x];
} // end for x
// move to next line of picture buffer
y_off+=320;
} // end for y
// increment number of frames
sprite->num_frames++;
// done!, let's bail!
} // end PCX_Grap_Bitmap
//////////////////////////////////////////////////////////////////////////////
void Sprite_Delete_Size(sprite_ptr sprite,int frame)
{
// this function deletes all the memory associated with a sprire
int index;
farfree(sprite->background);
// now de-allocate all the animation frames
for (index=0; index<frame; index++)
farfree(sprite->frames[index]);
} // end Sprite_Delete
void Sprite_Init_Size(sprite_ptr sprite,int x,int y,int ac,int as,int mc,int ms,int height,int width,int frame)
{
// this function initializes a sprite with the sent data
int index;
sprite->x = x;
sprite->y = y;
sprite->x_old = x;
sprite->y_old = y;
sprite->width = width;
sprite->height = height;
sprite->anim_clock = ac;
sprite->anim_speed = as;
sprite->motion_clock = mc;
sprite->motion_speed = ms;
sprite->curr_frame = 0;
sprite->state = SPRITE_DEAD;
sprite->num_frames = 0;
sprite->background = (char far *)malloc(width * height+1);
// set all bitmap pointers to null
for (index=0; index<frame; index++)
sprite->frames[index] = NULL;
} // end Sprite_Init
void PCX_Load_Screen_Height(char *filename, pcx_picture_ptr image,int enable_palette,int height)
{
// this function loads a pcx file into a picture structure, the actual image
// data for the pcx file is decompressed and expanded into a secondary buffer
// within the picture structure, the separate images can be grabbed from this
// buffer later. also the header and palette are loaded
FILE *fp;
int num_bytes,index;
unsigned int count;
unsigned char data;
char far *temp_buffer;
// open the file
fp = fopen(filename,"rb");
// load the header
temp_buffer = (char far *)image;
for (index=0; index<128; index++)
{
temp_buffer[index] = getc(fp);
} // end for index
// load the data and decompress into buffer
count=0;
while(count<=(unsigned int)SCREEN_WIDTH1 * height)
{
// get the first piece of data
data = getc(fp);
// is this a rle?
if (data>=192 && data<=255)
{
// how many bytes in run?
num_bytes = data-192;
// get the actual data for the run
data = getc(fp);
// replicate data in buffer num_bytes times
while(num_bytes-->0)
{
// image->buffer[count++] = data;
video_buffer[count++]=data;
} // end while
} // end if rle
else
{
// actual data, just copy it into buffer at next location
//image->buffer[count++] = data;
video_buffer[count++]=data;
} // end else not rle
} // end while
// move to end of file then back up 768 bytes i.e. to begining of palette
fseek(fp,-768L,SEEK_END);
// load the pallete into the palette
for (index=0; index<256; index++)
{
// get the red component
image->palette[index].red = (getc(fp) >> 2);
// get the green component
image->palette[index].green = (getc(fp) >> 2);
// get the blue component
image->palette[index].blue = (getc(fp) >> 2);
} // end for index
fclose(fp);
// change the palette to newly loaded palette if commanded to do so
if (enable_palette)
{
for (index=0; index<256; index++)
{
Set_Palette_Register(index,(RGB_color_ptr)&image->palette[index]);
} // end for index
} // end if change palette
} // end PCX_Load
void Draw_Sprite_Size(sprite_ptr sprite,int height,int width)
{
// this function draws a sprite on the screen row by row very quickly
// note the use of shifting to implement multplication
char far *work_sprite;
int work_offset=0,offset,x,y;
//unsigned char data;
// alias a pointer to sprite for ease of access
work_sprite = sprite->frames[sprite->curr_frame];
// compute offset of sprite in video buffer
offset = ((sprite->y) << 8) + ((sprite->y) << 6) + sprite->x;
for (y=0; y<height; y++)
{
// copy the next row into the screen buffer using memcpy for speed
for (x=0; x<width; x++)
{
// test for transparent pixel i.e. 0, if not transparent then draw
if(work_sprite[work_offset+x])
//data==(unsigned char)work_sprite[work_offset+x];
// if(data)
// video_buffer[offset+x] =data;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -