level 11
下面是部分源码:
(处理显示数字的)
要求首先要加载“TextNumber2_1.jpg”和“TextNumber2_2.jpg”两个字体图片文件(位于压缩文件Fonts文件夹下)
#define B /* Billion*/ 1000000000
//写入0-9,以及"+"和"-"的图片数据
IMAGE Number[2][13];
int Bit[11];
int a,b,c;
//读取数字字体文件(小字 32×32)
void LoadNumbers()
{
loadimage( &Number[0][12],_T("Fonts\\TextNumber2_2.jpg"));
loadimage( &Number[1][12],_T("Fonts\\TextNumber2_1.jpg"));
SetWorkingImage(&Number[0][12]);
for(int count=0;count<12;count++)
getimage(&Number[0][count],32*count,0,32,32);
SetWorkingImage(&Number[1][12]);
for(int count=0;count<12;count++)
getimage(&Number[1][count],32*count,0,32,32);
SetWorkingImage();
}
//设定显示字体颜色
void SetNumColor(int COLOR)
{
DWORD* P;
for(int i=0;i<12;i++)
{
//获取指定图片指针
P=GetImageBuffer(&Number[1][i]);
for(int m=0;m<32*32;m++)
{
//选择字体图片中特定区域上色
if(P[m]!=0&&P[m]!=0x010101)
P[m]=COLOR;
}
}
}
//判断这是几位数
int BitsCount(int Num)
{
int C=1;
for(int i=1;i<=B;i*=10)
if(Num<B)
{
if(Num/i==0)
{
if(Num==0)
return C;
else
{
return C-1;
break;
}
}
else
C++;
}
else
return 10;
}
//对数字进行位数分解
void BitDepartment(int Num,int BitC)
{
int BitsNum=BitC;
for(int i=1;i<=10;i++)
{
if(i<=BitC)
{
if(i==1&&Num>=B)
Bit[i]=Num/B;
else
Bit[i]=(Num%((int)(pow(10,(float)BitsNum))))/(pow(10,BitsNum-1.0));
BitsNum--;
}
else
break;
}
}
void ScoreNum(int Num,int x, int y)
{
//相应位置贴上底图
for(int i=1;i<=10;i++)
{
if(i<=BitsCount(Num))
putimage(x+(22*(i-1)),y,&Number[0][Bit[i]],SRCAND);
else
break;
}
putimage(78,y,&Number[0][11],SRCAND);
//ClearArea(pMem,x-25,y,255,40);
//位数分解需要两个参数: 1. 分数或者欲显示数字绝对值。 2. 该数值位数数目(比如5346为4位数,18920为5位数)
BitDepartment(abs(Num),BitsCount(abs(Num)));
if(Num<0)
{
putimage(78,y,&Number[0][11],SRCAND);
putimage(78,y,&Number[1][11],SRCPAINT);
}
//贴上数字本图
for(int i=1;i<=10;i++)
{
if(i<=BitsCount(Num))
{
putimage(x+(22*(i-1)),y,&Number[0][Bit[i]],SRCAND);
putimage(x+(22*(i-1)),y,&Number[1][Bit[i]],SRCPAINT);
}
else
break;
}
ClearArea(pMem,x-25,y,255,40);
}
#endif
2014年09月24日 05点09分
2
无视那个endif - - ,因为这段代码是写在头文件里的
![[黑线]](/static/emoticons/u9ed1u7ebf.png)
消除方法是点击不放开左键拖动
2014年09月24日 08点09分
level 11
2L使用到的ClearArea() 函数是模糊处理指定区域的内容,代码如下:
PS: 游戏窗体用的600×600 Pix 所以屏幕长宽下面全用的600
void ClearArea(DWORD* pMem,int x,int y,int L,int W)
{
int i;
for(int a=x;a<=x+L;a++)
for(int b= y;b<=y+W;b++)
i=a+b*600,
pMem[i] = RGB(
(GetRValue(pMem[i]) + GetRValue(pMem[i - 600]) + GetRValue(pMem[i-601]) + GetRValue(pMem[i-599]) + GetRValue(pMem[i - 1]) + GetRValue(pMem[i + 1]) + GetRValue(pMem[i + 600]) +GetRValue(pMem[599+i]) + GetRValue(pMem[601+i])) / 9.25,
(GetGValue(pMem[i]) + GetGValue(pMem[i - 600]) + GetGValue(pMem[i-601]) + GetGValue(pMem[i-599]) + GetGValue(pMem[i - 1]) + GetGValue(pMem[i + 1]) + GetGValue(pMem[i + 600]) + GetGValue(pMem[599+i]) + GetGValue(pMem[601+i])) / 9.25,
(GetBValue(pMem[i]) + GetBValue(pMem[i - 600]) + GetBValue(pMem[i-601]) + GetBValue(pMem[i-599]) + GetBValue(pMem[i - 1]) + GetBValue(pMem[i + 1]) + GetBValue(pMem[i + 600]) + GetBValue(pMem[599+i]) + GetBValue(pMem[601+i])) / 9.25);
}
以及一个EraseArea() ,区域擦除函数,需要5个量:显存指针,擦出位置xy坐标,高度和宽度。代码如下:
void EraseArea(DWORD* pMem,int x,int y,int L,int W)
{
int i;
for(int a=x;a<=x+L;a++)
for(int b= y;b<=y+W;b++)
i=a+b*600,
pMem[i] = RGB(0,0,0);
}
2014年09月24日 05点09分
3