📄 sprite.h
字号:
BITMAP *create_rle_sprite(char *file)
{FILE *fp;PCXHEAD pcx;
if((fp=fopen(file,"rb"))==NULL){
sprintf(grp_err,"Can't open Pcx file %s",file);
return FALSE;}
BITMAP *bitmap;int len;
bitmap=(BITMAP*)malloc(sizeof(BITMAP));
if(!bitmap)return FALSE;
fread(&pcx,1,sizeof(PCXHEAD),fp);
bitmap->h=pcx.ymax-pcx.ymin+1;
bitmap->w=pcx.width;
bitmap->line[0]=NULL;
bitmap->MskCol=0;
len=filelength(fp->_handle);
bitmap->dat=new unsigned char [len-128];
if(!bitmap->dat){free(bitmap);return FALSE;}
fseek(fp,128L,SEEK_SET);
fread(bitmap->dat,1,len-128,fp);
fclose(fp);
return bitmap;
}
void draw_rle_sprite(BITMAP *source,BITMAP *sprite,int x,int y)
{int x1,y1,total,count,auto_count=0;
unsigned char data;
sprite->MskCol=*(sprite->dat+1);
for(y1=0;y1<sprite->h;y1++)
{total=0;
while(total<sprite->w)
{count=1;
data=*(sprite->dat+auto_count);
auto_count++;
if(0xc0==(0xc0&data))
{count=0x3f&data;
data=*(sprite->dat+auto_count);
auto_count++;
}
if(data!=sprite->MskCol)
for(x1=0;x1<count;x1++)
{
*(*(source->line+y1+y)+x+x1+total)=data;
}
total+=count;
}
}
}
void draw_sprite(BITMAP *source,BITMAP *dest,int x,int y)
{masked_blit(source,dest,dest->x,dest->y,x,y,dest->w,dest->h);}
void draw_sprite_vh_flip(BITMAP *source,BITMAP *dest,int x,int y)
{
register unsigned int offset_d=0,offset_s,source_offset;
register int i,j;
register unsigned char data,*p=dest->dat;
offset_s=x+y*dest->w;
p+=dest->w*(dest->h-1);
source_offset=dest->y*source->w+dest->x;
for(i=0;i<dest->h;i++)
{
for(j=0;j<dest->w;j++)
if((data=*(p-offset_s+j))!=dest->MskCol)
*(source->dat+offset_d+j+source_offset)=data;
offset_d+=source->w;
offset_s+=dest->w;
}
return ;
}
void draw_sprite_v_flip(BITMAP *source,BITMAP *dest,int x,int y)
{
register unsigned int offset_d=0,offset_s,source_offset;
register int i,j;
register unsigned char data,*p=dest->dat;
offset_s=x+y*dest->w;
p+=dest->w*dest->h;
source_offset=dest->y*source->w+dest->x;
for(i=0;i<dest->h;i++)
{
for(j=0;j<dest->w;j++)
if((data=*(p-offset_s-j))!=dest->MskCol)
*(source->dat+offset_d+j+source_offset)=data;
offset_d+=source->w;
offset_s+=dest->w;
}
}
void draw_sprite_h_flip(BITMAP *source,BITMAP *dest,int x,int y)
{
register unsigned int offset_d=0,offset_s,source_offset;
register int i,j;
register unsigned char data,*p=dest->dat;
offset_s=x+(y+1)*dest->w;
source_offset=dest->y*source->w+dest->x;
for(i=0;i<dest->h;i++)
{
for(j=dest->w;j>0;j--)
if((data=*(p+offset_s-j))!=dest->MskCol)
*(source->dat+offset_d+j+source_offset)=data;
offset_d+=source->w;
offset_s+=dest->w;
}
return ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -