GMTKJam2021/Guest.gd

127 lines
3.0 KiB
GDScript3
Raw Permalink Normal View History

2021-06-12 13:39:49 +02:00
extends RigidBody2D
2021-06-12 02:05:15 +02:00
onready var pickUpArea = $PickUpArea
onready var collision = $PhysicsCollision
2021-06-12 02:05:15 +02:00
export var guestName = "Dieter"
2021-06-12 19:59:12 +02:00
export var PICKUPTRESHOLD = 100
2021-07-01 19:32:50 +02:00
export var destinationColor = Color.white
2021-06-12 21:54:29 +02:00
var pickup_time
2021-06-12 02:05:15 +02:00
signal picked_up(color,name)
signal dropped_off_success
signal dropped_off_idle
signal dropped_off_fail
2021-06-12 21:54:29 +02:00
2021-06-12 02:05:15 +02:00
var rng = RandomNumberGenerator.new()
onready var exclusionZoneShape = $ExclusionZone/CollisionShape2D
var sprite
2021-06-12 02:05:15 +02:00
var delivered
enum states {
waiting,
2021-06-13 18:05:34 +02:00
tethered,
delivered
}
2021-06-12 02:05:15 +02:00
var colorList = [
Color.yellow,
Color.violet,
Color.red,
2021-07-01 19:32:50 +02:00
Color.blue
2021-06-12 02:05:15 +02:00
]
var names = [
'Dieter',
'Peter',
'Gabi',
'Ursula',
'Manni',
'Karl',
'Christa',
'Britta'
]
var currentState = states.waiting
2021-06-12 02:05:15 +02:00
var follow_node = null
2021-06-13 18:05:34 +02:00
var follow_guest = null
var follow_pos = global_position
2021-06-30 20:28:47 +02:00
func set_state(state):
if state == states.delivered:
pickUpArea.monitorable = false
pickUpArea.monitoring = false
collision.disabled = true
if state == states.waiting:
collision.disabled = false
mode = RigidBody2D.MODE_KINEMATIC
if state == states.tethered:
collision.disabled = false
mode = RigidBody2D.MODE_STATIC
func _physics_process(delta):
if currentState == states.waiting:
linear_velocity.move_toward(Vector2.ZERO,5.0)
collision.disabled = false
elif currentState == states.tethered:
var rot_dir = get_angle_to(follow_pos)
2021-06-13 18:55:01 +02:00
rotation += (rot_dir + deg2rad(90))*0.2
var distance = follow_pos.distance_to(global_position)
2021-06-13 18:05:34 +02:00
global_position = follow_pos
pass
2021-06-30 20:28:47 +02:00
2021-06-12 13:39:49 +02:00
func _process(delta):
2021-06-13 18:05:34 +02:00
if delivered != null and OS.get_system_time_msecs() - delivered > 1000:
queue_free()
if visible == false:
follow_node = self
2021-06-13 18:05:34 +02:00
if delivered == null:
delivered = OS.get_system_time_msecs()
currentState = states.delivered
if follow_node != null and follow_node != self:
currentState = follow_node.currentState
if follow_node.visible == false:
follow_node = self
if follow_node == self:
currentState = states.waiting
else:
currentState = states.tethered
2021-06-13 18:05:34 +02:00
follow_pos = follow_node.get_node("Anchor/Joint/Rope/Anchor").global_position
else:
currentState = states.waiting
follow_pos = global_position
2021-06-12 13:39:49 +02:00
func _ready():
2021-06-12 02:05:15 +02:00
rng.randomize()
2021-07-01 19:32:50 +02:00
choose_random_sprite()
assign_color()
assign_name()
func assign_name():
guestName = names[rng.randi_range(0,names.size()-1)]
2021-06-12 02:05:15 +02:00
2021-07-01 19:32:50 +02:00
func assign_color():
destinationColor = colorList[rng.randi_range(0,colorList.size()-1)]
sprite.modulate = destinationColor
2021-06-12 02:05:15 +02:00
func _on_PickUpArea_body_entered(body):
2021-06-12 02:27:58 +02:00
print(body.name)
if body.name == "Playa":
pickup_time = OS.get_system_time_msecs()
emit_signal("picked_up",destinationColor,guestName)
2021-06-12 02:05:15 +02:00
func _on_PickUpArea_area_entered(area):
if area.name == "DROPOFF":
if area.destinationColor == destinationColor:
emit_signal("dropped_off_success")
else:
2021-06-12 02:05:15 +02:00
emit_signal("dropped_off_fail")
2021-06-12 02:27:58 +02:00
2021-07-01 19:32:50 +02:00
func choose_random_sprite():
var spriteNum = rng.randi_range(0,100)
if spriteNum % 2 == 0:
$SpriteMarkus.visible = true
sprite = $SpriteMarkus
if spriteNum % 2 != 0:
$SpriteSam.visible = true
sprite = $SpriteSam