Posted June 09, 2021 by copyrat90
Day 19-24
English isn't my first language, so I might write some broken English.
Every game needs some kind of interaction to call it a game.
So what interaction have I implemented?
1. Functionality to open doors with pressing buttons!
The above gif image shows everything. (except for the button click sound effect)
How does it work?
Well, it's complicated:
I have these blue IEntity-derived classes, and they store some datas. (including sprite & animations)
For example...
entity::Player class stores sprites and animations of our protagonist star character.
It also stores some collider infos (i.e. rects and points) shown above.
In the scene::Game lie ISystem-derived objects,
which are responsible for updating the IEntity datas within the Game scene.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | // scene_Game.h class Game final : public IScene { public: ... [[nodiscard]] bn::optional<Type> Update() final; private: ... // All member variables reside in here. // to easily pass states by reference into Systems. GameState state_; system::PlayerMovement playerMovement_; system::ButtonInteraction buttonInteraction_; ... }; | cs |
I have this GameState variable which holds all the members (including Entities) of the Game scene,
and it is passed by reference to each Systems.
And each System updates the GameState.
1 2 3 4 5 6 | bn::optional<Type> Game::Update() { playerMovement_.Update(); buttonInteraction_.Update(); ... } | cs |
I think this approach is not the greatest, but it somewhat modularizes the code to the managable state.
Hey, but you've never mentioned how does the button works!
Yup, but it would make this article at least 4 times more long...
So I'll just call it a day now. Sorry.
You can always check my source code on GitHub, if you want.
GitHub tag : Day-24
Select : Enable/Disable debug view
L : use Left hand / R : use Right hand