mirror of
https://github.com/mightypanders/GMTKJam2021.git
synced 2025-01-31 06:10:00 +01:00
adding and removing guests
This commit is contained in:
parent
e3f8f50e12
commit
6cb7983ef4
51
Playa.gd
51
Playa.gd
@ -4,30 +4,69 @@ export var ACCELERATION = 60
|
|||||||
export var MAX_SPEED = 150
|
export var MAX_SPEED = 150
|
||||||
export var FRICTION = 50
|
export var FRICTION = 50
|
||||||
|
|
||||||
|
var ROPEPIECE = preload("res://Rope.tscn")
|
||||||
var velocity = Vector2.ZERO
|
var velocity = Vector2.ZERO
|
||||||
var last_in_line
|
var last_in_line
|
||||||
|
var destinationColor = Color.transparent
|
||||||
|
onready var guestListNode = $GuestList
|
||||||
|
|
||||||
var guests = []
|
var guests = []
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
last_in_line = $Anchor
|
last_in_line = $Anchor
|
||||||
|
guests.append(last_in_line.get_parent())
|
||||||
pass # Replace with function body.
|
pass # Replace with function body.
|
||||||
|
|
||||||
func add_Guest_to_Line(parent,guest):
|
func add_Guest_to_Line(parent,guest):
|
||||||
guests.append(guest)
|
guests.append(guest)
|
||||||
var joint = parent.get_node("CollisionShape2D/Joint")
|
guestListNode.add_child(guest)
|
||||||
joint.add_child(guest)
|
|
||||||
joint.node_a = parent.get_path()
|
var springJoint = DampedSpringJoint2D.new()
|
||||||
joint.node_b = guest.get_path()
|
#springJoint.rotation+=get_angle_to(guest.global_position)
|
||||||
return guest
|
springJoint.length = 50
|
||||||
|
springJoint.rest_length = 10
|
||||||
|
springJoint.stiffness = 64
|
||||||
|
springJoint.damping = 1.0
|
||||||
|
springJoint.disable_collision =false
|
||||||
|
springJoint.node_a =parent.get_parent().get_path()
|
||||||
|
springJoint.node_b =guest.get_path()
|
||||||
|
springJoint.add_child(guest)
|
||||||
|
parent.add_child(springJoint)
|
||||||
|
var pua = guest.get_node("PickUpArea")
|
||||||
|
pua.monitoring = false
|
||||||
|
pua.monitorable = false
|
||||||
|
var guestAnchor = guest.get_node("Anchor")
|
||||||
|
springJoint.rotation = -rotation
|
||||||
|
return guestAnchor
|
||||||
|
|
||||||
|
|
||||||
|
func remove_Guests_from_Line(color):
|
||||||
|
|
||||||
|
var colorPositions = []
|
||||||
|
|
||||||
|
for g in range(guests.size()):
|
||||||
|
if guests[g].destinationColor == color:
|
||||||
|
guests[g].queue_free()
|
||||||
|
colorPositions.append(g)
|
||||||
|
|
||||||
|
for i in colorPositions:
|
||||||
|
guests.remove(i)
|
||||||
|
return guests.back()
|
||||||
|
|
||||||
func _on_PickupCheckArea_area_entered(area):
|
func _on_PickupCheckArea_area_entered(area):
|
||||||
|
|
||||||
if area.get_parent().is_in_group("DropOffPoint"):
|
if area.get_parent().is_in_group("DropOffPoint"):
|
||||||
print("It's a DOP")
|
print("It's a DOP")
|
||||||
|
var dop = area.get_parent()
|
||||||
|
var color = dop.destinationColor
|
||||||
|
print(color)
|
||||||
|
last_in_line= remove_Guests_from_Line(color)
|
||||||
#drop all guests after first guest.color == DOP.color, also vanish all guests.color == DOP.color
|
#drop all guests after first guest.color == DOP.color, also vanish all guests.color == DOP.color
|
||||||
pass
|
pass
|
||||||
if area.get_parent().is_in_group("Guest"):
|
if area.get_parent().is_in_group("Guest"):
|
||||||
|
if guests.has(area.get_parent()):
|
||||||
|
print("We already have you in line")
|
||||||
|
else:
|
||||||
print("It's a Guest")
|
print("It's a Guest")
|
||||||
last_in_line = add_Guest_to_Line(last_in_line,area.get_parent())
|
last_in_line = add_Guest_to_Line(last_in_line,area.get_parent())
|
||||||
print(last_in_line)
|
print(last_in_line)
|
||||||
@ -50,7 +89,7 @@ func _physics_process(delta):
|
|||||||
|
|
||||||
if steer_dir != 0 && velocity.length() > 0:
|
if steer_dir != 0 && velocity.length() > 0:
|
||||||
var direction_new = direction.rotated(PI/1.5 * steer_dir * delta)
|
var direction_new = direction.rotated(PI/1.5 * steer_dir * delta)
|
||||||
print(velocity.length())
|
#print(velocity.length())
|
||||||
#print(velocity.angle_to(velocity.rotated(direction_new.angle())))
|
#print(velocity.angle_to(velocity.rotated(direction_new.angle())))
|
||||||
velocity = velocity.rotated(direction.angle_to(direction_new))
|
velocity = velocity.rotated(direction.angle_to(direction_new))
|
||||||
rotate(direction.angle_to(direction_new))
|
rotate(direction.angle_to(direction_new))
|
||||||
|
15
Playa.tscn
15
Playa.tscn
@ -1,4 +1,4 @@
|
|||||||
[gd_scene load_steps=6 format=2]
|
[gd_scene load_steps=5 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://assets/car/Autoi cut.png" type="Texture" id=1]
|
[ext_resource path="res://assets/car/Autoi cut.png" type="Texture" id=1]
|
||||||
[ext_resource path="res://Playa.gd" type="Script" id=2]
|
[ext_resource path="res://Playa.gd" type="Script" id=2]
|
||||||
@ -11,10 +11,6 @@ height = 19.9256
|
|||||||
radius = 12.9279
|
radius = 12.9279
|
||||||
height = 25.8183
|
height = 25.8183
|
||||||
|
|
||||||
[sub_resource type="CapsuleShape2D" id=3]
|
|
||||||
radius = 5.0
|
|
||||||
height = 4.0
|
|
||||||
|
|
||||||
[node name="Playa" type="KinematicBody2D" groups=[
|
[node name="Playa" type="KinematicBody2D" groups=[
|
||||||
"Player",
|
"Player",
|
||||||
]]
|
]]
|
||||||
@ -33,14 +29,9 @@ shape = SubResource( 1 )
|
|||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="PickupCheckArea"]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="PickupCheckArea"]
|
||||||
shape = SubResource( 2 )
|
shape = SubResource( 2 )
|
||||||
|
|
||||||
[node name="Anchor" type="Area2D" parent="."]
|
[node name="Anchor" type="Position2D" parent="."]
|
||||||
position = Vector2( 0, 25 )
|
position = Vector2( 0, 25 )
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Anchor"]
|
[node name="GuestList" type="Node2D" parent="."]
|
||||||
shape = SubResource( 3 )
|
|
||||||
|
|
||||||
[node name="Joint" type="PinJoint2D" parent="Anchor/CollisionShape2D"]
|
|
||||||
node_a = NodePath("../../..")
|
|
||||||
softness = 2.0
|
|
||||||
|
|
||||||
[connection signal="area_entered" from="PickupCheckArea" to="." method="_on_PickupCheckArea_area_entered"]
|
[connection signal="area_entered" from="PickupCheckArea" to="." method="_on_PickupCheckArea_area_entered"]
|
||||||
|
Loading…
Reference in New Issue
Block a user