1
Fork 0
mirror of https://github.com/Steffo99/looping-for-loops.git synced 2024-11-22 16:14:22 +00:00
looping-for-loops/Objects/ConveyorBelt/ConveyorBelt.gd

33 lines
839 B
GDScript3
Raw Normal View History

extends StaticBody2D
class_name ConveyorBelt
# Speed (and direction) of the conveyor belt
2020-10-04 14:41:46 +00:00
export(float) var cb_speed: float = 100 setget set_cb_speed, get_cb_speed
export(bool) var randomize_gear_starting_position: bool = false
2020-10-04 14:35:24 +00:00
signal cb_speed_changed(old, new)
2020-10-04 18:26:45 +00:00
func _ready():
set_cb_speed(cb_speed)
func set_cb_speed(value):
2020-10-04 14:35:24 +00:00
var old = cb_speed
cb_speed = value
2020-10-04 14:35:24 +00:00
emit_signal("cb_speed_changed", old, value)
func get_cb_speed():
return cb_speed
func get_relative_cb_speed(other_pos: Vector2):
var relative_position = other_pos - position
var speed_sign = sign(relative_position.dot(Vector2.UP.rotated(rotation)))
return speed_sign * cb_speed
2020-10-05 20:20:12 +00:00
func _process(delta):
if Input.is_action_just_pressed("cheat_slower"):
set_cb_speed(cb_speed - 50)
if Input.is_action_just_pressed("cheat_faster"):
set_cb_speed(cb_speed + 50)