161 lines
4.9 KiB
C++
161 lines
4.9 KiB
C++
#pragma once
|
|
|
|
#include "Components.hpp"
|
|
#include "Entity.hpp"
|
|
#include <memory>
|
|
|
|
std::shared_ptr<Entity> CreateProbe() {
|
|
auto e = std::make_shared<Entity>();
|
|
auto &transform = e->AddComponent<TransformComponent>();
|
|
transform.x = 96.0f;
|
|
transform.y = 230.0f;
|
|
|
|
e->AddComponent<GravityReceiverComponent>();
|
|
|
|
auto &physics = e->AddComponent<PhysicsComponent>();
|
|
physics.vx = 108.0f;
|
|
physics.vy = 0.0f;
|
|
physics.speedCap = 8192.0f;
|
|
|
|
auto &collider = e->AddComponent<ColliderComponent>();
|
|
collider.radius = 7.0f;
|
|
|
|
auto &probeState = e->AddComponent<ProbeStateComponent>();
|
|
probeState.spawnX = 96.0f;
|
|
probeState.spawnY = 230.0f;
|
|
probeState.spawnVx = 165.0f;
|
|
probeState.spawnVy = 0.0f;
|
|
|
|
e->AddComponent<TrailComponent>();
|
|
e->AddComponent<ProjectionComponent>();
|
|
auto &render = e->AddComponent<RenderComponent>();
|
|
render.draw = [e]() {
|
|
auto transform = e->GetComponent<TransformComponent>();
|
|
if (!transform) {
|
|
return;
|
|
}
|
|
DrawCircleV({transform->get().x, transform->get().y}, 7.0f, Color{250, 244, 227, 255});
|
|
};
|
|
return e;
|
|
}
|
|
|
|
std::shared_ptr<Entity> CreateGravityWell() {
|
|
auto e = std::make_shared<Entity>();
|
|
auto &transform = e->AddComponent<TransformComponent>();
|
|
transform.x = 96.0f;
|
|
transform.y = 230.0f;
|
|
|
|
auto &well = e->AddComponent<GravityWellComponent>();
|
|
well.mass = (float)(1 << 22);
|
|
well.minDist = 28.0f;
|
|
well.followLerp = 12.0f;
|
|
|
|
auto &render = e->AddComponent<RenderComponent>();
|
|
render.draw = [e]() {
|
|
auto transform = e->GetComponent<TransformComponent>();
|
|
if (!transform) {
|
|
return;
|
|
}
|
|
DrawCircleLines(static_cast<int>(transform->get().x), static_cast<int>(transform->get().y),
|
|
18.0f, Color{86, 197, 255, 255});
|
|
};
|
|
return e;
|
|
}
|
|
|
|
std::shared_ptr<Entity> CreateStar(float x, float y) {
|
|
auto e = std::make_shared<Entity>();
|
|
auto &t = e->AddComponent<TransformComponent>();
|
|
t.x = x;
|
|
t.y = y;
|
|
auto &scrollable = e->AddComponent<ScrollableComponent>();
|
|
scrollable.worldX = x;
|
|
auto &collider = e->AddComponent<ColliderComponent>();
|
|
collider.radius = 6.0f;
|
|
|
|
e->AddComponent<CollectibleComponent>();
|
|
auto &render = e->AddComponent<RenderComponent>();
|
|
render.draw = [e]() {
|
|
auto transform = e->GetComponent<TransformComponent>();
|
|
if (!transform) {
|
|
return;
|
|
}
|
|
DrawCircleV({transform->get().x, transform->get().y}, 6.0f, Color{255, 223, 86, 255});
|
|
};
|
|
return e;
|
|
}
|
|
|
|
std::shared_ptr<Entity> CreateAsteroid(float x, float y) {
|
|
auto e = std::make_shared<Entity>();
|
|
auto &t = e->AddComponent<TransformComponent>();
|
|
t.x = x;
|
|
t.y = y;
|
|
auto &scrollable = e->AddComponent<ScrollableComponent>();
|
|
scrollable.worldX = x;
|
|
auto &collider = e->AddComponent<ColliderComponent>();
|
|
collider.radius = 13.0f;
|
|
|
|
e->AddComponent<HazardComponent>();
|
|
|
|
auto &render = e->AddComponent<RenderComponent>();
|
|
render.draw = [e]() {
|
|
auto transform = e->GetComponent<TransformComponent>();
|
|
if (!transform) {
|
|
return;
|
|
}
|
|
DrawCircleV({transform->get().x, transform->get().y}, 13.0f, Color{116, 126, 142, 255});
|
|
};
|
|
return e;
|
|
}
|
|
|
|
std::shared_ptr<Entity> CreateNullZone(float x, float width) {
|
|
auto e = std::make_shared<Entity>();
|
|
auto &t = e->AddComponent<TransformComponent>();
|
|
t.x = x;
|
|
auto &scrollable = e->AddComponent<ScrollableComponent>();
|
|
scrollable.worldX = x;
|
|
|
|
auto &nullZone = e->AddComponent<NullZoneComponent>();
|
|
nullZone.width = width;
|
|
auto &render = e->AddComponent<RenderComponent>();
|
|
render.draw = [e]() {
|
|
auto transform = e->GetComponent<TransformComponent>();
|
|
auto zone = e->GetComponent<NullZoneComponent>();
|
|
if (!transform || !zone) {
|
|
return;
|
|
}
|
|
|
|
DrawRectangle(static_cast<int>(transform->get().x), 0, static_cast<int>(zone->get().width),
|
|
GetScreenHeight(), Color{96, 64, 146, 80});
|
|
};
|
|
return e;
|
|
}
|
|
|
|
std::shared_ptr<Entity> CreateWorld() {
|
|
auto e = std::make_shared<Entity>();
|
|
e->AddComponent<ScrollComponent>();
|
|
e->AddComponent<SpawnComponent>();
|
|
return e;
|
|
}
|
|
|
|
std::shared_ptr<Entity> CreateHUD() {
|
|
auto e = std::make_shared<Entity>();
|
|
e->AddComponent<MeterComponent>();
|
|
e->AddComponent<HudComponent>();
|
|
auto &render = e->AddComponent<RenderComponent>();
|
|
render.draw = [e]() {
|
|
auto meter = e->GetComponent<MeterComponent>();
|
|
if (!meter) {
|
|
return;
|
|
}
|
|
|
|
const float t = std::clamp(meter->get().value / 100.0f, 0.0f, 1.0f);
|
|
const int x = 14;
|
|
const int y = 86;
|
|
const int w = 240;
|
|
const int h = 14;
|
|
DrawRectangleLines(x, y, w, h, Color{125, 140, 165, 255});
|
|
DrawRectangle(x + 1, y + 1, static_cast<int>((w - 2) * t), h - 2, Color{60, 199, 178, 255});
|
|
};
|
|
return e;
|
|
}
|