From d63ab558e4c74d5ff8fdee31769b4d7ecf147212 Mon Sep 17 00:00:00 2001 From: Charpurrr Date: Sun, 1 Sep 2024 21:44:49 +0200 Subject: [PATCH] FLUDD, First Steps - Added the FluddManager class that handles the nozzle types, the available nozzles, and the active nozzle. - Added a way to switch between FLUDD nozzles. (Code only, no implementation) - Gave every PlayerState a reference to the FluddManager through a descendant line. (See PlayerStateManager) --- .../rmsmartshape/materials/shape_material.gd | 2 +- entities/player/mario/mario.tscn | 28 +++++++--------- entities/player/shared/fludd_manager.gd | 33 +++++++++++++++++++ .../player/shared/player_state_manager.gd | 2 ++ .../dry/airborne/fall_states/water_exit.gd | 20 ----------- .../shared/states/dry/airborne/lazy_jump.gd | 26 +++++++++++++++ entities/player/shared/states/dry/dry.gd | 2 +- entities/player/shared/states/player_state.gd | 5 +-- project.godot | 10 ++++++ ui/ui.tscn | 11 +++---- 10 files changed, 93 insertions(+), 46 deletions(-) create mode 100644 entities/player/shared/fludd_manager.gd delete mode 100644 entities/player/shared/states/dry/airborne/fall_states/water_exit.gd create mode 100644 entities/player/shared/states/dry/airborne/lazy_jump.gd diff --git a/addons/rmsmartshape/materials/shape_material.gd b/addons/rmsmartshape/materials/shape_material.gd index e77955c..76290c6 100644 --- a/addons/rmsmartshape/materials/shape_material.gd +++ b/addons/rmsmartshape/materials/shape_material.gd @@ -136,4 +136,4 @@ func set_fill_texture_angle_offset(value: float) -> void: func set_fill_texture_absolute_position(value: bool) -> void: fill_texture_absolute_position = value - emit_changed() \ No newline at end of file + emit_changed() diff --git a/entities/player/mario/mario.tscn b/entities/player/mario/mario.tscn index 8c9c941..6686c47 100644 --- a/entities/player/mario/mario.tscn +++ b/entities/player/mario/mario.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=363 format=3 uid="uid://dgqp3sqvmcvpu"] +[gd_scene load_steps=364 format=3 uid="uid://dgqp3sqvmcvpu"] [ext_resource type="Script" path="res://entities/player/shared/player.gd" id="1_87j6i"] [ext_resource type="Texture2D" uid="uid://bbgppbst4akvn" path="res://entities/player/mario/anime/backflip.png" id="2_i2o54"] @@ -129,7 +129,7 @@ [ext_resource type="Script" path="res://entities/player/shared/states/dry/airborne/fall_states/fall.gd" id="113_j3k6p"] [ext_resource type="Script" path="res://entities/player/shared/states/dry/airborne/fall_states/freefall.gd" id="114_mgnux"] [ext_resource type="AudioStream" uid="uid://1fibybjdw7pc" path="res://entities/player/shared/motion_nsmbw/groundpound.wav" id="116_078t4"] -[ext_resource type="Script" path="res://entities/player/shared/states/dry/airborne/fall_states/water_exit.gd" id="116_wolak"] +[ext_resource type="Script" path="res://entities/player/shared/states/dry/airborne/lazy_jump.gd" id="116_wolak"] [ext_resource type="AudioStream" uid="uid://23at2s4l6qjv" path="res://entities/player/mario/voice/watch_it.wav" id="120_qvxml"] [ext_resource type="AudioStream" uid="uid://lktt3ecwf5nm" path="res://entities/player/mario/voice/oh_surprised.wav" id="121_se657"] [ext_resource type="AudioStream" uid="uid://udnnj6t7h54x" path="res://entities/player/mario/voice/mhpm.wav" id="122_r00kr"] @@ -150,6 +150,7 @@ [ext_resource type="AudioStream" uid="uid://bbw3474fd3uxc" path="res://entities/player/shared/motion/spinattack_shine.wav" id="136_a6kal"] [ext_resource type="AudioStream" uid="uid://bowyc14wpkcra" path="res://entities/player/shared/motion/dive.wav" id="138_88upi"] [ext_resource type="Script" path="res://entities/player/shared/states/dry/butt_slide.gd" id="140_lfmwr"] +[ext_resource type="Script" path="res://entities/player/shared/fludd_manager.gd" id="151_4womg"] [sub_resource type="AtlasTexture" id="AtlasTexture_8n85e"] atlas = ExtResource("2_i2o54") @@ -2030,6 +2031,9 @@ target_position = Vector2(-9, 0) script = ExtResource("21_onm15") buffer_duration = 6 +[node name="FluddManager" type="Node" parent="."] +script = ExtResource("151_4womg") + [node name="Movement" type="Node" parent="." node_paths=PackedStringArray("actor")] script = ExtResource("37_quca3") actor = NodePath("..") @@ -2040,12 +2044,8 @@ snap_length = 8.0 swim_speed = 3.0 min_slide_incline = 0.4 -[node name="StateManager" type="Node" parent="." node_paths=PackedStringArray("input", "movement", "target_actor", "initial_state")] +[node name="StateManager" type="Node" parent="."] script = ExtResource("38_vxs65") -input = NodePath("../InputManager") -movement = NodePath("../Movement") -target_actor = NodePath("..") -initial_state = NodePath("Dry/Airborne") [node name="Submerged" type="Node" parent="StateManager"] script = ExtResource("135_2utkk") @@ -2191,6 +2191,11 @@ animation = &"triple_jump" anim_offset = Vector2i(0, 5) sfx_layers = Array[ExtResource("49_apkmk")]([SubResource("Resource_c6n5s"), SubResource("Resource_0beus"), SubResource("Resource_32052")]) +[node name="LazyJump" type="Node" parent="StateManager/Dry/Airborne/JumpStates"] +script = ExtResource("116_wolak") +animation = &"jump" +anim_offset = Vector2i(0, 5) + [node name="Spinjump" type="Node" parent="StateManager/Dry/Airborne/JumpStates"] script = ExtResource("92_pwmyp") jump_power = 6.7 @@ -2275,13 +2280,6 @@ script = ExtResource("114_mgnux") animation = &"freefall" sfx_layers = Array[ExtResource("49_apkmk")]([SubResource("Resource_5kqsg")]) -[node name="WaterExit" type="Node" parent="StateManager/Dry/Airborne/FallStates"] -script = ExtResource("116_wolak") -animation_jump = &"jump" -anim_offset_j = Vector2(0, 5) -animation = &"jump_fall" -anim_offset = Vector2i(0, 5) - [node name="DoubleFall" type="Node" parent="StateManager/Dry/Airborne/FallStates"] script = ExtResource("113_j3k6p") animation = &"double_fall" @@ -2358,6 +2356,4 @@ animation_airborne = &"butt_slide_jump" hitbox_type = "Small" animation = &"butt_slide" -[node name="FluddManager" type="Node" parent="."] - [connection signal="body_entered" from="Areas/SpinHitbox" to="StateManager/Dry/Spin" method="_on_spin_hitbox_body_entered"] diff --git a/entities/player/shared/fludd_manager.gd b/entities/player/shared/fludd_manager.gd new file mode 100644 index 0000000..76d1ef0 --- /dev/null +++ b/entities/player/shared/fludd_manager.gd @@ -0,0 +1,33 @@ +class_name FluddManager +extends Node +## Handles communication between PlayerStates in regards to FLUDD. + +enum Nozzle{ + NONE, + HOVER, + ROCKET, + TURBO, +} + +var available_nozzles: Array[Nozzle] = [ + Nozzle.NONE, + Nozzle.HOVER, + #Nozzle.ROCKET, + #Nozzle.TURBO, + ] + +var active_nozzle: Nozzle = Nozzle.NONE + + +# Done within physics process to guarantee being properly synced with the player. +func _physics_process(_delta: float) -> void: + if Input.is_action_just_pressed(&"switch_nozzle"): + switch_nozzle() + + +func switch_nozzle() -> void: + var current_id: int = available_nozzles.find(active_nozzle) + + active_nozzle = available_nozzles[wrapi(current_id + 1, 0, available_nozzles.size())] + + print(Nozzle.find_key(active_nozzle)) diff --git a/entities/player/shared/player_state_manager.gd b/entities/player/shared/player_state_manager.gd index 223cec8..661f2a1 100644 --- a/entities/player/shared/player_state_manager.gd +++ b/entities/player/shared/player_state_manager.gd @@ -4,11 +4,13 @@ extends StateManager ## Adds player specialised variables and functions. @export var input: InputManager +@export var fludd: FluddManager @export var movement: PMovement func _custom_passdowns() -> Dictionary: return { &"input": input, + &"fludd": fludd, &"movement": movement, } diff --git a/entities/player/shared/states/dry/airborne/fall_states/water_exit.gd b/entities/player/shared/states/dry/airborne/fall_states/water_exit.gd deleted file mode 100644 index 9b8a130..0000000 --- a/entities/player/shared/states/dry/airborne/fall_states/water_exit.gd +++ /dev/null @@ -1,20 +0,0 @@ -class_name WaterExit -extends Fall -## Exiting a body of water by normal means. (Not by spinning) - -@export_category(&"Animation (Unique to State)") -@export var animation_jump: StringName -@export var anim_offset_j: Vector2 - - -func _physics_tick(): - _set_appropriate_anim() - super() - - -## Sets either the jumping or falling animation depending on velocity. -func _set_appropriate_anim(): - if actor.vel.y < 0: - actor.doll.play(animation_jump) - else: - actor.doll.play(animation) diff --git a/entities/player/shared/states/dry/airborne/lazy_jump.gd b/entities/player/shared/states/dry/airborne/lazy_jump.gd new file mode 100644 index 0000000..87dac9f --- /dev/null +++ b/entities/player/shared/states/dry/airborne/lazy_jump.gd @@ -0,0 +1,26 @@ +class_name LazyJump +extends Fall +## A jump that doesn't give you any height. +## Used for actions that look like jumps but don't act like them. + + +func _trans_rules() -> Variant: + if not movement.dived and movement.can_air_action() and input.buffered_input(&"dive"): + return &"Dive" + + if movement.can_spin() and input.buffered_input(&"spin"): + return &"Spin" + + if Input.is_action_just_pressed(&"groundpound") and movement.can_air_action(): + return &"GroundPound" + + if actor.push_rays.is_colliding() and input.buffered_input(&"jump"): + return [&"Walljump", -movement.facing_direction] + + if movement.can_init_wallslide(): + return &"Wallslide" + + if actor.vel.y > 0: + return &"Fall" + + return &"" diff --git a/entities/player/shared/states/dry/dry.gd b/entities/player/shared/states/dry/dry.gd index 16c5d72..c660b5b 100644 --- a/entities/player/shared/states/dry/dry.gd +++ b/entities/player/shared/states/dry/dry.gd @@ -16,4 +16,4 @@ func _trans_rules(): func _defer_rules(): - return &"WaterExit" + return &"LazyJump" diff --git a/entities/player/shared/states/player_state.gd b/entities/player/shared/states/player_state.gd index 2bb25fc..0e906d3 100644 --- a/entities/player/shared/states/player_state.gd +++ b/entities/player/shared/states/player_state.gd @@ -19,8 +19,9 @@ extends State ## sound effects it can cycle through. @export var sfx_layers: Array[SFXLayer] -@onready var input: InputManager = null -@onready var movement: PMovement = null +var input: InputManager = null +var fludd: FluddManager = null +var movement: PMovement = null func trigger_enter(handover): diff --git a/project.godot b/project.godot index b47949a..e012376 100644 --- a/project.godot +++ b/project.godot @@ -178,6 +178,16 @@ e_pin_hotbar_item={ "events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":1,"canceled":false,"pressed":false,"double_click":false,"script":null) ] } +switch_nozzle={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":67,"key_label":0,"unicode":99,"location":0,"echo":false,"script":null) +] +} +use_fludd={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":32,"key_label":0,"unicode":32,"location":0,"echo":false,"script":null) +] +} [layer_names] diff --git a/ui/ui.tscn b/ui/ui.tscn index 650a1e4..2620f1f 100644 --- a/ui/ui.tscn +++ b/ui/ui.tscn @@ -1948,7 +1948,6 @@ layout_mode = 2 texture = ExtResource("5_cgoe6") [node name="PauseScreen" type="Control" parent="." node_paths=PackedStringArray("choices", "pause_menu", "settings_menu")] -visible = false layout_mode = 3 anchors_preset = 15 anchor_right = 1.0 @@ -2340,22 +2339,22 @@ texture = ExtResource("19_wa1aj") expand_mode = 1 stretch_mode = 5 -[node name="Turbo" type="TextureRect" parent="PauseScreen/PauseMenu/Info/Contents/Bottom/ActiveNozzles/Icons"] +[node name="Rocket" type="TextureRect" parent="PauseScreen/PauseMenu/Info/Contents/Bottom/ActiveNozzles/Icons"] modulate = Color(0, 0, 0, 1) layout_mode = 2 size_flags_horizontal = 3 size_flags_vertical = 3 -texture = ExtResource("20_yd3bl") +texture = ExtResource("21_xk5tc") expand_mode = 1 stretch_mode = 5 -[node name="Rocket" type="TextureRect" parent="PauseScreen/PauseMenu/Info/Contents/Bottom/ActiveNozzles/Icons"] +[node name="Turbo" type="TextureRect" parent="PauseScreen/PauseMenu/Info/Contents/Bottom/ActiveNozzles/Icons"] modulate = Color(0, 0, 0, 1) layout_mode = 2 size_flags_horizontal = 3 size_flags_vertical = 3 -size_flags_stretch_ratio = 0.5 -texture = ExtResource("21_xk5tc") +size_flags_stretch_ratio = 0.7 +texture = ExtResource("20_yd3bl") expand_mode = 1 stretch_mode = 5