-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor lighthouse #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feature/actors
Are you sure you want to change the base?
Conversation
NikolaJelic
commented
Jun 17, 2025
- Create Lighthouse class
- Add texture rendering with placeholder texture
- Create Lighthouse class - Add texture rendering with placeholder texture
src/lighthouse.cpp
Outdated
m_texture = asset_loader.load_texture("images/lighthouse.png"); | ||
m_sprite.texture = &m_texture.value(); | ||
} | ||
void Lighthouse::rotate_towards_cursor(glm::vec2 const& cursor_pos) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: add empty line between functions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to fix incorrect unit vector
- rotate lighthouse image so it better follows the cursor - adjust whitespace - fix unit vector typo
Add new util/random
- add targeted movement - change spawn point generation
src/enemy.cpp
Outdated
glm::vec2 direction = glm::normalize(m_target_pos - m_sprite.transform.position); | ||
glm::vec2 movement = direction * m_move_speed * dt.count(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: locals should be const
unless being mutated after construction
src/enemy.cpp
Outdated
float radius = std::max(screen_size.x, screen_size.y) / 2.0f; | ||
float angle = util::random_range(0.0f, 2.0f * std::numbers::pi_v<float>); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const
src/enemy.hpp
Outdated
|
||
void render(le::Renderer& renderer) const; | ||
void move(); | ||
void move(kvf::Seconds dt); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change the name to tick()
, and don't use the identifier move
in C++, it might conflict with std::move()
, despite being in different namespaces. Also looks weird (use translate()
or something instead).
src/enemy.hpp
Outdated
|
||
private: | ||
glm::vec2 generate_spawn_pos(glm::vec2 screen_size); | ||
static glm::vec2 generate_spawn_pos(glm::vec2 screen_size); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of a static member function make this a free function in an unnamed namespace in the cpp file
src/enemy.hpp
Outdated
glm::vec2 m_target_pos; | ||
float m_move_speed; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uninitialized primitives (use {}
)
src/game.cpp
Outdated
@@ -1,10 +1,11 @@ | |||
#include <game.hpp> | |||
#include <glm/gtx/norm.hpp> | |||
#include <le2d/context.hpp> | |||
#include "glm/ext/vector_float2.hpp" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this needed?
namespace miracle { | ||
class Enemy { | ||
public: | ||
explicit Enemy(gsl::not_null<le::ServiceLocator const*> services, glm::vec2 target_pos, float move_speed); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest moving target_pos
and move_speed
params into a struct and take an instance of that in the constructor. A few benefits:
- Constructor signature doesn't change even if the struct members evolve over time
- Much more readable at call site:
{.move_speed = 50.0f, .target_pos = {1.0f, 2.0f}}
vs(50.0f, {1.0f, 2.0f})
- Callers can memoize params into their own objects that can be reused
src/enemy.hpp
Outdated
glm::vec2 m_target_pos; | ||
float m_move_speed; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uninitialized members (use {}
)
- move spawn point position generation to the 'util::random' namespace - add default initialization to primitives - remove redudant includes - add 'const' to local variables where appropriate - rename 'move' function to avoid naming conflicts
@@ -0,0 +1,27 @@ | |||
#include <enemy.hpp> | |||
#include <algorithm> | |||
#include "glm/ext/vector_float2.hpp" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do these random glm headers keep popping up in your PR?
// Returns a random coordinate on the specified radius | ||
[[nodiscard]] inline auto get_random_location_on_radius(float radius) -> glm::vec2 { | ||
float const angle = random_range(0.0f, 2.0f * std::numbers::pi_v<float>); | ||
return {radius * std::cos(angle), radius * std::sin(angle)}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::cos
requires <cmath>
@@ -0,0 +1,44 @@ | |||
#pragma once | |||
#include <glm/ext/vector_float2.hpp> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WTF