From 8c6a11cd90680300c838e01222212dfea23d1024 Mon Sep 17 00:00:00 2001 From: tokc Date: Sat, 27 Mar 2021 06:43:45 +0100 Subject: [PATCH 1/6] Make long comment fit within line length guide. --- Player.gd | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Player.gd b/Player.gd index 8d7457a..7c7d80f 100644 --- a/Player.gd +++ b/Player.gd @@ -169,7 +169,9 @@ func fall(delta): if is_on_floor(): velocity -= delta * get_floor_normal() * 20 - if not was_on_floor: # if this is the first frame of ground conotact after a frame of no ground contact - we've just ended a fall + # If this is the first frame of ground contact after a frame of no + # ground contact - we've just ended a fall. + if not was_on_floor: weapon_bob_anim.travel("Land") else: From 3e5758ccb55374d5535c7af63d8f08ad93ed7758 Mon Sep 17 00:00:00 2001 From: tokc Date: Sat, 27 Mar 2021 06:45:46 +0100 Subject: [PATCH 2/6] Remove debug print. --- Player.gd | 2 -- 1 file changed, 2 deletions(-) diff --git a/Player.gd b/Player.gd index 7c7d80f..c83810b 100644 --- a/Player.gd +++ b/Player.gd @@ -164,8 +164,6 @@ func walk(delta): func fall(delta): - print(is_on_floor()) - if is_on_floor(): velocity -= delta * get_floor_normal() * 20 From 945818439eecba3ba7037bbca60b556bb03186e9 Mon Sep 17 00:00:00 2001 From: tokc Date: Sat, 27 Mar 2021 08:21:28 +0100 Subject: [PATCH 3/6] Add two jetpack implementations based on earlier jetpack code. --- Player.gd | 71 ++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 63 insertions(+), 8 deletions(-) diff --git a/Player.gd b/Player.gd index c83810b..b8a4198 100644 --- a/Player.gd +++ b/Player.gd @@ -23,11 +23,12 @@ onready var weapon_bob_anim = $Camera/Hand/WeaponBobAnimationTree["parameters/pl var is_dead = true var was_on_floor = false -const JETPACK_FUEL_MAX = 1 -const JETPACK_REFILL_RATE = 1/5 -const JETPACK_THRUST = 1500 +const JETPACK_FUEL_MAX = 0.6 +const JETPACK_REFILL_RATE = 0.2 +const JETPACK_THRUST = 25 var jetpack_active = false # is the jetpack active? +var jetpack_used = false # Is the jetpack recharging? var jetpack_fuel = JETPACK_FUEL_MAX # max fuel (in seconds) #onready var sfx_foosteps = [$"Sounds/Footstep-Concrete-01", @@ -93,10 +94,66 @@ func on_bullet_flyby(from, to): remote func jump(): if is_on_floor(): - velocity.y = JUMP_VELOCITY + velocity.y += JUMP_VELOCITY $Sounds/Jump.play() weapon_bob_anim.travel("Jump") +""" +# Charge when empty variant. +func jetpack(delta): + debug.text = "Jetpack fuel: %s\nJetpack active: %s\nJetpack used: %s\nJetpack sound: %s" % [ + jetpack_fuel, jetpack_active, jetpack_used, !$Sounds/Jetpack.stream_paused + ] + + # Enable jetpack when it is fully charged. + if jetpack_fuel == JETPACK_FUEL_MAX: + jetpack_used = false + # Disable jetpack when it is empty. + elif jetpack_fuel <= 0 and not jetpack_active: + jetpack_used = true + + if jetpack_active and not jetpack_used and jetpack_fuel > 0: + velocity.y += JETPACK_THRUST * delta + jetpack_fuel -= delta + $Sounds/Jetpack.stream_paused = false + else: + $Sounds/Jetpack.stream_paused = true + + # Only charge when fully empty. + if jetpack_used: + jetpack_fuel = clamp( + jetpack_fuel + JETPACK_REFILL_RATE * delta, + 0.0, + JETPACK_FUEL_MAX + ) +""" + +# Charge when grounded variant. +func jetpack(delta): + debug.text = "Jetpack fuel: %s\nJetpack active: %s\nJetpack sound: %s" % [ + jetpack_fuel, jetpack_active, !$Sounds/Jetpack.stream_paused + ] + + # Only charge when grounded. + if is_on_floor(): + jetpack_fuel = clamp( + jetpack_fuel + JETPACK_REFILL_RATE * delta, + 0.0, + JETPACK_FUEL_MAX + ) + + $Sounds/Jetpack.stream_paused = true + + # Only use jetpack in the air. + else: + if jetpack_active and jetpack_fuel > 0: + velocity.y += JETPACK_THRUST * delta + jetpack_fuel -= delta + $Sounds/Jetpack.stream_paused = false + else: + $Sounds/Jetpack.stream_paused = true + + remote func mouselook_abs(x, y): camera.rotation.x = x rotation.y = y @@ -117,7 +174,7 @@ func _physics_process(delta): walk(delta) fall(delta) - + jetpack(delta) var movement_vector = Vector3() if Input.is_action_just_pressed("MoveJump"): @@ -134,7 +191,6 @@ func _physics_process(delta): rset("translation", translation) func walk(delta): - # Walk walk_direction = Vector2() if Input.is_action_pressed("MoveForward"): @@ -176,7 +232,6 @@ func fall(delta): velocity += delta * GRAVITY was_on_floor = is_on_floor() - master func on_hit(damage, location): set_health(health - 30) @@ -274,7 +329,7 @@ func _input(event): if event.is_action_pressed("MoveJetpack"): jetpack_active = true - else: + if event.is_action_released("MoveJetpack"): jetpack_active = false if event.is_action_pressed("WeaponPrimary"): From 0db4882c8356ac0f960ad1a4f62216483e9b0488 Mon Sep 17 00:00:00 2001 From: tokc Date: Sat, 27 Mar 2021 08:26:14 +0100 Subject: [PATCH 4/6] Comment out debug text. --- Player.gd | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Player.gd b/Player.gd index b8a4198..db93f37 100644 --- a/Player.gd +++ b/Player.gd @@ -101,9 +101,9 @@ remote func jump(): """ # Charge when empty variant. func jetpack(delta): - debug.text = "Jetpack fuel: %s\nJetpack active: %s\nJetpack used: %s\nJetpack sound: %s" % [ - jetpack_fuel, jetpack_active, jetpack_used, !$Sounds/Jetpack.stream_paused - ] + #debug.text = "Jetpack fuel: %s\nJetpack active: %s\nJetpack used: %s\nJetpack sound: %s" % [ + # jetpack_fuel, jetpack_active, jetpack_used, !$Sounds/Jetpack.stream_paused + #] # Enable jetpack when it is fully charged. if jetpack_fuel == JETPACK_FUEL_MAX: @@ -130,9 +130,9 @@ func jetpack(delta): # Charge when grounded variant. func jetpack(delta): - debug.text = "Jetpack fuel: %s\nJetpack active: %s\nJetpack sound: %s" % [ - jetpack_fuel, jetpack_active, !$Sounds/Jetpack.stream_paused - ] + #debug.text = "Jetpack fuel: %s\nJetpack active: %s\nJetpack sound: %s" % [ + # jetpack_fuel, jetpack_active, !$Sounds/Jetpack.stream_paused + #] # Only charge when grounded. if is_on_floor(): From 0cb0cb521b9ed17d3ae579947c0b437afc9322a4 Mon Sep 17 00:00:00 2001 From: tokc Date: Sun, 28 Mar 2021 03:13:26 +0200 Subject: [PATCH 5/6] Comment out debug text. --- Player.gd | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Player.gd b/Player.gd index db93f37..10c46a3 100644 --- a/Player.gd +++ b/Player.gd @@ -130,9 +130,9 @@ func jetpack(delta): # Charge when grounded variant. func jetpack(delta): - #debug.text = "Jetpack fuel: %s\nJetpack active: %s\nJetpack sound: %s" % [ - # jetpack_fuel, jetpack_active, !$Sounds/Jetpack.stream_paused - #] + debug.text = "Jetpack fuel: %s\nJetpack active: %s\nJetpack sound: %s" % [ + jetpack_fuel, jetpack_active, !$Sounds/Jetpack.stream_paused + ] # Only charge when grounded. if is_on_floor(): From 104cdc76e0e9403264469244fc3ccd44cffc14ac Mon Sep 17 00:00:00 2001 From: tokc Date: Tue, 30 Mar 2021 17:31:16 +0200 Subject: [PATCH 6/6] Make jetpack versions easily swappable in the code. --- Player.gd | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/Player.gd b/Player.gd index aa282a8..2db6ac4 100644 --- a/Player.gd +++ b/Player.gd @@ -103,15 +103,18 @@ remote func jump(): $Sounds/Jump.play() weapon_bob_anim.travel("Jump") -""" -# Charge when empty variant. func jetpack(delta): - #debug.text = "Jetpack fuel: %s\nJetpack active: %s\nJetpack used: %s\nJetpack sound: %s" % [ - # jetpack_fuel, jetpack_active, jetpack_used, !$Sounds/Jetpack.stream_paused - #] + # Swap these to try the different versions of the jetpack. + jetpack_grounded(delta) + #jetpack_empty(delta) + +func jetpack_empty(delta): + debug.text = "JP fuel: %s\nJP active: %s\nJP used: %s\nJP sound: %s" % [ + jetpack_fuel, jetpack_active, jetpack_used, !$Sounds/Jetpack.stream_paused + ] # Enable jetpack when it is fully charged. - if jetpack_fuel == JETPACK_FUEL_MAX: + if jetpack_fuel > (JETPACK_FUEL_MAX - 0.001): jetpack_used = false # Disable jetpack when it is empty. elif jetpack_fuel <= 0 and not jetpack_active: @@ -131,16 +134,15 @@ func jetpack(delta): 0.0, JETPACK_FUEL_MAX ) -""" # Charge when grounded variant. -func jetpack(delta): - debug.text = "Jetpack fuel: %s\nJetpack active: %s\nJetpack sound: %s" % [ +func jetpack_grounded(delta): + debug.text = "JP fuel: %s\nJP active: %s\nJP sound: %s" % [ jetpack_fuel, jetpack_active, !$Sounds/Jetpack.stream_paused ] # Only charge when grounded. - if is_on_floor(): + if is_on_floor: jetpack_fuel = clamp( jetpack_fuel + JETPACK_REFILL_RATE * delta, 0.0, @@ -157,7 +159,6 @@ func jetpack(delta): $Sounds/Jetpack.stream_paused = false else: $Sounds/Jetpack.stream_paused = true - remote func mouselook_abs(x, y): camera.rotation.x = x