Skip to content

Commit

Permalink
Add pressure button & shutter functionality
Browse files Browse the repository at this point in the history
- Pressure button can be pressed with player & symbols
- shutter now blocks player if it is shut
- Add & modify sound effects
- Debug view is off by default
  • Loading branch information
copyrat90 committed Jun 22, 2021
1 parent b8f07e4 commit 894dfe2
Show file tree
Hide file tree
Showing 21 changed files with 241 additions and 120 deletions.
Binary file added audio/sfx_hover_button_toggle.wav
Binary file not shown.
File renamed without changes.
Binary file modified audio/sfx_symbol_drop.wav
Binary file not shown.
Binary file added audio/sfx_symbol_ground_bump.wav
Binary file not shown.
Binary file added audio/sfx_symbol_pickup.wav
Binary file not shown.
File renamed without changes.
Binary file modified graphics/bg_w0_s0_0.bmp
Binary file not shown.
67 changes: 31 additions & 36 deletions graphics_source/bg_w0_s0_0.tmx

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions include/constant.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@ constexpr bn::fixed music_rene = 0.2;
constexpr bn::fixed sfx_menu_cursor = SFX_DEFAULT;
constexpr bn::fixed sfx_menu_select = SFX_DEFAULT;
constexpr bn::fixed sfx_player_jump = SFX_DEFAULT;
constexpr bn::fixed sfx_symbol_bump = SFX_DEFAULT;
constexpr bn::fixed sfx_symbol_pickup = 0.5;
constexpr bn::fixed sfx_symbol_drop = SFX_DEFAULT;
constexpr bn::fixed sfx_symbol_wall_bump = SFX_DEFAULT;
constexpr bn::fixed sfx_symbol_ground_bump = SFX_DEFAULT;
constexpr bn::fixed sfx_symbol_throw = SFX_DEFAULT;
constexpr bn::fixed sfx_toggle_button = SFX_DEFAULT;
constexpr bn::fixed sfx_hover_button_toggle = SFX_DEFAULT;
constexpr bn::fixed sfx_pressure_button_toggle = SFX_DEFAULT;

