TeamHypersomnia / Hypersomnia

Multiplayer top-down shooter made from scratch in C++. Play in your Browser! https://hypersomnia.io Made in 🇵🇱
https://hypersomnia.io/
GNU Affero General Public License v3.0
1.08k stars 47 forks source link

Reimplement recoil_player and put it to use with a sample assault rifle #240

Closed geneotech closed 6 years ago

geneotech commented 7 years ago

There should be two structures: recoil_player (global scope) Has a vector of recoil impulses and a parameter for the duration it takes the cooldown to descend from one impulse to the previous. Is an asset. Its get_logical_meta(const assets_manager& manager) const shall return the recoil_player itself as a copy. Has a corresponding assets::recoil_player_id defined.

recoil_player_instance (global scope) Keeps data that determines the index of the value to be returned as the next impulse. Has methods like: float shoot_and_get_impulse(const recoil_player& meta); void cooldown(float amount_ms);

If the next impulse is out of bounds, it should return a random value seeded after the current heat.

Add recoil_player_instance and assets::recoil_player_id to components::gun and take use of it in the gun_system.cpp where the force applied upon shot is always in the same direction ( if (total_recoil_amount > 0.f) { ... } ). Hint: the recoil player will be obtained by step.input.metas_of_assets.find. If it returns null pointer (player not found), apply no recoil at all.

Note: this might be easier to tweak once we have the editor GUI. Hint: use minimal_scene.cpp (former name: one_entity.cpp) and debug_minimal_test_scene = true in config for maximum performance in Debug mode.

geneotech commented 7 years ago

physical_material struct follows a very similar schema to recoil_player (regarding assets and ids, though no instances of materials), and is used to generate collision sounds in sound_existence_system::create_sounds_from_game_events

geneotech commented 7 years ago

Updated preferred file locations:

src/game/assets/recoil_player_id.h
src/game/assets/recoil_player.h
src/game/assets/recoil_player.cpp
DaTa- commented 7 years ago

I have following issues which render last task related commit incomplete:

geneotech commented 7 years ago
                        recoil_body.apply_angular_impulse(
                            total_recoil_amount * recoil_body.get_inertia() * 10.f
                        );

And apart from cooldown, that should be all change that's needed in gun_system.cpp.

The signature should be thus: float shoot_and_get_impulse(const recoil_player& meta); (I've just copy-derped the previous one)

The rotation of the character's CROSSHAIR_RECOIL_BODY determines the angle by which to rotate the character itself, which effectively simulates a recoil effect.

geneotech commented 7 years ago

The cooldown should also happen in an else to this condition:

            if (
                gun.is_trigger_pressed 
                && has_enough_mana
                && has_enough_physical_bullets
                && gun.shot_cooldown.try_to_fire_and_reset(cosmos.get_timestamp(), delta)
            ) {
geneotech commented 6 years ago

Implementation is complete.