summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2024-03-21 18:05:27 +0100
committerStanislaw Halik <sthalik@misaki.pl>2024-03-21 18:05:27 +0100
commit993dde2e427127e0c1eb20099c1e014228050c90 (patch)
tree0b9b3e3471d691437d185057f37b27230e053a09 /src
parentf3dd8b426f5f39bebc64ed1fae39c8b7d73a6aa5 (diff)
w auto movement
Diffstat (limited to 'src')
-rw-r--r--src/critter.cpp25
-rw-r--r--src/critter.hpp7
2 files changed, 21 insertions, 11 deletions
diff --git a/src/critter.cpp b/src/critter.cpp
index 3e88d8df..2d0393f3 100644
--- a/src/critter.cpp
+++ b/src/critter.cpp
@@ -123,10 +123,12 @@ bool critter_proto::operator==(const object_proto& e0) const
void critter::set_keys(bool L, bool R, bool U, bool D)
{
- b_L = L;
- b_R = R;
- b_U = U;
- b_D = D;
+ movement = { L, R, U, D, false };
+}
+
+void critter::set_keys_auto()
+{
+ movement = { false, false, false, false, true };
}
float critter::depth_offset() const
@@ -144,14 +146,17 @@ void critter::update(size_t i, Ns dt)
{
if (playable)
{
- const auto new_r = arrows_to_dir(b_L, b_R, b_U, b_D);
- if (new_r == rotation_COUNT)
+ if (!movement.AUTO)
{
- offset_frac = {};
- delta = 0;
+ const auto new_r = arrows_to_dir(movement.L, movement.R, movement.U, movement.D);
+ if (new_r == rotation_COUNT)
+ {
+ offset_frac = {};
+ delta = 0;
+ }
+ else
+ update_movement(i, dt, new_r);
}
- else
- update_movement(i, dt, new_r);
}
else
update_nonplayable(i, dt);
diff --git a/src/critter.hpp b/src/critter.hpp
index 1148b82b..d3f39e87 100644
--- a/src/critter.hpp
+++ b/src/critter.hpp
@@ -33,13 +33,18 @@ struct critter final : object
void update_movement(size_t i, Ns dt, rotation r);
void update_nonplayable(size_t i, Ns dt);
void set_keys(bool L, bool R, bool U, bool D);
+ void set_keys_auto();
Vector2 ordinal_offset(Vector2b offset) const override;
float depth_offset() const override;
String name;
float speed = 1;
Vector2us offset_frac; // todo! switch to Vector2ui due to `allocate_frame_time'
- bool b_L : 1 = false, b_R : 1 = false, b_U : 1 = false, b_D : 1 = false;
+
+ struct movement_s {
+ bool L : 1, R : 1, U : 1, D : 1, AUTO : 1;
+ } movement = {};
+
bool playable : 1 = false;
private: