Manager agora só estado, admin adiciona players e mata

parent 0cfadbdc
......@@ -10,33 +10,23 @@ var player_rot
var numPlayer = 0
var dead = 0
func _ready():
randomize()
# Variaveis
var ready_players = []
func _create_player():
var vector = Vector2(rand_range(50, 961), rand_range(50, 571))
var GrabbedInstance = PLAYER.instance()
player_pos = get_child(numPlayer).position
player_rot = get_child(numPlayer).get_rotation()
GrabbedInstance.position = player_pos
GrabbedInstance.set_rotation(player_rot)
add_child(GrabbedInstance)
numPlayer += 1
print("PLAYER CREATED")
# Recebe o sinal "dead"
GrabbedInstance.connect("died", self, "_is_over")
# Signal
signal game_over
func _input(event):
if event.is_action_pressed("new_player") and numPlayer < MAX_PLAYER:
_create_player()
func _setup(players, map):
ready_players = players
numPlayer = ready_players.size()
for i in numPlayer:
if ready_players[i] != null:
map.add_child(ready_players[i])
ready_players[i].connect("died", self, "_is_over")
func _is_over():
dead += 1
print("DEAD")
if dead == numPlayer - 1:
if dead == numPlayer:
print("GAME OVER")
get_tree().paused = true
emit_signal("game_over")
......@@ -3,14 +3,11 @@ extends Control
const PLAYER_SELECTION_RES = "res://Menus/Selecao_Players/Selecao_Players.tscn"
const MAP_SELECTION_RES = "res://Menus/Selecao_Mapas/Selecao_Mapas.tscn"
const MENU_PRINCIPAL_RES = "res://Menus/Menu_principal/Menu_teste.tscn"
const ADMIN_RES = "res://Admin/Admin.tscn"
#Connected Players
var connected_players = []
#Variables
var deaths = 0
var num_players = 0
func _ready():
var player_selection = load(PLAYER_SELECTION_RES).instance()
player_selection.connect("players_ready", self, "_players_ready")
......@@ -38,13 +35,12 @@ func _players_ready(players):
#na tela de seleção de mapas
func _map_selected(map):
get_child(0).queue_free()
var admin_instance = load(ADMIN_RES).instance()
var map_instance = load(map).instance()
self.add_child(map_instance)
map_instance.get_child(1).queue_free()
for i in connected_players.size():
if connected_players[i] != null:
map_instance.add_child(connected_players[i])
connected_players[i].connect("died", self, "_game_over")
admin_instance._setup(connected_players, map_instance)
admin_instance.connect("game_over", self, "_game_over")
#Chamado pelo menu de seleção de mapas
#para voltar para a seleção de jogadores
......@@ -57,12 +53,9 @@ func _map_selection_back():
#Chamado quando um jogo termina
func _game_over():
deaths += 1
if deaths == connected_players.size():
deaths = 0
get_child(0).queue_free()
var player_selection = load(PLAYER_SELECTION_RES).instance()
player_selection.connect("players_ready", self, "_players_ready")
player_selection.connect("player_exited", self, "_menu_principal_back")
connected_players = player_selection.players
self.add_child(player_selection)
get_child(0).queue_free()
var player_selection = load(PLAYER_SELECTION_RES).instance()
player_selection.connect("players_ready", self, "_players_ready")
player_selection.connect("player_exited", self, "_menu_principal_back")
connected_players = player_selection.players
self.add_child(player_selection)
......@@ -18,6 +18,9 @@ anchor_bottom = 0.9
custom_constants/vseparation = 10
custom_constants/hseparation = 10
columns = 4
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Voltar" type="Button" parent="."]
anchor_left = 0.5
......
......@@ -6,10 +6,14 @@ const PLAYER = "res://Player_inicial/Player.tscn"
#variables
var ready_devices = [null, null, null, null]
var player_existence = [null, null, null, null]
var id
var players = []
var players_ready = 0
var existent_players = 0
#sinais
# warning-ignore:unused_signal
signal players_ready(devices)
signal player_exited
......@@ -18,22 +22,63 @@ signal player_exited
#Chamada quando os jogadores voltam da
#seleção de mapas para esse menu.
#Deve colocar os jogadores de volta no lugar.
func _count_not_null(array):
var counter = 0
for i in array.size():
if array[i] != null:
counter +=1
return counter
func _setup(instanced_players):
for i in instanced_players.size():
if instanced_players[i] != null:
instanced_players[i].position = POSITIONS[i]
func _ready():
$Button.visible = false
# warning-ignore:unused_argument
func _process(delta):
for i in player_existence.size():
if player_existence[i] != null:
$Button.visible = true
func _input(event):
if event.is_action_pressed("player_start"):
id = event.get_device()
var player = load(PLAYER).instance()
player._setup(id)
ready_devices[id] = id
player_existence[id] = player
player.position = POSITIONS[id]
players.push_back(player)
emit_signal("players_ready", ready_devices)
if event.is_action_pressed("player_exit"):
id = event.get_device()
ready_devices.remove(id)
emit_signal("player_exited")
player_existence.remove(id)
existent_players = 0
existent_players = self._count_not_null(player_existence)
if existent_players == 0:
emit_signal("player_exited")
if $Button.visible:
if event.is_action_pressed("player_start") and player_existence[event.get_device()] != null:
ready_devices[event.get_device()] = player_existence[event.get_device()]
players_ready += 1
existent_players = self._count_not_null(player_existence)
if players_ready == existent_players:
emit_signal("players_ready", ready_devices)
else:
existent_players = 0
if event.is_action_pressed("player_exit") and player_existence[event.get_device()] != null:
ready_devices.remove(event.get_device())
if players_ready > 0:
players_ready -= 1
if players_ready == 0:
$Button.visible = false
......@@ -21,3 +21,10 @@ __meta__ = {
}
[node name="Players" type="Node2D" parent="."]
[node name="Button" type="Button" parent="."]
margin_left = 469.285
margin_top = 305.688
margin_right = 557.285
margin_bottom = 325.688
text = "READY?"
......@@ -8,6 +8,9 @@ onready var RADIUS = get_node("Collision_bola").shape.radius
var id = -1 #Id do Controle
export(int,0,3) var skin_id = -1 #Id da skin
var is_id = false
var keyboard_id_1
var keyboard_id_2
#Velocidade do personagem
var speed = 0
......@@ -34,8 +37,7 @@ onready var bola = $bola
func ball_dist():
return -(8*(bola.scale.x+1)+bola.get_radius())
#Sinal e timer
signal dead
#Timer
var timer = Timer.new()
func _setup(id):
......@@ -52,51 +54,52 @@ func _ready():
timer.start()
func _input(event):
#Actions pressed
if event.is_action_pressed("ui_right"):
rotation_state = turning.right
elif event.is_action_pressed("ui_left"):
rotation_state = turning.left
elif event.is_action_pressed("ui_up"):
state = direction.up
elif event.is_action_pressed("ui_down"):
state = direction.down
elif event.is_action_pressed("ui_select") and has_ball:
has_ball = false
#desabilitando colisão da bola
$"Collision_bola".disabled = true
#removendo ligação do player com a bola
#a fim de não possibilitar movimento
#conjunto após lançamento
var pai = self.get_parent()
var ball_pos = bola.global_position
self.remove_child(bola)
bola.position = ball_pos
pai.add_child(bola)
#chamando função de lançamento da bola
#e transformando ângulo em vetor
# "1.5" é necessário pois embora comece
#de um ângulo 0, o player não inicia virado
#para a direita, mas para cima
var direction = Vector2(cos(rotation-1.5), sin(rotation-1.5))
bola.launch_ball(direction)
#ligando o timer
$Timer.start()
#Actions released
elif event.is_action_released("ui_right"):
rotation_state = turning.none
elif event.is_action_released("ui_left"):
rotation_state = turning.none
elif event.is_action_released("ui_up"):
state = direction.none
elif event.is_action_released("ui_down"):
state = direction.none
if event.get_device() == id:
#Actions pressed
if event.is_action_pressed("ui_right"):
rotation_state = turning.right
elif event.is_action_pressed("ui_left"):
rotation_state = turning.left
elif event.is_action_pressed("ui_up"):
state = direction.up
elif event.is_action_pressed("ui_down"):
state = direction.down
elif event.is_action_pressed("ui_select") and has_ball:
has_ball = false
#desabilitando colisão da bola
$"Collision_bola".disabled = true
#removendo ligação do player com a bola
#a fim de não possibilitar movimento
#conjunto após lançamento
var pai = self.get_parent()
var ball_pos = bola.global_position
self.remove_child(bola)
bola.position = ball_pos
pai.add_child(bola)
#chamando função de lançamento da bola
#e transformando ângulo em vetor
# "1.5" é necessário pois embora comece
#de um ângulo 0, o player não inicia virado
#para a direita, mas para cima
var direction = Vector2(cos(rotation-1.5), sin(rotation-1.5))
bola.launch_ball(direction)
#ligando o timer
$Timer.start()
#Actions released
elif event.is_action_released("ui_right"):
rotation_state = turning.none
elif event.is_action_released("ui_left"):
rotation_state = turning.none
elif event.is_action_released("ui_up"):
state = direction.none
elif event.is_action_released("ui_down"):
state = direction.none
#warning-ignore:unused_argument
func _process(delta):
......@@ -151,6 +154,7 @@ func _on_Timer_timeout():
#preload retorna uma PackedScene
#quando uso instance(), retorno o root
bola = nova_bola.instance()
bola.get_child(0).texture = load("res://assets/bolas/sphere-0%s.png" % skin_id)
bola.set_position(Vector2(0, ball_dist() ))
$"Collision_bola".set_position(Vector2(0, ball_dist()))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment