39 const float screenWidth =
static_cast<float>(width);
40 const float screenHeight =
static_cast<float>(height);
51 const auto entity = pair.first;
59 transform->
x += velocity->x * dt;
60 transform->y += velocity->y * dt;
62 if (transform->x < -10.0f || transform->x > screenWidth + 10.0f || transform->y < -10.0f ||
63 transform->y > screenHeight + 10.0f)
65 transform->x = screenWidth + std::rand() % 200;
66 transform->y =
static_cast<float>(std::rand() %
static_cast<int>(screenHeight));
78 const std::string &pixelId = pixel->
id;
79 isStar = (pixelId ==
"star_far" || pixelId ==
"star_mid" || pixelId ==
"star_near");
80 isNear = (pixelId ==
"star_near");
81 isMid = (pixelId ==
"star_mid");
83 unsigned char finalAlpha = color->a;
86 float starPhase = (transform->x * 0.1f + transform->y * 0.15f +
m_timeAccumulator * 0.8f);
87 float twinkle = (std::sin(starPhase) + 1.0f) * 0.5f;
88 finalAlpha =
static_cast<unsigned char>(color->a * (0.5f + twinkle * 0.5f));
91 cachedColor = {.r = color->r, .g = color->g, .b = color->b, .a = finalAlpha};
97 cachedColor.a =
static_cast<unsigned char>(finalAlpha * 0.8f);
102 cachedColor.a =
static_cast<unsigned char>(finalAlpha * 0.7f);
128 const unsigned int screenHeight,
const eng::Color &color,
float velocity,
129 const std::string &
id)
131 for (
int i = 0; i < count; ++i)
135 .with<Transform>(
id +
"_transform",
static_cast<float>(std::rand() % screenWidth),
136 static_cast<float>(std::rand() % screenHeight), 0.0f)
137 .with<
Color>(
id +
"_color", color.
r, color.
g, color.
b, color.
a)
138 .with<Velocity>(
id +
"_vel", velocity, 0.0f)
143 const unsigned int screenHeight)
145 for (
int i = 0; i < count; ++i)
149 .with<Transform>(
"star_shooting_transform",
static_cast<float>(std::rand() % screenWidth),
150 static_cast<float>(std::rand() % screenHeight), 0.0f)
153 .with<Velocity>(
"star_shooting_vel", -120.0f,
static_cast<float>((std::rand() % 20) - 10))
158 const unsigned int screenHeight)
160 for (
int i = 0; i < count; ++i)
164 .with<Transform>(
"planet_far_transform",
static_cast<float>(std::rand() % screenWidth),
165 static_cast<float>(std::rand() % screenHeight), 0.0f)
168 .with<Velocity>(
"planet_far_vel", -5.0f, 0.0f)
173 const unsigned int screenHeight)
175 for (
int i = 0; i < count; ++i)
179 .with<Transform>(
"nebula_transform",
static_cast<float>(std::rand() % screenWidth),
180 static_cast<float>(std::rand() % screenHeight), 0.0f)
184 .with<Velocity>(
"nebula_vel", -8.0f, 0.0f)
189 const unsigned int screenHeight)
191 for (
int i = 0; i < count; ++i)
195 .with<Transform>(
"comet_transform",
static_cast<float>(std::rand() % screenWidth),
196 static_cast<float>(std::rand() % screenHeight), 0.0f)
199 .with<Velocity>(
"comet_vel", -60.0f,
static_cast<float>((std::rand() % 40) - 20))
205 const unsigned int screenHeight,
float velocity,
const std::string &baseId)
207 for (
int i = 0; i < count; ++i)
209 int colorType = std::rand() % 4;
210 unsigned char r, g, b, a;
242 .with<Transform>(baseId +
"_transform",
static_cast<float>(std::rand() % screenWidth),
243 static_cast<float>(std::rand() % screenHeight), 0.0f)
244 .with<
Color>(baseId +
"_color", r, g, b, a)
245 .with<Velocity>(baseId +
"_vel", velocity, 0.0f)
This file contains the component definitions.
This file contains the IRenderer class declaration.
This file contains the interface for systems.
This file contains the Registry class declaration.
Abstract class for system.
EntityBuilder & with(Args &&...args)
Class for managing entities and their components.
EntityBuilder createEntity()
std::unordered_map< Entity, T > & getAll()
T * getComponent(Entity e)
StarfieldSystem & operator=(const StarfieldSystem &)=delete
static void createStars(Registry ®istry, const int count, const unsigned int screenWidth, const unsigned int screenHeight, const eng::Color &color, float velocity, const std::string &id)
static void createNebulae(Registry ®istry, const int count, const unsigned int screenWidth, const unsigned int screenHeight)
static void createComets(Registry ®istry, const int count, const unsigned int screenWidth, const unsigned int screenHeight)
~StarfieldSystem() override=default
static void createStarfield(Registry ®istry, const eng::WindowSize &windowSize)
void update(Registry ®istry, const float dt) override
static void createShootingStars(Registry ®istry, const int count, const unsigned int screenWidth, const unsigned int screenHeight)
static void createStarsVaried(Registry ®istry, const int count, const unsigned int screenWidth, const unsigned int screenHeight, float velocity, const std::string &baseId)
StarfieldSystem(const std::shared_ptr< eng::IRenderer > &renderer, Registry ®istry)
StarfieldSystem(const StarfieldSystem &)=delete
StarfieldSystem & operator=(StarfieldSystem &&)=delete
static void createPlanets(Registry ®istry, const int count, const unsigned int screenWidth, const unsigned int screenHeight)
const std::shared_ptr< eng::IRenderer > & m_renderer
StarfieldSystem(StarfieldSystem &&)=delete
virtual WindowSize getWindowSize()=0
virtual void drawPoint(float x, float y, Color color)=0
This file contains common definitions and constants.
static constexpr eng::Color PURPLE
static constexpr eng::Color BLUE_SECOND
static constexpr eng::Color WHITE_TRANS
static constexpr eng::Color BLUE
static constexpr eng::Color YELLOW
static constexpr eng::Color GREEN