第四十六章 整理一下绘制函数的参数吧
一直到上一章位置,graph.cpp的DrawGraph和DrawRotaGraph函数之类的坐标都是○○+FX+dn.x这个样子的,我们必须每次都要把○○之外的多余部分写进去。
FX是为了让区域从0,0点稍微往右下方向错开而设置的X坐标分量。
而dn.x是画面咚!地摇动的时候的用于摇动控制的放入x坐标的变量。
这些东西要是每次都写的话就太麻烦了,而且毫无用处地横着把代码变得那么长看起来也不容易。
比如
void graph_item(){
int i;
for(i=0;i<ITEM_MAX;i++){
if(item[i].flag==1){
DrawRotaGraphF(item[i].x+FX+dn.x,item[i].y+FY+dn.y,item[i].r.....);
DrawRotaGraphF(item[i].x+FX+dn.x,item[i].y+FY+dn.y,item[i].r.....);
DrawRotaGraphF(item[i].x+FX+dn.x,item[i].y+FY+dn.y,item[i].r.....);
}
}
}
这些紫色的部分是每次都必须要写的部分,也是毫无意义的部分。
那么因此,我们不妨这样考虑:“在进行必须这样写的处理的时候,干脆直接调用自动追加这些部分的函数不就好了?”
现在我们说DrawRotaGraph函数是直接在区域上绘制的版本(译者注:DrawRotaGraph函数是DX Library的函数,它始终使用GDI坐标系即左上角坐标为(0,0),而现在要实现的版本是以游戏区域为原点进行绘制的版本),因此编写了DrawRotaGraphFdF这个函数。而且从现在开始我们就开始使用这些函数吧。
这个函数的参数和之前是一样的。只不过调用这些函数的时候,将绘制的坐标往上述的部分自动移动然后显示出来。
比如像下面这样将上面的函数用新的函数替换。
void graph_item(){
int i;
for(i=0;i<ITEM_MAX;i++){
if(item[i].flag==1){
DrawRotaGraphFdF(item[i].x,item[i].y,item[i].r....);
DrawRotaGraphFdF(item[i].x,item[i].y,item[i].r....);
DrawRotaGraphFdF(item[i].x,item[i].y,item[i].r....);
}
}
}
不过全部手动替换的话要全部变更就太麻烦了。
因此我们使用“替换”的功能。
graph.cpp中的
+FX
+FY
+dn.x
+dn.y
请把这些全部删除。
调出替换窗口,在搜索字符串窗口中输入上面那些文字,而置换部分什么都不写就行了。
接下来同样地在graph.cpp把下面的
DrawRotaGraphF → DrawRotaGraphFdF DrawModiGraphF → DrawModiGraphFdF 像这样子替换。
graph.cpp的graph_bullet()函数中的DrawGraph也变为DrawGraphFd。
在graph.cpp上进行以下追加
int DrawRotaGraphF( double xd, double yd, double ExRate, double Angle, int GrHandle, int TransFlag, int TurnFlag = FALSE ) {
return DrawRotaGraphF((float)xd,(float)yd,ExRate,Angle,GrHandle,TransFlag,TurnFlag);
}
int DrawModiGraphF( double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, int GrHandle, int TransFlag ){
return DrawModiGraphF( (float)x1, (float)y1, (float)x2, (float)y2, (float)x3, (float)y3, (float)x4, (float)y4, GrHandle, TransFlag ) ;
}
/***修改请注意***/
int DrawRotaGraphFdF( double xd, double yd, double ExRate, double Angle, int GrHandle, int TransFlag, int TurnFlag = FALSE ) {
return DrawRotaGraphF((float)xd+FX+dn.x,(float)yd+FY+dn.y,ExRate,Angle,GrHandle,TransFlag,TurnFlag);
}
int DrawModiGraphFdF( double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, int GrHandle, int TransFlag ){
return DrawModiGraphF( (float)x1+FX+dn.x, (float)y1+FY+dn.y, (float)x2+FX+dn.x, (float)y2+FY+dn.y,
(float)x3+FX+dn.x, (float)y3+FY+dn.y, (float)x4+FX+dn.x, (float)y4+FY+dn.y, GrHandle, TransFlag ) ;
}
int DrawGraphFd( int xd, int yd, int GrHandle, int TransFlag) {
return DrawGraph(xd+FX+dn.x,yd+FY+dn.y,GrHandle,TransFlag);
}
/***修改请注意***/
这样就行了。
graph_back.cpp的函数也请这样变更
#include "../include/GV.h"
/***修改请注意***/
extern int DrawGraphFd( int xd, int yd, int GrHandle, int TransFlag);
/***修改请注意***/
void graph_back00(){//通常背景
/***修改请注意***/
SetDrawArea( FX , FY , FX+FMX , FY+FMY ) ;//设定可以绘制的区域
DrawGraphFd(0,count%700-700,img_back[0],FALSE);
DrawGraphFd(0,count%700 ,img_back[0],FALSE);
SetDrawArea( 0, 0, 640, 480);//还原区域
/***修改请注意***/
}
void graph_back01(){//SC用背景
/***修改请注意***/
SetDrawArea( FX , FY , FX+FMX , FY+FMY ) ;//设定可以绘制的区域
DrawGraphFd(0,-count%480,img_back[11],FALSE);
DrawGraphFd(0,-count%480+480,img_back[11],FALSE);
DrawGraphFd(0,0,img_back[10],TRUE);
SetDrawArea( 0, 0, 640, 480);//还原区域
/***修改请注意***/
}
void graph_back_main(){
//Boss如果有效且为SC得话
if(boss.flag==1 && boss.back_knd[boss.knd]==1)
graph_back01();
else//除此之外
graph_back00();
}
如何?在此之前往参数传入的
+FX+dn.x,
+FY+dn.y,
全部都消失了,一样看去结构是不是变清晰了呢?
运行结果
本章没有动画。因为没有什么看上去的变化。