mirror of
				https://github.com/mightypanders/GMTKJam2021.git
				synced 2025-10-31 01:13:47 +01:00 
			
		
		
		
	do some evil things with guests, how the get removed and what they follow
This commit is contained in:
		
							
								
								
									
										45
									
								
								Guest.gd
									
									
									
									
									
								
							
							
						
						
									
										45
									
								
								Guest.gd
									
									
									
									
									
								
							| @ -1,6 +1,7 @@ | ||||
| extends RigidBody2D | ||||
|  | ||||
| onready var pickUpArea = $PickUpArea | ||||
| onready var collision = $PhysicsCollision | ||||
| export var guestName = "Dieter" | ||||
| export var  PICKUPTRESHOLD = 100 | ||||
| export var destinationColor = Color.yellow | ||||
| @ -15,6 +16,8 @@ var rng = RandomNumberGenerator.new() | ||||
| onready var exclusionZoneShape = $ExclusionZone/CollisionShape2D | ||||
| var sprite | ||||
|  | ||||
| var delivered | ||||
|  | ||||
| enum states { | ||||
| 	waiting, | ||||
| 	tethered | ||||
| @ -39,24 +42,40 @@ var names = [ | ||||
| var currentState = states.waiting | ||||
|  | ||||
| var follow_node = null | ||||
| var follow_pos = global_position | ||||
|  | ||||
| func _physics_process(delta): | ||||
| 	 | ||||
| 	if false: | ||||
| 		if follow_node != null: | ||||
| 			currentState = states.tethered | ||||
| 			mode = RigidBody2D.MODE_STATIC | ||||
| 			var rot_dir = get_angle_to(follow_node.global_position) | ||||
| 			rotation += (rot_dir) | ||||
| 			var distance = follow_node.global_position.distance_to(global_position) | ||||
| 			global_position = (follow_node.global_position + Vector2(10,0) )  | ||||
| 	 | ||||
| 	#linear_velocity = linear_velocity.clamped(100) | ||||
| 	if currentState == states.waiting: | ||||
| 		linear_velocity.move_toward(Vector2.ZERO,5.0) | ||||
| 		collision.disabled = false | ||||
|  | ||||
| 	elif currentState == states.tethered: | ||||
| 		collision.disabled = true | ||||
| 		mode = RigidBody2D.MODE_STATIC | ||||
| 		var rot_dir = get_angle_to(follow_pos) | ||||
| 		rotation += (rot_dir) | ||||
| 		var distance = follow_pos.distance_to(global_position) | ||||
| 		global_position = (follow_node.global_position)  | ||||
| 		pass | ||||
|  | ||||
| func _process(delta): | ||||
| 	if delivered != null and OS.get_system_time_msecs() - delivered > 10000: | ||||
| 		queue_free() | ||||
| 	if visible == false: | ||||
| 		follow_node = self | ||||
| 		delivered = OS.get_system_time_msecs() | ||||
| 	if follow_node != null: | ||||
| 		if follow_node.visible == false: | ||||
| 			follow_node = self | ||||
| 		if follow_node == self: | ||||
| 			currentState = states.waiting | ||||
| 		else: | ||||
| 			currentState = states.tethered | ||||
| 			follow_pos = follow_node.global_position | ||||
| 	else: | ||||
| 		currentState = states.waiting | ||||
| 		follow_pos = global_position | ||||
|  | ||||
| func _ready(): | ||||
| 	rng.randomize() | ||||
| @ -76,10 +95,8 @@ func _ready(): | ||||
| func _on_PickUpArea_body_entered(body): | ||||
| 	print(body.name) | ||||
| 	if body.name == "Playa": | ||||
|  | ||||
|  | ||||
| 			pickup_time = OS.get_system_time_msecs() | ||||
| 			emit_signal("picked_up",destinationColor,guestName) | ||||
| 		pickup_time = OS.get_system_time_msecs() | ||||
| 		emit_signal("picked_up",destinationColor,guestName) | ||||
| 			# start pickup process | ||||
| 		# we are being picked up by the player | ||||
| 	pass | ||||
|  | ||||
| @ -15,8 +15,8 @@ radius = 6.0 | ||||
| height = 9.75 | ||||
|  | ||||
| [sub_resource type="CapsuleShape2D" id=6] | ||||
| radius = 4.71085 | ||||
| height = 5.19882 | ||||
| radius = 8.02541 | ||||
| height = 10.5115 | ||||
|  | ||||
| [node name="Guest" type="RigidBody2D" groups=[ | ||||
| "Guest", | ||||
| @ -50,7 +50,7 @@ visible = false | ||||
| scale = Vector2( 0.25, 0.25 ) | ||||
| texture = ExtResource( 3 ) | ||||
|  | ||||
| [node name="CollisionShape2D" type="CollisionShape2D" parent="."] | ||||
| [node name="PhysicsCollision" type="CollisionShape2D" parent="."] | ||||
| modulate = Color( 0, 1, 0.976471, 1 ) | ||||
| shape = SubResource( 3 ) | ||||
|  | ||||
|  | ||||
							
								
								
									
										54
									
								
								Playa.gd
									
									
									
									
									
								
							
							
						
						
									
										54
									
								
								Playa.gd
									
									
									
									
									
								
							| @ -1,5 +1,7 @@ | ||||
| extends KinematicBody2D | ||||
|  | ||||
| var rope = preload("res://Rope.tscn") | ||||
|  | ||||
| export var ACCELERATION = 60 | ||||
| export var MAX_SPEED = 150 | ||||
| export var FRICTION = 50 | ||||
| @ -21,13 +23,28 @@ func add_Guest_to_Line(parent,guest): | ||||
| 	guests.append(guest) | ||||
| 	print('Picked up Guest %s with color %s'%[guest.guestName,guest.destinationColor]) | ||||
| 	var parentAnchor = parent.get_node("Anchor") | ||||
| 	parentAnchor.add_child(get_a_springjoint(parent,guest)) | ||||
| 	#parentAnchor.add_child(get_a_springjoint(parent,guest)) | ||||
| 	var piece = rope.instance() | ||||
| 	parentAnchor.add_child(get_a_pinjoint(parent,piece)) | ||||
| 	var pieceAnchor = piece.get_node("Anchor") | ||||
| 	guest.follow_node = pieceAnchor | ||||
| 	var pua = guest.get_node("PickUpArea") | ||||
| 	pua.monitorable = false | ||||
| 	guest.follow_node = parentAnchor | ||||
| 	#springJoint.rotation = -rotation | ||||
| 	piece.start() | ||||
| 	return guest | ||||
|  | ||||
| func get_a_pinjoint(parent,piece): | ||||
| 	var jointAnchor = parent.get_node("Anchor") | ||||
| 	piece.anchor_ahead = jointAnchor | ||||
| 	var joint = PinJoint2D.new() | ||||
| 	joint.add_child(piece) | ||||
| 	joint.disable_collision = false | ||||
| 	joint.softness = 10 | ||||
| 	joint.node_a = parent.get_path() | ||||
| 	joint.node_b = piece.get_path() | ||||
| 	return joint | ||||
| 	 | ||||
| func get_a_springjoint(parent,child): | ||||
| 	var springJoint = DampedSpringJoint2D.new() | ||||
| 	#springJoint.rotation+=get_angle_to(guest.global_position) | ||||
| @ -44,26 +61,40 @@ func get_a_springjoint(parent,child): | ||||
|  | ||||
| func get_score_from_guest(guest): | ||||
| 	var now = OS.get_system_time_msecs() | ||||
| 	var diff = now - guest.pickup_time | ||||
| 	var subtract = 0 | ||||
| 	if guest.pickup_time != null: | ||||
| 		subtract = guest.pickup_time | ||||
| 	else:  | ||||
| 		subtract = now + 50000 | ||||
| 	var diff = now - subtract | ||||
| 	var score = diff / 1000 | ||||
| 	score = 50 - score | ||||
| 	return score | ||||
| 	 | ||||
| func remove_Guests_from_Line(color): | ||||
|  | ||||
| 	var colormatches = [] | ||||
|  | ||||
| 	var firstFound  | ||||
| 	for g in range(guests.size()): | ||||
| 		if guests[g]!= null: | ||||
| 			if guests[g].destinationColor == color: | ||||
| 				colormatches.append(guests[g]) | ||||
| 				if firstFound == null: | ||||
| 					firstFound = g | ||||
|  | ||||
| 	for i in colormatches: | ||||
| 		for g in guests: | ||||
| 			if g.is_in_group('Player'): | ||||
| 				continue | ||||
| 			if g.follow_node.get_parent() == i: | ||||
| 				g.follow_node == g | ||||
| 		var scoreValue = get_score_from_guest(i) | ||||
| 		emit_signal("scored",scoreValue) | ||||
| 		var pos = guests.find(i) | ||||
| 		i.queue_free() | ||||
| 		guests.remove(pos) | ||||
| 		#i.queue_free() | ||||
| 		i.visible = false | ||||
| 		#guests.remove(pos) | ||||
| 	if firstFound != null: | ||||
| 		guests = guests.slice(0,firstFound-1,1,true) | ||||
| 	return guests.back() | ||||
|  | ||||
| func _on_PickupCheckArea_area_entered(area): | ||||
| @ -78,10 +109,11 @@ func _on_PickupCheckArea_area_entered(area): | ||||
| 		pass | ||||
| 	if area.get_parent().is_in_group("Guest"): | ||||
| 		if guests.has(area.get_parent()): | ||||
| 			print("Area has parent %s" % area.get_parent()) | ||||
| 			print("Guests we have:") | ||||
| 			print(guests) | ||||
| 			print("We already have you in line") | ||||
| 			#print("Area has parent %s" % area.get_parent()) | ||||
| 			#print("Guests we have:") | ||||
| 			#print(guests) | ||||
| 			#print("We already have you in line") | ||||
| 			pass | ||||
| 		else: | ||||
| 			print("Area has parent %s" % area.get_parent()) | ||||
| 			print("It's a Guest") | ||||
|  | ||||
		Reference in New Issue
	
	Block a user