constexpr bn::fixed ClampVolume(bn::fixed volume)
{
Expand Down
3 changes: 2 additions & 1 deletion include/game_system_PhysicsMovement.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ class PhysicsMovement final : public ISystem

void UpdateSymbols_();
void UpdateSymbolsInHands_();
void UpdateSymbolsOnFloor_();
void UpdateSymbolsOfCurrentZone_();
void UpdateSymbolsThrown_();
void SymbolCollision_(entity::Symbol&);

static constexpr int MAX_PLAYER_JUMP_COUNT = 1;
int playerJumpCount = MAX_PLAYER_JUMP_COUNT;
Expand Down
4 changes: 3 additions & 1 deletion include/game_system_TriggerInteraction.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,16 @@ class TriggerInteraction final : public ISystem
void PlayerPicksUpSymbol_(Hand interactHand, bn::ilist<entity::Symbol>::iterator symbolIter);
void PlayerPutsDownSymbol_(Hand hand);
void PlayerClicksHoverButton_(int hoverButtonIdx);
void InteractHoverButtonAndThrownSymbol_();
void InteractHoverButtonsAndThrownSymbol_();
void InteractPressureButtonsAndEntities_();

void UpdateKeyLastingCount_();
[[nodiscard]] bool IsLKeyPressLasts_() const;
[[nodiscard]] bool IsRKeyPressLasts_() const;
void ResetLKeyPress_();
void ResetRKeyPress_();
void ToggleOpenedHoverButtonAssociatedOpenables_(int hoverButtonIdx);
void ToggleOpenedPressureButtonAssociatedOpenables_(int pressureButtonIdx);
};

} // namespace sym::game::system
6 changes: 6 additions & 0 deletions license/sfx_hover_button_toggle.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Sound name : Click
Made by : complex_waveform
Link : https://freesound.org/people/complex_waveform/sounds/213148/
License : CC BY 3.0 (https://creativecommons.org/licenses/by/3.0/)

This sound is embedded into GBA, thus modified to 22050Hz, 8bit PCM.
File renamed without changes.
8 changes: 4 additions & 4 deletions license/sfx_symbol_drop.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Sound name : drop04.wav
Made by : newagesoup
Link : https://freesound.org/people/newagesoup/sounds/339358/
License : CC0 1.0 (https://creativecommons.org/publicdomain/zero/1.0/)
Sound name : Pop (made by DuffyBro)
Made by : DuffyBro
Link : https://freesound.org/people/DuffyBro/sounds/319107/
License : https://creativecommons.org/publicdomain/zero/1.0/

This sound is embedded into GBA, thus modified to 22050Hz, 8bit PCM.
6 changes: 6 additions & 0 deletions license/sfx_symbol_ground_bump.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Sound name : drop04.wav
Made by : newagesoup
Link : https://freesound.org/people/newagesoup/sounds/339358/
License : CC0 1.0 (https://creativecommons.org/publicdomain/zero/1.0/)

This sound is embedded into GBA, thus modified to 22050Hz, 8bit PCM.
6 changes: 6 additions & 0 deletions license/sfx_symbol_pickup.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Sound name : Bubble Pop
Made by : elmasmalo1
Link : https://freesound.org/people/elmasmalo1/sounds/376968/
License : CC BY 3.0 (https://creativecommons.org/licenses/by/3.0/)

This sound is embedded into GBA, thus modified to 22050Hz, 8bit PCM.
File renamed without changes.
25 changes: 10 additions & 15 deletions src/game_stage_W0_S0.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,28 @@ constexpr bn::size MAP_DIMENSIONS[] = {
};

constexpr ZoneInfo::SymbolInfo Z0_symbolInfos_[] = {
{{227 - MAP_DIMENSIONS[0].width() / 2, 927 - MAP_DIMENSIONS[0].height() / 2}, entity::Symbol::Type::BAR},
{{254 - MAP_DIMENSIONS[0].width() / 2, 927 - MAP_DIMENSIONS[0].height() / 2}, entity::Symbol::Type::XOR},
{{106 - MAP_DIMENSIONS[0].width() / 2, 974 - MAP_DIMENSIONS[0].height() / 2}, entity::Symbol::Type::BAR},
{{127 - MAP_DIMENSIONS[0].width() / 2, 974 - MAP_DIMENSIONS[0].height() / 2}, entity::Symbol::Type::XOR},
};

constexpr ZoneInfo::DoorInfo Z0_doorInfos_[] = {
{{87 - MAP_DIMENSIONS[0].width() / 2, 849 - MAP_DIMENSIONS[0].height() / 2}, false, -1, -1, 1},
{{55 - MAP_DIMENSIONS[0].width() / 2, 849 - MAP_DIMENSIONS[0].height() / 2}, true, -1, -1, 1},
{{87 - MAP_DIMENSIONS[0].width() / 2, 792 - MAP_DIMENSIONS[0].height() / 2}, false, -1, -1, 2},
{{55 - MAP_DIMENSIONS[0].width() / 2, 792 - MAP_DIMENSIONS[0].height() / 2}, true, -1, -1, 2},
{{124 - MAP_DIMENSIONS[0].width() / 2, 872 - MAP_DIMENSIONS[0].height() / 2}, false, -1, -1, 2},
};

constexpr ZoneInfo::ShutterInfo Z0_shutterInfos_[] = {
{{256 - MAP_DIMENSIONS[0].width() / 2, 792 - MAP_DIMENSIONS[0].height() / 2}, false, 0},
{{135 - MAP_DIMENSIONS[0].width() / 2, 849 - MAP_DIMENSIONS[0].height() / 2}, false, 1},
{{119 - MAP_DIMENSIONS[0].width() / 2, 849 - MAP_DIMENSIONS[0].height() / 2}, true, 1},
{{135 - MAP_DIMENSIONS[0].width() / 2, 792 - MAP_DIMENSIONS[0].height() / 2}, false, 2},
{{119 - MAP_DIMENSIONS[0].width() / 2, 792 - MAP_DIMENSIONS[0].height() / 2}, true, 2},
{{252 - MAP_DIMENSIONS[0].width() / 2, 928 - MAP_DIMENSIONS[0].height() / 2}, false, 0},
{{154 - MAP_DIMENSIONS[0].width() / 2, 872 - MAP_DIMENSIONS[0].height() / 2}, false, 1},
{{262 - MAP_DIMENSIONS[0].width() / 2, 928 - MAP_DIMENSIONS[0].height() / 2}, false, 3},
};

constexpr ZoneInfo::ButtonInfo Z0_hoverButtonInfos_[] = {
{{92 - MAP_DIMENSIONS[0].width() / 2, 962 - MAP_DIMENSIONS[0].height() / 2}, false, 0},
{{167 - MAP_DIMENSIONS[0].width() / 2, 849 - MAP_DIMENSIONS[0].height() / 2}, false, 1},
{{167 - MAP_DIMENSIONS[0].width() / 2, 792 - MAP_DIMENSIONS[0].height() / 2}, false, 2},
{{180 - MAP_DIMENSIONS[0].width() / 2, 974 - MAP_DIMENSIONS[0].height() / 2}, false, 0},
{{205 - MAP_DIMENSIONS[0].width() / 2, 870 - MAP_DIMENSIONS[0].height() / 2}, false, 2},
};

constexpr ZoneInfo::ButtonInfo Z0_pressureButtonInfos_[] = {
{{136 - MAP_DIMENSIONS[0].width() / 2, 984 - MAP_DIMENSIONS[0].height() / 2}, false, 3},
{{257 - MAP_DIMENSIONS[0].width() / 2, 856 - MAP_DIMENSIONS[0].height() / 2}, false, 1},
{{210 - MAP_DIMENSIONS[0].width() / 2, 936 - MAP_DIMENSIONS[0].height() / 2}, false, 3},
};

constexpr ZoneInfo::ExitInfo Z0_exitInfos_[] = {
Expand Down
158 changes: 101 additions & 57 deletions src/game_system_PhysicsMovement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <bn_math.h>
#include <bn_optional.h>

#include "bn_vector.h"
#include "helper_keypad.h"
#include "helper_math.h"
#include "helper_tilemap.h"
Expand Down Expand Up @@ -193,6 +194,41 @@ enum class PushbackDirection
return bn::nullopt;
}

/**
* @brief Detect and Resolve colision.
* You need to call this once again, if if returns value other than `bn::nullopt`.
*
*/
[[nodiscard]] bn::optional<PushbackDirection> ShuttersCollisionResolution_(
entity::IPhysicsEntity& entity, bn::vector<entity::Shutter, scene::GameState::ZONE_SHUTTER_MAX_COUNT>& shutters)
{
for (const auto& shutter : shutters)
{
bn::fixed_rect entityCollider = entity.GetPhysicsCollider();
const bn::fixed_rect shutterCollider = shutter.GetInteractRange();
if (shutter.GetOpened())
continue;
if (!entityCollider.intersects(shutterCollider))
continue;

if (entityCollider.position().x() <= shutterCollider.position().x())
{
const bn::fixed dx = entityCollider.right() - shutterCollider.left();
entity.SetX(entity.GetX() - dx);
entity.SetXVelocity(0);
return PushbackDirection::LEFT;
}
else
{
const bn::fixed dx = shutterCollider.right() - entityCollider.left();
entity.SetX(entity.GetX() + dx);
entity.SetXVelocity(0);
return PushbackDirection::RIGHT;
}
}
return bn::nullopt;
}

void ApplyGravity_(entity::IPhysicsEntity& entity)
{
bn::fixed_point velocity = entity.GetVelocity();
Expand All @@ -216,59 +252,6 @@ void ClampVelocity_(entity::IPhysicsEntity& entity)
entity.SetVelocity(velocity);
}

void SymbolCollision_(entity::Symbol& symbol, const helper::tilemap::TileInfo& mapTileInfo,
const effect::Transition& fadeIn)
{
bn::optional<PushbackDirection> collisionResult;
bool nextGrounded = false;
for (int i = 0; i < COLLISION_LOOP_MAX_COUNT; ++i)
{
collisionResult = PlatformCollisionResolution_(symbol, mapTileInfo);
if (!collisionResult)
break;
switch (*collisionResult)
{
case PushbackDirection::UP:
if (!nextGrounded)
{
nextGrounded = true;
if (!symbol.GetGrounded())
{
if (fadeIn.GetState() != effect::Transition::State::ONGOING)
bn::sound_items::sfx_symbol_drop.play();
}
}
break;
case PushbackDirection::DOWN:
case PushbackDirection::LEFT:
case PushbackDirection::RIGHT:
if (!symbol.GetGravityEnabled())
{
symbol.SetThrown(false);
symbol.SetGravityEnabled(true);
bn::sound_items::sfx_symbol_bump.play();
}
break;
default:
BN_ERROR("Invalid PushbackDirection: ", static_cast<int>(*collisionResult));
}
if (i == COLLISION_LOOP_MAX_COUNT - 1)
BN_LOG("[WARN] Collision detection loop max count reached!");
}
symbol.SetGrounded(nextGrounded);
}

void UpdateSymbolOnFloor_(entity::Symbol& symbol, const helper::tilemap::TileInfo& mapTileInfo,
const effect::Transition& fadeIn)
{
ApplyGravity_(symbol);

ClampVelocity_(symbol);
symbol.SetPosition(symbol.GetPosition() + symbol.GetVelocity());

SymbolCollision_(symbol, mapTileInfo, fadeIn);
}

} // namespace

PhysicsMovement::PhysicsMovement(scene::GameState& state) : ISystem(state)
Expand Down Expand Up @@ -331,9 +314,17 @@ void PhysicsMovement::PlayerCollision_()
bool nextGrounded = false;
for (int i = 0; i < COLLISION_LOOP_MAX_COUNT; ++i)
{
// resolve collision
collisionResult = PlatformCollisionResolution_(state_.player, state_.currentMapTileInfo);
if (!collisionResult)
break;
{
collisionResult =
ShuttersCollisionResolution_(state_.player, state_.shuttersOfZones[state_.currentZoneIdx]);
if (!collisionResult)
break;
}

// additional work to do when collision is detected
switch (*collisionResult)
{
case PushbackDirection::UP:
Expand Down Expand Up @@ -398,7 +389,7 @@ void PhysicsMovement::PlayerAnimation_()
void PhysicsMovement::UpdateSymbols_()
{
UpdateSymbolsInHands_();
UpdateSymbolsOnFloor_();
UpdateSymbolsOfCurrentZone_();
UpdateSymbolsThrown_();
}

Expand All @@ -414,12 +405,65 @@ void PhysicsMovement::UpdateSymbolsInHands_()
}
}

void PhysicsMovement::UpdateSymbolsOnFloor_()
void PhysicsMovement::UpdateSymbolsOfCurrentZone_()
{
for (auto& symbol : state_.symbolsOfZones[state_.currentZoneIdx])
{
UpdateSymbolOnFloor_(symbol, state_.currentMapTileInfo, state_.fadeIn);
ApplyGravity_(symbol);

ClampVelocity_(symbol);
symbol.SetPosition(symbol.GetPosition() + symbol.GetVelocity());

SymbolCollision_(symbol);
}
}

void PhysicsMovement::SymbolCollision_(entity::Symbol& symbol)
{
bn::optional<PushbackDirection> collisionResult;
bool nextGrounded = false;
for (int i = 0; i < COLLISION_LOOP_MAX_COUNT; ++i)
{
// resolve collision
collisionResult = PlatformCollisionResolution_(symbol, state_.currentMapTileInfo);
if (!collisionResult)
{
collisionResult = ShuttersCollisionResolution_(symbol, state_.shuttersOfZones[state_.currentZoneIdx]);
if (!collisionResult)
break;
}

// additional work to do when collision is detected
switch (*collisionResult)
{
case PushbackDirection::UP:
if (!nextGrounded)
{
nextGrounded = true;
if (!symbol.GetGrounded())
{
if (state_.fadeIn.GetState() != effect::Transition::State::ONGOING)
bn::sound_items::sfx_symbol_ground_bump.play(constant::volume::sfx_symbol_ground_bump);
}
}
break;
case PushbackDirection::DOWN:
case PushbackDirection::LEFT:
case PushbackDirection::RIGHT:
if (!symbol.GetGravityEnabled())
{
symbol.SetThrown(false);
symbol.SetGravityEnabled(true);
bn::sound_items::sfx_symbol_wall_bump.play(constant::volume::sfx_symbol_wall_bump);
}
break;
default:
BN_ERROR("Invalid PushbackDirection: ", static_cast<int>(*collisionResult));
}
if (i == COLLISION_LOOP_MAX_COUNT - 1)
BN_LOG("[WARN] Collision detection loop max count reached!");
}
symbol.SetGrounded(nextGrounded);
}

void PhysicsMovement::UpdateSymbolsThrown_()
Expand Down
Loading

0 comments on commit 894dfe2

Please sign in to comment.