Spikes will hurt you
Day 38-44
English isn't my first language, so I might write some broken English.
OMG, the GBA Jam 2021 ends in just 12 days!
I think I can't even manage to implement necessary features...
I need to work hard from now on.
Anyways, this week I got spikes working!
1. Spike collision detection
2. Write a global transition manager, game::system::Transition.
Now I can assign events to the system::Transition, and they will be callback-ed on same-named transition phase.
This way, I don't need to busy-loop check if the transition is done or not.
I'm now also using the system when moving to another zone, and it's clear that this callback approach has significantly reduced the amount of code than using busy-loop check.
[Worse] Busy-loop check
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | void ZoneSwitch::UpdateNextZone_() { switch (exitFadeState_) { case ExitFadeState::NOT_STARTED: exitFadeState_ = ExitFadeState::FADE_OUT; state_.fadeOut.Init(); state_.player.SetControllable(false); break; case ExitFadeState::FADE_OUT: if (state_.fadeOut.GetState() == Transition::State::DONE) { exitFadeState_ = ExitFadeState::FADE_IN; SwitchToNextZone_(); state_.fadeIn.Init(); state_.player.SetControllable(true); } break; case ExitFadeState::FADE_IN: if (state_.fadeIn.GetState() == Transition::State::DONE) { exitFadeState_ = ExitFadeState::NOT_STARTED; nextZone_.reset(); } break; default: BN_ERROR("Invalid ExitState: ", static_cast<int>(exitFadeState_)); break; } } | cs |
I had to constantly call this ZoneSwitch::UpdateNextZone_() function above.
and there's this dirty switch-case checks of the current transition states.
[Better] Callback
1 2 3 4 5 6 7 8 9 10 11 | void ZoneSwitch::InitTransition_() { state_.player.SetControllable(false); state_.transition.SetBlendingAppliedItems(Transition::AppliedItems::ALL); state_.transition.SetMosaicAppliedItems(Transition::AppliedItems::ALL); state_.transition.InitOutAndIn(TRANSITION_TYPES, FADE_OUT_UPDATE_COUNT, FADE_IN_UPDATE_COUNT); state_.transition.SetWaitBetweenEventHandler([this] { SwitchToNextZone_(); }); state_.transition.SetLastTransitionEventHandler([this] { state_.player.SetControllable(true); }); state_.transition.SetDoneEventHandler([this] { nextZone_.reset(); }); } | cs |
Now, I don't need to do it.
I just call the function above only once, which has the same functionality.
and the state_.transition automatically callbacks the EventHandlers I assigned here on each transition states.
Wonder how the state_.transition implemented the callback?
See this header and this source file.
Basically, using the std::function from the standard library,
you can store a Callable - anything that can be called with operator() as a variable.
and I'm calling this variable when the execution reaches the certain transition state.
And according to a small snippet I made, including <functional> takes up 1.2KB of memory, which is huge for GBA, but still manageable.
3. Respawn to a safe position
The 'Safe position' is the last position player was standing on.
GitHub tag : Day-44
Select : Enable/Disable debug view
Arrow : Move
A : jump
L / R :
1. pick-up an item in Left/Right hand
2. toggle switch on the wall with Left/Right hand
↓ + L / R : put down the item in Left/Right hand
Get Symbol★Merged
Symbol★Merged
[Demo] A puzzle platformer game for GBA where you can merge items in hands, and use its superpower.
Status | In development |
Author | copyrat90 |
Genre | Puzzle, Platformer |
Tags | Game Boy Advance, gbajam, gbajam2021, Puzzle-Platformer |
More posts
- Demo released!Jul 11, 2021
- Turning into a gameJun 22, 2021
- Platforming physicsJun 14, 2021
- Open the doors, please.Jun 09, 2021
- Edge-snapping cameraJun 03, 2021
- Displaying itemsMay 30, 2021
- Rudimentary Title screenMay 23, 2021
- Refactoring transitionMay 20, 2021
- Let's start the journey!May 17, 2021
Leave a comment
Log in with itch.io to leave a comment.