src / stages / gimmicks / pulley / pulley.tscn

Diagram

Diagram

Assets

200

Overridden virtual functions

_ready

func _ready() -> void:
	set_prev_position()

_physics_process

func _physics_process(_delta: float) -> void:
	if player and player.state != Player.State.FAILED:
		var diff = %Platform.global_position - prev_position
		player.global_position += diff
	set_prev_position()

Scene Tree

  • Pulley Node2D

    • Sprites Node2D

      • Wire Sprite2D

      • Platform Sprite2D

        • Area2D Area2D

          • CollisionShape2D CollisionShape2D

        • StaticBody2D StaticBody2D

          • CollisionShape2D CollisionShape2D

    • AnimationPlayer AnimationPlayer

Signal Connections

$Sprites/Platform/Area2D:[area_entered]⇒$.
func _on_area_2d_area_entered(area: Area2D) -> void:
	player = area.owner as Player
	if state == State.IDLE: move()
$Sprites/Platform/Area2D:[area_exited]⇒$.
func _on_area_2d_area_exited(_area: Area2D) -> void:
	player = null
	if state == State.MOVED: rewind()
$AnimationPlayer:[animation_finished]⇒$.
func _on_animation_player_animation_finished(anim_name: StringName) -> void:
	match anim_name:
		&'move': rewind()
		&'rewind': if player: move()

Animations

move

Diagram

Animation_4wfbi

Diagram

rewind

Diagram

Properties

Table 1. Root properties
Name Value

script

Table 2. $Sprites properties
Name Value

scale

Vector2(7, 7)

Table 3. $Sprites/Wire properties
Name Value

position

Vector2(34.600002, -4.4000006)

rotation

-0.15687567

texture

Pulley
Figure 1. res://assets/images/stages/gimmicks/Pulley.png

region_enabled

true

region_rect

Rect2(17, 0, 83, 12)

Table 4. $Sprites/Platform properties
Name Value

unique_name_in_owner

true

texture

Pulley
Figure 2. res://assets/images/stages/gimmicks/Pulley.png

region_enabled

true

region_rect

Rect2(0, 0, 17, 12)

Table 5. $Sprites/Platform/Area2D properties
Name Value

scale

Vector2(0.19999999, 0.19999999)

collision_layer

0

collision_mask

2

Table 6. $Sprites/Platform/Area2D/CollisionShape2D properties
Name Value

position

Vector2(-0.5, -30)

shape

SubResource("RectangleShape2D_4wfbi")

Table 7. $Sprites/Platform/StaticBody2D properties
Name Value

visible

false

position

Vector2(0.2000032, -0.59999996)

scale

Vector2(0.99999994, 0.99999994)

Table 8. $Sprites/Platform/StaticBody2D/CollisionShape2D properties
Name Value

position

Vector2(-2.7537344e-06, 0.50000036)

scale

Vector2(0.99999976, 0.99999976)

shape

SubResource("RectangleShape2D_75xxw")

Table 9. $AnimationPlayer properties
Name Value

unique_name_in_owner

true

libraries

{ &"": SubResource("AnimationLibrary_4wfbi") }

pulley.gd

extends Node2D

enum State { IDLE, MOVING, MOVED }
@export var state : State = State.IDLE
@export var force := Vector2(4000, 0)
@onready var player : Player = null
var prev_position : Vector2


func _ready() -> void:
	set_prev_position()


func set_prev_position() -> void:
	prev_position = %Platform.global_position


func _physics_process(_delta: float) -> void:
	if player and player.state != Player.State.FAILED:
		var diff = %Platform.global_position - prev_position
		player.global_position += diff
	set_prev_position()


func reset() -> void:
	play(&'RESET')
	unlaunchable()


func move() -> void:
	play(&'move')


func rewind() -> void:
	play(&'rewind')


func launchable() -> void:
	if player: player.jump_boost = force


func unlaunchable() -> void:
	if player: player.jump_boost = Vector2(0, 0)


func play(key: StringName) -> void:
	%AnimationPlayer.play(key)


func _on_area_2d_area_entered(area: Area2D) -> void:
	player = area.owner as Player
	if state == State.IDLE: move()


func _on_area_2d_area_exited(_area: Area2D) -> void:
	player = null
	if state == State.MOVED: rewind()


func _on_animation_player_animation_finished(anim_name: StringName) -> void:
	match anim_name:
		&'move': rewind()
		&'rewind': if player: move()