2022-07-26 12:40:54 +08:00
|
|
|
module;
|
|
|
|
#include <d2d1.h>
|
|
|
|
#include <wrl/client.h>
|
|
|
|
|
|
|
|
export module GameObject;
|
|
|
|
|
|
|
|
import Graphics;
|
|
|
|
import Math;
|
|
|
|
|
|
|
|
export struct Texture
|
|
|
|
{
|
|
|
|
using BitMap = ::Microsoft::WRL::ComPtr<ID2D1Bitmap>;
|
|
|
|
|
|
|
|
BitMap bitmap;
|
|
|
|
Vector2 size;
|
|
|
|
Rect rect;
|
|
|
|
|
|
|
|
static Texture LoadFromFile(LPCWSTR uri)
|
|
|
|
{
|
|
|
|
Texture tex;
|
|
|
|
tex.bitmap = Graphics::LoadImageFromFile(uri);
|
|
|
|
auto s = tex.bitmap->GetPixelSize();
|
|
|
|
tex.size = { (FLOAT)s.width, (FLOAT)s.height };
|
|
|
|
tex.rect = { 0.f, 0.f, tex.size.x, tex.size.y };
|
|
|
|
return tex;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export class GameObject
|
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
Texture imge;
|
|
|
|
Vector2 Posi;
|
|
|
|
Vector2 Anch;
|
|
|
|
Vector2 Size;
|
|
|
|
|
|
|
|
GameObject() {}
|
|
|
|
|
|
|
|
virtual void OnStartUp() = 0;
|
|
|
|
virtual void OnCleanUp() = 0;
|
|
|
|
virtual void OnUpdate(float delta) = 0;
|
|
|
|
virtual void OnLaterUpdate(float delta) = 0;
|
|
|
|
|
2022-08-01 17:19:30 +08:00
|
|
|
virtual void OnRender()
|
2022-07-26 12:40:54 +08:00
|
|
|
{
|
|
|
|
Rect dst =
|
|
|
|
{
|
|
|
|
Posi.x - Size.x * Anch.x,
|
|
|
|
Posi.y + Size.y * (1.f - Anch.y),
|
|
|
|
Posi.x + Size.x * (1.f - Anch.x),
|
|
|
|
Posi.y - Size.y * Anch.y,
|
|
|
|
};
|
|
|
|
Graphics::DrawBitMap(imge.bitmap, dst, imge.rect);
|
|
|
|
}
|
|
|
|
};
|