MegaSteve/Steve.ixx

124 lines
3.3 KiB
Plaintext
Raw Normal View History

module;
#include <wrl/client.h>
export module Steve;
import GameObject;
import Input;
export struct Steve : GameObject
{
2022-08-01 17:19:30 +08:00
static constexpr const float ground_height = 50;
2022-08-05 23:50:08 +08:00
static constexpr const float x_pos = 100;
float a, v, h;
bool jumping = false;
2022-08-01 17:19:30 +08:00
float time = 0.0f;
2022-08-05 23:50:08 +08:00
static constexpr Rect IdleRect = { 76, 2, 164, 96 };
static constexpr Rect NormalRect = { 1678, 2, 1766, 96 };
static constexpr Rect CloseEyeRect = { 1766, 2, 1854, 96 };
static constexpr Rect RightRect = { 1854, 2, 1942, 96 };
static constexpr Rect LeftRect = { 1942, 2, 2030, 96 };
static constexpr Rect BigEyeRect = { 2030, 2, 2118, 96 };
static constexpr Rect DeadRect = { 2122, 2, 2202, 96 };
static constexpr Rect CrawlingRightRect = { 2203, 2, 2321, 96 };
static constexpr Rect CrawlingLeftRect = { 2321, 2, 2439, 96 };
enum Status { Idle, Running, Jumping, Freefall, Crawling, Dead } status;
virtual void OnStartUp() override
{
2022-08-01 17:19:30 +08:00
imge.rect = IdleRect;
Anch = { 0.5f,0 };
2022-08-05 23:50:08 +08:00
Posi = { x_pos, ground_height };
Size = imge.rect.size();
a = v = h = 0.0f;
}
virtual void OnCleanUp() override
{
imge.bitmap = nullptr;
}
virtual void OnUpdate(float delta) override
{
2022-08-05 23:50:08 +08:00
if (isPaused) return;
2022-08-01 17:19:30 +08:00
time += delta;
switch (status)
{
case Steve::Idle:
if (KeyBoard::GetKey(VK_SPACE)) status = Running;
2022-08-01 17:19:30 +08:00
imge.rect = IdleRect;
2022-08-05 23:50:08 +08:00
Size = imge.rect.size();
break;
case Steve::Running:
if (KeyBoard::GetKey(VK_SPACE))
{
status = Jumping;
2022-08-01 17:19:30 +08:00
break;
}
2022-08-05 23:50:08 +08:00
if (KeyBoard::GetKey(VK_DOWN))
{
status = Crawling;
break;
}
2022-08-01 17:19:30 +08:00
imge.rect = (int)(time / 0.1) % 2 ? LeftRect : RightRect;
2022-08-05 23:50:08 +08:00
Size = imge.rect.size();
break;
case Steve::Jumping:
2022-08-01 17:19:30 +08:00
imge.rect = NormalRect;
2022-08-05 23:50:08 +08:00
Size = imge.rect.size();
2022-08-01 17:19:30 +08:00
if ((h < 75 || KeyBoard::GetKey(VK_SPACE)) && h < 150.f)
{
v = 1000.f;
h += v * delta;
2022-08-01 17:19:30 +08:00
Posi.y = ground_height + h;
}
else
{
status = Freefall;
}
break;
case Steve::Freefall:
a = -8000.f;
v += a * delta;
2022-08-01 17:19:30 +08:00
if (v < -1200) v = -1200;
h += v * delta;
2022-08-01 17:19:30 +08:00
Posi.y = ground_height + h;
if (Posi.y <= ground_height)
{
status = Running;
2022-08-01 17:19:30 +08:00
Posi.y = ground_height;
}
break;
case Steve::Crawling:
2022-08-05 23:50:08 +08:00
if (KeyBoard::GetKey(VK_DOWN))
{
imge.rect = (int)(time / 0.1) % 2 ? CrawlingLeftRect : CrawlingRightRect;
Size = imge.rect.size();
}
else
{
status = Running;
}
break;
default:
break;
}
}
virtual void OnLaterUpdate(float delta) override
{
2022-08-05 23:50:08 +08:00
if (isPaused) return;
}
virtual void OnReset() override
{
imge.rect = IdleRect;
status = Idle;
Anch = { 0.5f,0 };
Posi = { x_pos, ground_height };
Size = imge.rect.size();
a = v = h = 0.0f;
}
};