MegaSteve/Obstacle.ixx

93 lines
2.0 KiB
Plaintext
Raw Permalink Normal View History

2022-08-05 23:50:08 +08:00
module;
#include <random>
export module Obstacle;
import GameObject;
export struct Obstacle : GameObject
{
static constexpr Rect ObstacleRectList[]
{
//Small Cactus
{ 446,2,480,72 },
{ 480,2,514,72 },
{ 514,2,548,72 },
{ 548,2,582,72 },
{ 582,2,616,72 },
{ 616,2,650,72 },
//Giant Cactus
{ 652,2,702,102 },
{ 702,2,750,102 },
{ 752,2,802,102 },
{ 802,2,850,102 },
//Double Giant Cactus
{ 652,2,750,102 },
{ 752,2,850,102 },
//Tirple Giant Cactus
{ 850,2,952,102 },
//Qradro Giant Cactus
{ 802,2,952,102 },
2022-08-06 00:47:11 +08:00
// Pterosaur
2022-08-05 23:50:08 +08:00
{ 260,2,352,82 },
{ 352,2,444,82 },
};
float speed = -500.f;
float time = 0.f;
bool isCactus = true;
virtual void OnStartUp() override
{
imge.rect = ObstacleRectList[0];
Size = imge.rect.size();
Posi = { 1200, 50 };
Anch = { 0.5f,0 };
Reset();
}
virtual void OnCleanUp() override
{
}
virtual void OnUpdate(float delta) override
{
time += delta;
Posi.x += speed * delta;
imge.rect = (int)(time / 0.3) % 2 ? ObstacleRectList[14] : ObstacleRectList[15];
}
virtual void OnLaterUpdate(float delta) override
{
if (Posi.x <= -100.f) Reset();
}
void Start()
{
}
std::mt19937 random{std::random_device()()};
void Reset()
{
2022-08-06 00:47:11 +08:00
int index = random() % 15;
2022-08-05 23:50:08 +08:00
if (index == 14)
{
isCactus = false;
2022-08-06 00:47:11 +08:00
Posi.y = 120;
2022-08-05 23:50:08 +08:00
}
else
{
isCactus = true;
Posi.y = 50;
}
imge.rect = ObstacleRectList[index];
Size = imge.rect.size();
speed += -1.f;
Posi.x = 1200.f;
}
virtual void OnReset() override
{
imge.rect = ObstacleRectList[0];
Size = imge.rect.size();
Posi = { 1200, 50 };
Anch = { 0.5f,0 };
Reset();
}
};