游戲微小更新,油庫里可以“左顧右盼”了

以下是相關代碼,有問題隨便問,有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;
}