refactored guest _ready
This commit is contained in:
parent
47f5cfe27f
commit
8c020f4357
43
Guest.gd
43
Guest.gd
|
@ -4,7 +4,7 @@ onready var pickUpArea = $PickUpArea
|
||||||
onready var collision = $PhysicsCollision
|
onready var collision = $PhysicsCollision
|
||||||
export var guestName = "Dieter"
|
export var guestName = "Dieter"
|
||||||
export var PICKUPTRESHOLD = 100
|
export var PICKUPTRESHOLD = 100
|
||||||
export var destinationColor = Color.yellow
|
export var destinationColor = Color.white
|
||||||
var pickup_time
|
var pickup_time
|
||||||
|
|
||||||
signal picked_up(color,name)
|
signal picked_up(color,name)
|
||||||
|
@ -27,7 +27,7 @@ var colorList = [
|
||||||
Color.yellow,
|
Color.yellow,
|
||||||
Color.violet,
|
Color.violet,
|
||||||
Color.red,
|
Color.red,
|
||||||
Color.turquoise
|
Color.blue
|
||||||
]
|
]
|
||||||
var names = [
|
var names = [
|
||||||
'Dieter',
|
'Dieter',
|
||||||
|
@ -46,17 +46,13 @@ var follow_guest = null
|
||||||
var follow_pos = global_position
|
var follow_pos = global_position
|
||||||
|
|
||||||
func _physics_process(delta):
|
func _physics_process(delta):
|
||||||
#linear_velocity = linear_velocity.clamped(100)
|
|
||||||
|
|
||||||
if currentState == states.waiting:
|
if currentState == states.waiting:
|
||||||
linear_velocity.move_toward(Vector2.ZERO,5.0)
|
linear_velocity.move_toward(Vector2.ZERO,5.0)
|
||||||
collision.disabled = false
|
collision.disabled = false
|
||||||
|
|
||||||
elif currentState == states.tethered:
|
elif currentState == states.tethered:
|
||||||
collision.disabled = true
|
collision.disabled = true
|
||||||
mode = RigidBody2D.MODE_STATIC
|
mode = RigidBody2D.MODE_STATIC
|
||||||
var rot_dir = get_angle_to(follow_pos)
|
var rot_dir = get_angle_to(follow_pos)
|
||||||
|
|
||||||
rotation += (rot_dir + deg2rad(90))*0.2
|
rotation += (rot_dir + deg2rad(90))*0.2
|
||||||
var distance = follow_pos.distance_to(global_position)
|
var distance = follow_pos.distance_to(global_position)
|
||||||
global_position = follow_pos
|
global_position = follow_pos
|
||||||
|
@ -69,14 +65,11 @@ func _physics_process(delta):
|
||||||
func _process(delta):
|
func _process(delta):
|
||||||
if delivered != null and OS.get_system_time_msecs() - delivered > 1000:
|
if delivered != null and OS.get_system_time_msecs() - delivered > 1000:
|
||||||
queue_free()
|
queue_free()
|
||||||
|
|
||||||
|
|
||||||
if visible == false:
|
if visible == false:
|
||||||
follow_node = self
|
follow_node = self
|
||||||
if delivered == null:
|
if delivered == null:
|
||||||
delivered = OS.get_system_time_msecs()
|
delivered = OS.get_system_time_msecs()
|
||||||
currentState = states.delivered
|
currentState = states.delivered
|
||||||
|
|
||||||
if follow_node != null and follow_node != self:
|
if follow_node != null and follow_node != self:
|
||||||
currentState = follow_node.currentState
|
currentState = follow_node.currentState
|
||||||
if follow_node.visible == false:
|
if follow_node.visible == false:
|
||||||
|
@ -92,27 +85,22 @@ func _process(delta):
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
rng.randomize()
|
rng.randomize()
|
||||||
var spriteNum = rng.randi_range(0,100)
|
choose_random_sprite()
|
||||||
if spriteNum % 2 == 0:
|
assign_color()
|
||||||
$SpriteMarkus.visible = true
|
assign_name()
|
||||||
sprite = $SpriteMarkus
|
|
||||||
if spriteNum % 2 != 0:
|
func assign_name():
|
||||||
$SpriteSam.visible = true
|
guestName = names[rng.randi_range(0,names.size()-1)]
|
||||||
sprite = $SpriteSam
|
|
||||||
var n = rng.randi_range(0,colorList.size()-1)
|
func assign_color():
|
||||||
destinationColor = colorList[n]
|
destinationColor = colorList[rng.randi_range(0,colorList.size()-1)]
|
||||||
sprite.modulate = destinationColor
|
sprite.modulate = destinationColor
|
||||||
var m = rng.randi_range(0,names.size()-1)
|
|
||||||
guestName = names[m]
|
|
||||||
|
|
||||||
func _on_PickUpArea_body_entered(body):
|
func _on_PickUpArea_body_entered(body):
|
||||||
print(body.name)
|
print(body.name)
|
||||||
if body.name == "Playa":
|
if body.name == "Playa":
|
||||||
pickup_time = OS.get_system_time_msecs()
|
pickup_time = OS.get_system_time_msecs()
|
||||||
emit_signal("picked_up",destinationColor,guestName)
|
emit_signal("picked_up",destinationColor,guestName)
|
||||||
# start pickup process
|
|
||||||
# we are being picked up by the player
|
|
||||||
pass
|
|
||||||
|
|
||||||
func _on_PickUpArea_area_entered(area):
|
func _on_PickUpArea_area_entered(area):
|
||||||
if area.name == "DROPOFF":
|
if area.name == "DROPOFF":
|
||||||
|
@ -121,3 +109,12 @@ func _on_PickUpArea_area_entered(area):
|
||||||
else:
|
else:
|
||||||
emit_signal("dropped_off_fail")
|
emit_signal("dropped_off_fail")
|
||||||
|
|
||||||
|
|
||||||
|
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
|
Loading…
Reference in New Issue