mapcreator git · master
SDL3 2.5D game and engine using assets, with map editor
C++ 99.3%git clone https://git.christianimmanuel.de/sdl-graphics/mapcreator.gitwget https://git.christianimmanuel.de/sdl-graphics/mapcreator/archive/mapcreator.tar.gzProper death with unpracticed sht
music/character.dead.wav | Bin 0 -> 3034798 bytes music/orig.character.dead.wav | Bin 0 -> 3034798 bytes src/character/character.cpp | 32 ++++++++++++++++++++------------ src/defaults/shuffle_texture.hpp | 8 ++++---- src/game/state_playing.cpp | 1 + 5 files changed, 25 insertions(+), 16 deletions(-) diff --git a/music/character.dead.wav b/music/character.dead.wav new file mode 100644 index 0000000..623a694 Binary files /dev/null and b/music/character.dead.wav differ diff --git a/music/orig.character.dead.wav b/music/orig.character.dead.wav new file mode 100644 index 0000000..4c7b6b1 Binary files /dev/null and b/music/orig.character.dead.wav differ diff --git a/src/character/character.cpp b/src/character/character.cpp index 21f48ff..3999d99 100644 --- a/src/character/character.cpp +++ b/src/character/character.cpp @@ -133,6 +133,8 @@ Character::Init(SDL_Renderer* renderer) { animation.drinking_river[WalkDirection::SIDE] = Animation::load(renderer, "Pixel_Crawler/Entities/Characters/Body_A/Animations/Collect_Base/Collect_Side-Sheet.png", tile_size, tile_size, "None"); animation.drinking_river[WalkDirection::UP] = Animation::load(renderer, "Pixel_Crawler/Entities/Characters/Body_A/Animations/Collect_Base/Collect_Up-Sheet.png", tile_size, tile_size, "None"); + Animation::audio->RegisterSound("character.dead", "music/character.dead.wav"); + handle_Animation(); set_Status(CharacterStatus::IDLE); @@ -256,7 +258,6 @@ Character::Draw(SDL_Renderer* renderer) { // Render Character const SDL_FRect& src = active_anim->frames[active_anim->current_frame]; - std::cout << "FR: " << active_anim->current_frame<< std::endl; SDL_FRect dst { Scale(x + Map::offset.x), @@ -1046,9 +1047,20 @@ Character::Resurrect() { constexpr float SHUFFLE_START_TIME = 1.6f; constexpr float MOVE_START_TIME = 2.1f; - constexpr float UNSHUFFLE_TIME = 2.8f; + constexpr float UNSHUFFLE_TIME = 1.4f; constexpr float FRAME_REDUCE_TIME = 0.8f; - constexpr float TICK_INTERVAL = 0.04f; + constexpr float MAX_DST = 32.0f; + + auto distance = [](const SDL_FPoint& a, const SDL_FPoint& b) { + float dx = a.x - b.x; + float dy = a.y - b.y; + return SDL_sqrtf(dx * dx + dy * dy); + }; + + float TICK_INTERVAL = 0.04f; + if (resurrect_phase > 0 && distance(collider_world, spawn_point) < MAX_DST) { + TICK_INTERVAL = 0.02f; + } static float tick_accumulator = 0.0f; tick_accumulator += Default::delta_time; @@ -1058,12 +1070,6 @@ Character::Resurrect() { tick = true; } - auto distance = [](const SDL_FPoint& a, const SDL_FPoint& b) { - float dx = a.x - b.x; - float dy = a.y - b.y; - return SDL_sqrtf(dx * dx + dy * dy); - }; - /* ---------------- PHASE 0: INITIAL DELAY ---------------- */ if (resurrect_phase == 0) { if (shuffle_timer >= SHUFFLE_START_TIME) { @@ -1090,7 +1096,10 @@ Character::Resurrect() { /* ---------------- PHASE 2: SHUFFLE + MOVE ---------------- */ if (resurrect_phase == 2) { if (tick) { - death_shuffler->shufflePixels(); + if (MAX_DST && distance(collider_world, spawn_point) > MAX_DST) + death_shuffler->shufflePixels(); + else + death_shuffler->unshuffleStep(); } if (distance(collider_world, spawn_point) <= 2.0f) { @@ -1125,7 +1134,7 @@ Character::Resurrect() { if (t > 1.0f) t = 1.0f; active_anim->current_frame = - static_cast<int>(resurrection_start_frame * (1.0f - t)); + resurrection_start_frame * (1.0f - t); if (resurrection_timer >= FRAME_REDUCE_TIME) { resurrect_phase = 5; @@ -1250,7 +1259,6 @@ Character::handle_Animation() { default: active_anim_ref = &animation.idle[dir]; - std::cout << "IDLEoo\n"; break; } diff --git a/src/defaults/shuffle_texture.hpp b/src/defaults/shuffle_texture.hpp index 4ca1bb6..3dab3af 100644 --- a/src/defaults/shuffle_texture.hpp +++ b/src/defaults/shuffle_texture.hpp @@ -105,10 +105,10 @@ public: int nx = x, ny = y; switch (direction) { - case 0: nx = x + 1; break; // right - case 1: ny = y + 1; break; // down - case 2: nx = x - 1; break; // left - case 3: ny = y - 1; break; // up + case 0: nx = (x + 1) % width; break; + case 1: ny = (y + 1) % height; break; + case 2: nx = (x - 1 + width) % width; break; + case 3: ny = (y - 1 + height) % height; break; } // Only swap if neighbor is valid diff --git a/src/game/state_playing.cpp b/src/game/state_playing.cpp index f60e0a3..4886152 100644 --- a/src/game/state_playing.cpp +++ b/src/game/state_playing.cpp @@ -205,6 +205,7 @@ void StatePlaying::Update(Game* game) { if (player->status == CharacterStatus::DEAD && player->death_shuffler == nullptr) { player->death_shuffler = new PixelShuffler(game->renderer, player->active_anim->surface); player->shuffle_timer = 0.0f; + Animation::audio->Play("character.dead"); return; }