2020-10-03 16:46:14 +00:00
|
|
|
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-03 16:46:14 +00:00
|
|
|
|
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)
|
|
|
|
|
2020-10-04 13:01:51 +00:00
|
|
|
func set_cb_speed(value):
|
2020-10-04 14:35:24 +00:00
|
|
|
var old = cb_speed
|
2020-10-04 13:01:51 +00:00
|
|
|
cb_speed = value
|
2020-10-04 14:35:24 +00:00
|
|
|
emit_signal("cb_speed_changed", old, value)
|
2020-10-03 16:46:14 +00:00
|
|
|
|
2020-10-04 13:01:51 +00:00
|
|
|
func get_cb_speed():
|
|
|
|
return cb_speed
|
|
|
|
|
|
|
|
func get_relative_cb_speed(other_pos: Vector2):
|
2020-10-03 16:46:14 +00:00
|
|
|
var relative_position = other_pos - position
|
|
|
|
var speed_sign = sign(relative_position.dot(Vector2.UP.rotated(rotation)))
|
2020-10-04 13:01:51 +00:00
|
|
|
return speed_sign * cb_speed
|