#include "game_data.h" int flip_horizontal(Action_Graph *src) /* 将图像进行水平翻转 */ { int value = 0,x,y,pos,temp,count; int width = src->width,hight = src->height; unsigned char buff; if(src->malloc != IS_TRUE) { value = -1; } else{ temp = (int)width/2; for (y=0;y<hight;y++) { /* 水平翻转其实也就是交换两边的数据 */ pos = y*img_width; for (x=0;x<temp;x++) { count = img_width - x - 1; buff = src->rgba[0][pos+x]; src->rgba[0][pos+x] = src->rgba[0][count]; src->rgba[0][count] = buff; buff = src->rgba[1][pos+x]; src->rgba[1][pos+x] = src->rgba[1][count]; src->rgba[1][count] = buff; buff = src->rgba[2][pos+x]; src->rgba[2][pos+x] = src->rgba[2][count]; src->rgba[2][count] = buff; buff = src->rgba[3][pos+x]; src->rgba[3][pos+x] = src->rgba[3][count]; src->rgba[3][count] = buff; /* “命中”点阵图的翻转 */ if(src->hit_flag == IS_TRUE){ buff = src->hit[pos+x]; src->hit[pos+x] = src->hit[count]; src->hit[count] = buff; } /* “攻击”点阵图的翻转 */ if(src->atk_flag == IS_TRUE){ buff = src->atk[pos+x]; src->atk[pos+x] = src->atk[count]; src->atk[count] = buff; } } } } return value; }
由于现在写的游戏,需要处理攻击和被攻击,我就为每一帧的图形添加了攻击和被攻击的点阵图,方便处理。能将图形水平翻转的函数(2)
内容版权声明:除非注明,否则皆为本站原创文章。