summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2024-02-28 00:50:24 +0100
committerStanislaw Halik <sthalik@misaki.pl>2024-02-28 00:50:24 +0100
commita537f2c28acef8c43535f2326997499d29eb7e01 (patch)
tree323b897ca5de90f0f2ac561d4c7ab83c71a399a2
parent28da3cfd99370694806286df363aa5fa19c49de0 (diff)
enable move speed scaling with critter.speed
-rw-r--r--editor/app.cpp3
-rw-r--r--src/critter.cpp32
2 files changed, 9 insertions, 26 deletions
diff --git a/editor/app.cpp b/editor/app.cpp
index 70766ccd..fe4f9b53 100644
--- a/editor/app.cpp
+++ b/editor/app.cpp
@@ -68,12 +68,13 @@ shared_ptr_wrapper<critter> app::ensure_player_character(world& w)
{
critter_proto cproto;
cproto.name = "Player"_s;
+ cproto.speed = 4;
cproto.playable = true;
ret.ptr = w.make_object<critter>(w.make_id(), global_coords{}, cproto);
_character_id = ret.ptr->id;
}
fm_debug_assert(ret.ptr);
- return shared_ptr_wrapper<critter>{ret};
+ return ret;
}
void app::reset_world(class world&& w_)
diff --git a/src/critter.cpp b/src/critter.cpp
index a4f69362..b7d67dd9 100644
--- a/src/critter.cpp
+++ b/src/critter.cpp
@@ -15,7 +15,7 @@ namespace floormat {
namespace {
-constexpr double framerate = 96 * 3, move_speed = Vector2d(TILE_SIZE2).length() * 4.25;
+constexpr double framerate = 60, move_speed = 150;
constexpr double frame_time = 1/framerate;
constexpr auto arrows_to_dir(bool left, bool right, bool up, bool down)
@@ -147,24 +147,6 @@ Vector2 critter::ordinal_offset(Vector2b offset) const
return Vector2(offset);
}
-constexpr auto make_move_vec(rotation r)
-{
- auto [_0, _1, _2] = rotation_to_similar(r);
- return std::array<Vector2, 3>{{
- move_vec(rotation_to_vec(_0)),
- move_vec(rotation_to_vec(_1)),
- move_vec(rotation_to_vec(_2)),
- }};
-}
-
-template<size_t... Index>
-constexpr auto make_move_vecs(std::index_sequence<Index...>)
-{
- return std::array<std::array<Vector2, 3>, (size_t)rotation_COUNT>{{
- make_move_vec((rotation)Index)...,
- }};
-}
-
void critter::update(size_t i, float dt)
{
const auto new_r = arrows_to_dir(b_L, b_R, b_U, b_D);
@@ -175,13 +157,13 @@ void critter::update(size_t i, float dt)
return;
}
- int nframes = allocate_frame_time(dt);
+ int nframes = allocate_frame_time(dt * speed);
if (nframes == 0)
return;
- constexpr auto move_vecs_ = make_move_vecs(std::make_index_sequence<(size_t)rotation_COUNT>{});
- const auto& move_vecs = move_vecs_[(size_t)r];
- size_t nvecs = (int)new_r & 1 ? 3 : 1;
+ const auto rotations = rotation_to_similar(new_r);
+
+ const unsigned nvecs = (int)new_r & 1 ? 3 : 1;
if (r != new_r)
if (is_dynamic())
@@ -191,9 +173,9 @@ void critter::update(size_t i, float dt)
for (int k = 0; k < nframes; k++)
{
- for (auto j = 0uz; j < nvecs; j++)
+ for (unsigned j = 0; j < nvecs; j++)
{
- auto vec = move_vecs[j];
+ const auto vec = move_vec(rotation_to_vec(rotations[j]));
constexpr auto frac = 65535u;
constexpr auto inv_frac = 1.f / (float)frac;
const auto sign_vec = Math::sign(vec);