MegaSteve/GameObject.ixx

57 lines
1.1 KiB
C++

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;
virtual void OnRender()
{
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);
}
};