1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- class_name Hub
- extends Node2D
- # User interface to create liners
- signal hub_finished
- const ACTION_PLAYER_PREFIX = "p"
- const ACTION_LEFT_SUFFIX = "_left"
- const ACTION_RIGHT_SUFFIX = "_right"
- const MAX_PLAYERS = 8
- export (Array, Color) var playerColors = [
- Color.red,
- Color.blue,
- Color.green,
- Color.yellow,
- Color.white,
- Color.cyan,
- Color.magenta,
- Color.orange,
- ]
- var _playerScene = preload("res://Player.tscn")
- var _playerActionsLeft
- var _playerActionsRight
- var _hub_enabled = true
- func _ready():
- _fill_action_arrays()
- func _unhandled_input(event):
- 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()
-
- _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)
- get_tree().set_input_as_handled()
- func _fill_action_arrays():
- _playerActionsLeft = []
- _playerActionsRight = []
- for k in MAX_PLAYERS:
- _playerActionsLeft.append(ACTION_PLAYER_PREFIX + str(k) + ACTION_LEFT_SUFFIX)
- _playerActionsRight.append(ACTION_PLAYER_PREFIX + str(k) + ACTION_RIGHT_SUFFIX)
|