diff options
Diffstat (limited to 'Units/climber.gd')
-rw-r--r-- | Units/climber.gd | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/Units/climber.gd b/Units/climber.gd new file mode 100644 index 0000000..5c1f0c2 --- /dev/null +++ b/Units/climber.gd @@ -0,0 +1,57 @@ +extends Unit + + +var speed := 1000.0 +var direction := Vector2.RIGHT + +var was_climbing := false +var post_climb_position_fix := 3 + + +func _physics_process(delta: float) -> void: + if $RayWallLeft.is_colliding() or $RayWallRight.is_colliding(): + process_climbing(delta) + elif was_climbing: + var default = load("res://Units/Default.tscn").instantiate() + default.global_position = global_position + (post_climb_position_fix * direction) + default.direction = direction + get_tree().current_scene.add_child(default) + queue_free() + else: + process_walking(delta) + + move_and_slide() + + +func process_walking(delta: float) -> void: + if not is_on_floor(): + velocity.x = 0 + velocity += get_gravity() * delta * Game.speed + if velocity.y > (get_gravity().y / 10): + $AnimatedSprite.play("fall") + + if is_on_floor(): + if $RayWallLeft.is_colliding() or $RayHeadLeft.is_colliding(): + direction = Vector2.RIGHT + elif $RayWallRight.is_colliding() or $RayHeadRight.is_colliding(): + direction = Vector2.LEFT + + if ( + ($RaySlopeLeft.is_colliding() and not $RayWallLeft.is_colliding()) or + ($RaySlopeRight.is_colliding() and not $RayWallRight.is_colliding()) + ): + position.y -= 10 * delta * Game.speed + position.x += 10 * direction.x * delta * Game.speed + + velocity.x = direction.x * speed * delta * Game.speed + + $AnimatedSprite.play("walk") + $AnimatedSprite.flip_h = direction.x < 0 + + +func process_climbing(delta: float) -> void: + was_climbing = true + + velocity.y = -((speed / 2) * delta * Game.speed) + + $AnimatedSprite.play("climb") |