-
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
7cef3ab
Refactor lighthouse
NikolaJelic d87ec64
Refacotr PR requests
NikolaJelic e4360a0
Add very basic enemy spawn and render
NikolaJelic 972e408
Add util/random, demo in app (#5)
karnkaul c7ab5f6
Merge branch 'main' into nikola/enemy
NikolaJelic 30c3153
Refactor Enemy
NikolaJelic c1b20c7
Include <numbers> to fix compilation on Win
NikolaJelic 3e86574
Refactor small issues
NikolaJelic 8ec1158
Add missing namespace
NikolaJelic 5862bef
Change function signature
NikolaJelic acef7e4
Add enemy waves
NikolaJelic d76611d
Fix iterator type
NikolaJelic 26b9323
Fix type `int` -> `size_t`
NikolaJelic 19bc668
Add simple collision detection
NikolaJelic e241f8a
Minor formatting and include changes
NikolaJelic d378bf9
Extract enemy starter movement values to dedicated struct
NikolaJelic 1c2b973
Fix vec2 include
NikolaJelic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,31 @@ | ||
#include <enemy.hpp> | ||
#include <algorithm> | ||
#include <iostream> | ||
#include <numbers> | ||
#include "glm/ext/vector_float2.hpp" | ||
#include "glm/geometric.hpp" | ||
#include "kvf/color.hpp" | ||
#include "util/random.hpp" | ||
|
||
namespace miracle { | ||
Enemy::Enemy(gsl::not_null<le::ServiceLocator const*> services, glm::vec2 target_pos) : m_services(services), m_target_pos(target_pos) { | ||
Enemy::Enemy(gsl::not_null<le::ServiceLocator const*> services, glm::vec2 target_pos, float move_speed) | ||
: m_services(services), m_target_pos(target_pos), m_move_speed(move_speed) { | ||
m_sprite.create(50.0f, kvf::red_v); | ||
auto const framebuffer_size = m_services->get<le::Context>().framebuffer_size(); | ||
std::cout << framebuffer_size.x; | ||
m_sprite.transform.position = generate_spawn_pos(framebuffer_size); | ||
// TODO: add proper textures | ||
} | ||
|
||
void Enemy::render(le::Renderer& renderer) const { m_sprite.draw(renderer); } | ||
|
||
void move() {} | ||
void Enemy::move(kvf::Seconds const dt) { | ||
glm::vec2 direction = glm::normalize(m_target_pos - m_sprite.transform.position); | ||
glm::vec2 movement = direction * m_move_speed * dt.count(); | ||
NikolaJelic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
m_sprite.transform.position += movement; | ||
} | ||
|
||
glm::vec2 Enemy::generate_spawn_pos(glm::vec2 screen_size) { | ||
float radius = std::min(screen_size.x, screen_size.y) / 2.0f; | ||
// this is temporary and will be replaced with a more robust random number generator | ||
float angle = rand() / RAND_MAX * 2.0f * M_PI; | ||
glm::vec2 Enemy::generate_spawn_pos(glm::vec2 screen_size) { | ||
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>); | ||
NikolaJelic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return {radius * std::cos(angle), radius * std::sin(angle)}; | ||
} | ||
|
||
} // namespace miracle |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.