diff --git a/scenes/molikman.tscn b/scenes/molikman.tscn index 3646fd8..6363e96 100644 --- a/scenes/molikman.tscn +++ b/scenes/molikman.tscn @@ -268,23 +268,23 @@ script = ExtResource("8_f1ej7") current_state = NodePath("Stand") metadata/_custom_type_script = "uid://3777rkbebgjm" -[node name="Crouch" type="Node" parent="BodyStateMachine" node_paths=PackedStringArray("stand_up_area", "player", "animation_player")] +[node name="Crouch" type="Node" parent="BodyStateMachine" node_paths=PackedStringArray("stand_up_area", "player", "animation_player", "weapon_system")] script = ExtResource("9_oprun") -SPEED = 3.125 stand_up_area = NodePath("../../StandArea") player = NodePath("../..") animation_player = NodePath("../../AnimationPlayer") +weapon_system = NodePath("../../WeaponSystem") -[node name="Stand" type="Node" parent="BodyStateMachine" node_paths=PackedStringArray("player")] +[node name="Stand" type="Node" parent="BodyStateMachine" node_paths=PackedStringArray("player", "weapon_system")] script = ExtResource("10_a8ls1") -SPEED = 6.25 JUMP_VELOCITY = 6.0 player = NodePath("../..") +weapon_system = NodePath("../../WeaponSystem") -[node name="Walk" type="Node" parent="BodyStateMachine" node_paths=PackedStringArray("player")] +[node name="Walk" type="Node" parent="BodyStateMachine" node_paths=PackedStringArray("player", "weapon_system")] script = ExtResource("11_qfm1y") -SPEED = 3.125 player = NodePath("../..") +weapon_system = NodePath("../../WeaponSystem") [node name="Fall" type="Node" parent="BodyStateMachine" node_paths=PackedStringArray("player")] script = ExtResource("12_fulsm") diff --git a/scenes/weapons/starting_pistol.tscn b/scenes/weapons/starting_pistol.tscn index da2274e..e48267f 100644 --- a/scenes/weapons/starting_pistol.tscn +++ b/scenes/weapons/starting_pistol.tscn @@ -24,6 +24,7 @@ animation_prefix = &"baked_sp_" droppable = &"uid://dgfqppi21c2u0" visibility_target = &"sp" max_ammo = 20 +speed_modifier = 0.9 slot = &"secondary" enter_state = NodePath("Intro") metadata/_custom_type_script = "uid://e6lqknfl4ngt" diff --git a/scripts/player/states/crouching.gd b/scripts/player/states/crouching.gd index a6ecf12..f4b782c 100644 --- a/scripts/player/states/crouching.gd +++ b/scripts/player/states/crouching.gd @@ -1,11 +1,12 @@ extends State -@export var SPEED: float = 2.5 +@export var speed: float = 2.5 @export var toggle: bool = false @export var stand_up_area: Area3D @export var player: Player @export var animation_player: AnimationPlayer @export var crouch_time: float = 0.1 +@export var weapon_system: WeaponSystem func enter() -> void: animation_player.play("crouch",-1,1/crouch_time) @@ -26,12 +27,13 @@ func physics_update(_delta: float) -> void: var input_dir := Input.get_vector("plr_strafe_r","plr_strafe_l", "plr_back","plr_forward") var direction := (player.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized() + var modified_speed = speed * weapon_system.get_speed_modifier() if direction: - player.velocity.x = direction.x * SPEED - player.velocity.z = direction.z * SPEED + player.velocity.x = direction.x * modified_speed + player.velocity.z = direction.z * modified_speed else: - player.velocity.x = move_toward(player.velocity.x, 0, SPEED) - player.velocity.z = move_toward(player.velocity.z, 0, SPEED) + player.velocity.x = move_toward(player.velocity.x, 0, modified_speed) + player.velocity.z = move_toward(player.velocity.z, 0, modified_speed) func state_input(event: InputEvent) -> void: if (toggle == true and event.is_action_pressed("plr_crouch")) or (toggle == false and event.is_action_released("plr_crouch")): diff --git a/scripts/player/states/standing.gd b/scripts/player/states/standing.gd index 3388958..645cac8 100644 --- a/scripts/player/states/standing.gd +++ b/scripts/player/states/standing.gd @@ -1,8 +1,9 @@ extends State -@export var SPEED: float = 5.0 +@export var speed: float = 5.0 @export var JUMP_VELOCITY: float = 4.5 @export var player: Player +@export var weapon_system: WeaponSystem func enter() -> void: pass @@ -24,12 +25,13 @@ func physics_update(_delta: float) -> void: var input_dir := Input.get_vector("plr_strafe_r","plr_strafe_l", "plr_back","plr_forward") var direction := (player.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized() + var modified_speed := speed * weapon_system.get_speed_modifier() if direction: - player.velocity.x = direction.x * SPEED - player.velocity.z = direction.z * SPEED + player.velocity.x = direction.x * modified_speed + player.velocity.z = direction.z * modified_speed else: - player.velocity.x = move_toward(player.velocity.x, 0, SPEED) - player.velocity.z = move_toward(player.velocity.z, 0, SPEED) + player.velocity.x = move_toward(player.velocity.x, 0, modified_speed) + player.velocity.z = move_toward(player.velocity.z, 0, modified_speed) func state_input(event: InputEvent) -> void: if event.is_action_pressed("plr_crouch"): diff --git a/scripts/player/states/walk.gd b/scripts/player/states/walk.gd index 2cff863..7e1b901 100644 --- a/scripts/player/states/walk.gd +++ b/scripts/player/states/walk.gd @@ -1,8 +1,9 @@ extends State -@export var SPEED: float = 2.5 +@export var speed: float = 2.5 @export var JUMP_VELOCITY: float = 4.5 @export var player: Player +@export var weapon_system: WeaponSystem func enter() -> void: pass @@ -24,12 +25,13 @@ func physics_update(_delta: float) -> void: var input_dir := Input.get_vector("plr_strafe_r","plr_strafe_l", "plr_back","plr_forward") var direction := (player.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized() + var modified_speed = speed * weapon_system.get_speed_modifier() if direction: - player.velocity.x = direction.x * SPEED - player.velocity.z = direction.z * SPEED + player.velocity.x = direction.x * modified_speed + player.velocity.z = direction.z * modified_speed else: - player.velocity.x = move_toward(player.velocity.x, 0, SPEED) - player.velocity.z = move_toward(player.velocity.z, 0, SPEED) + player.velocity.x = move_toward(player.velocity.x, 0, modified_speed) + player.velocity.z = move_toward(player.velocity.z, 0, modified_speed) func state_input(event: InputEvent) -> void: if event.is_action_released("plr_walk"): diff --git a/scripts/weapon_system/bomb/bomb_state.gd b/scripts/weapon_system/bomb/bomb_state.gd index a9cc27a..11ef0ad 100644 --- a/scripts/weapon_system/bomb/bomb_state.gd +++ b/scripts/weapon_system/bomb/bomb_state.gd @@ -5,9 +5,11 @@ const active_bomb: StringName = "uid://dtbpyfdawb02b" func enter(): machine.animation_player.play(machine.animation_prefix+"plant") machine.animation_player.animation_finished.connect(on_animation_finished) + machine.speed_modifier = 0.0 func exit(): machine.animation_player.animation_finished.disconnect(on_animation_finished) + machine.speed_modifier = 1.0 func on_animation_finished(animation: StringName): if animation == machine.animation_prefix + "plant": diff --git a/scripts/weapon_system/weapon_substate_machine.gd b/scripts/weapon_system/weapon_substate_machine.gd index c88ecda..1cc4aa0 100644 --- a/scripts/weapon_system/weapon_substate_machine.gd +++ b/scripts/weapon_system/weapon_substate_machine.gd @@ -10,6 +10,8 @@ class_name WeaponSubStateMachine @onready var ammo: int = max_ammo @onready var remaining_ammo: int = max_ammo * 3 +@export var speed_modifier: float = 1.0 + @export var can_be_previous: bool = true @export var destroy_when_empty: bool = false diff --git a/scripts/weapon_system/weapon_system.gd b/scripts/weapon_system/weapon_system.gd index 34e5a59..92c2eba 100644 --- a/scripts/weapon_system/weapon_system.gd +++ b/scripts/weapon_system/weapon_system.gd @@ -25,6 +25,11 @@ signal switched_to(state: WeaponSubStateMachine) func _ready() -> void: $WeaponSpawner.spawn_function = pick_up_weapon +func get_speed_modifier() -> float: + if current_state == null: + return 1 + return current_state.speed_modifier + func can_add(slot: StringName) -> bool: return slots.has(slot) and slots[slot] == null