diff options
Diffstat (limited to 'Characters')
-rw-r--r-- | Characters/Character.gd | 39 | ||||
-rw-r--r-- | Characters/Character.tscn | 4 | ||||
-rw-r--r-- | Characters/Tux.gd | 4 | ||||
-rw-r--r-- | Characters/Tux.tscn | 4 |
4 files changed, 34 insertions, 17 deletions
diff --git a/Characters/Character.gd b/Characters/Character.gd index 53260f2..b9bcd16 100644 --- a/Characters/Character.gd +++ b/Characters/Character.gd @@ -6,13 +6,19 @@ const JUMPFORCE = -500 const GRAVITY = 20 const RUNSPEED = SPEED * 2 const WALLJUMPFORCE = JUMPFORCE * 0.75 -const WALLJUMPSPEED = SPEED * 10 +const WALLJUMPSPEED = SPEED * 8 var direction = Enum.DIRECTION.RIGHT var canDoubleJump = false var hasPlayedFallStop = false var jumpHeightModifier = 0 +var wasOnWall = false +var lastWallDirection = Enum.DIRECTION.LEFT + + +func _ready(): + pass func _physics_process(delta): @@ -69,7 +75,7 @@ func _physics_process(delta): canDoubleJump = true velocity.y = JUMPFORCE jumpHeightModifier = JUMPFORCE - elif not is_on_floor() and not is_on_wall() and canDoubleJump: + elif not is_on_floor() and not is_on_wall() and not wasOnWall and canDoubleJump: canDoubleJump = false velocity.y = JUMPFORCE if Input.is_action_pressed("JUMP"): @@ -80,18 +86,25 @@ func _physics_process(delta): velocity.y -= jumpHeightModifier - if is_on_wall(): + if is_on_wall() and not is_on_floor(): velocity.y *= 0.8 $Sprite2D.play("wall") - - if Input.is_action_just_pressed("JUMP"): - velocity.y = WALLJUMPFORCE - if direction == Enum.DIRECTION.LEFT: - velocity.x = WALLJUMPSPEED - $Sprite2D.flip_h = false - elif direction == Enum.DIRECTION.RIGHT: - velocity.x = -WALLJUMPSPEED - $Sprite2D.flip_h = true + wasOnWall = true + lastWallDirection = direction + + if not is_on_wall() and wasOnWall: + wasOnWall = false + $WalljumpTimer.start() + + if canWallJump() and Input.is_action_just_pressed("JUMP"): + $WalljumpTimer.stop() + velocity.y = WALLJUMPFORCE + if lastWallDirection == Enum.DIRECTION.LEFT: + velocity.x = WALLJUMPSPEED + $Sprite2D.flip_h = false + elif lastWallDirection == Enum.DIRECTION.RIGHT: + velocity.x = -WALLJUMPSPEED + $Sprite2D.flip_h = true # stop @@ -105,7 +118,7 @@ func is_running(): func canWallJump(): - return self.wallJumpGraceTimer < 0.1 + return (is_on_wall() and not is_on_floor()) or not $WalljumpTimer.is_stopped() func check_flag(): diff --git a/Characters/Character.tscn b/Characters/Character.tscn index 3016f35..055d754 100644 --- a/Characters/Character.tscn +++ b/Characters/Character.tscn @@ -110,3 +110,7 @@ shape = SubResource("2") target_position = Vector2(0, 150) [node name="CheckFallLanding" type="RayCast2D" parent="."] + +[node name="WalljumpTimer" type="Timer" parent="."] +wait_time = 0.1 +one_shot = true diff --git a/Characters/Tux.gd b/Characters/Tux.gd index b7c6d31..048d59c 100644 --- a/Characters/Tux.gd +++ b/Characters/Tux.gd @@ -1,5 +1 @@ extends "res://Characters/Character.gd" - - -func _ready(): - pass diff --git a/Characters/Tux.tscn b/Characters/Tux.tscn index fdda659..6a5b6de 100644 --- a/Characters/Tux.tscn +++ b/Characters/Tux.tscn @@ -111,3 +111,7 @@ shape = SubResource("2") target_position = Vector2(0, 150) [node name="CheckFallLanding" type="RayCast2D" parent="."] + +[node name="WalljumpTimer" type="Timer" parent="."] +wait_time = 0.25 +one_shot = true |