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

Download .gba file


Select : Enable/Disable debug view

Arrow : Move

: 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

Leave a comment

Log in with itch.io to leave a comment.