Parcourir la source

Add player when left action event happens

Add the corresponding player owning the left action.
DricomDragon il y a 4 ans
Parent
commit
1f8ae43d98
1 fichiers modifiés avec 21 ajouts et 15 suppressions
  1. 21 15
      Hub.gd

+ 21 - 15
Hub.gd

@@ -21,20 +21,26 @@ var _playerActionsRight = ["p1_right", "p2_right", "p3_right"]
 
 var _hub_enabled = true
 
+
 func _unhandled_input(event):
-	if event.is_action("ui_accept") and event.is_pressed() and _hub_enabled:
-		get_tree().set_input_as_handled()
-
-		# Create players
-		var player
-		for k in 2:
-			player = _playerScene.instance()
-			player.turn_left_action = _playerActionsLeft[k]
-			player.turn_right_action = _playerActionsRight[k]
-			player.position = Vector2()
-			player.modulate = playerColors[k]
-			add_child(player)
+	if event.is_pressed() and _hub_enabled:
+		if event.is_action("ui_accept"):
+			if get_tree().get_nodes_in_group("players").size() > 0:
+				get_tree().set_input_as_handled()
 	
-		# TODO : make hub interactive
-		_hub_enabled = false
-		emit_signal("hub_finished")
+				_hub_enabled = false
+				emit_signal("hub_finished")
+
+		elif event.is_action_type():
+			for pal in _playerActionsLeft:
+				if event.is_action(pal):
+					# Create player
+					var id = _playerActionsLeft.find(pal)
+
+					var player
+					player = _playerScene.instance()
+					player.turn_left_action = _playerActionsLeft[id]
+					player.turn_right_action = _playerActionsRight[id]
+					player.position = Vector2(id * 100.0, 0.0)
+					player.modulate = playerColors[id]
+					add_child(player)