欢迎光临散文网 会员登陆 & 注册

游戏微小更新,油库里可以“左顾右盼”了

2023-07-13 22:20 作者:childlizr  | 我要投稿

以下是相关代码,有问题随便问,有bug随便提。

虽然是咱自己想出来的,但是肯定有雷同,咱懒得去找,反正能达到目的就行。

测试方法在注释里。


#include <easyx.h>

#include <conio.h>

//运行后随便按一个字母键后,图片水平翻转。

//图片需要自己准备,为png格式,名称改为test.png,和这个源文件放在同一文件夹

class youkuli

{

protected:

IMAGE* body;

public:

youkuli()

{

this->body = new IMAGE;

loadimage(this->body, L"./test.png");

}

~youkuli()

{

delete this->body;

this->body = nullptr;

}

void flip_horizontal()//将图片水平翻转(水平镜像)

{

DWORD* tem_picture = GetImageBuffer(this->body);//身体原图片(将要被修改的)

IMAGE base = *(this->body);//备用(不变的)

DWORD* base_picture = GetImageBuffer(&base);//备用(不变的)

int R = 0, G = 0, B = 0;

int max = this->body->getheight() * this->body->getwidth();

int i_for_tem = 0;//被改写的点的下角标

int where_x = 0, where_y = 0;//不变的那个图的点的对应坐标

while (i_for_tem < max)

{

if (where_x == this->body->getwidth())//换行

{

where_x = 0;

where_y++;

}

auto get_order = [&i_for_tem, this, &where_y]()//得到翻转后的下角标

{

return ((this->body->getwidth() - (i_for_tem % this->body->getwidth())) + where_y * this->body->getwidth());

};

R = GetRValue(base_picture[get_order()]);

G = GetGValue(base_picture[get_order()]);

B = GetBValue(base_picture[get_order()]);

tem_picture[i_for_tem] = RGB(R, G, B);

where_x++;

i_for_tem++;

}

}

void draw(int x, int y)

{

putimage(x, y, this->body);

}

};

int main()

{

initgraph(1000, 600);

youkuli* test = new youkuli();

setbkcolor(BLACK);

BeginBatchDraw();


while (1)

{

test->draw(10,10);

FlushBatchDraw();

//_getch();

test->flip_horizontal();

test->draw(10,10);

FlushBatchDraw();

_getch();

}

return 0;

}

游戏微小更新,油库里可以“左顾右盼”了的评论 (共 条)

分享到微博请遵守国家法律