Skip to content

Commit

Permalink
Don't start game if less than 4 players are connected.
Browse files Browse the repository at this point in the history
  • Loading branch information
derac committed Mar 13, 2020
1 parent bc9ba3e commit 9023936
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Classes/1_Setup/Join_Button.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func _pressed() -> void:
Log.if_error(Game_Server.start_client(address["ip"], int(address["port"])),
"Could not start game client at %s:%s." % [address["ip"], int(address["port"])])
else:
Sound.play_sfx("res://Assets/SFX/bad.wav", -3, .75)
Sound.play_sfx("res://Assets/SFX/bad.wav", -5, .75)

func _connection_succeeded() -> void:
Game_Server.server_address = address
Expand Down
2 changes: 1 addition & 1 deletion Classes/1_Setup/New_Button.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ func _pressed() -> void:
Log.if_error(get_tree().change_scene_to(lobby_scene),
"Failed to change scene to lobby_scene")
else:
Sound.play_sfx("res://Assets/SFX/bad.wav", -3, .75)
Sound.play_sfx("res://Assets/SFX/bad.wav", -5, .75)
2 changes: 1 addition & 1 deletion Classes/2_Lobby/My_IP_Button.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ onready var Address = get_node("/root/Lobby/Information/Address")
onready var UPNP_Message = get_node("/root/Lobby/Information/UPNP")

func _ready() -> void:
if Game_Server.is_server != true:
if not Game_Server.is_server:
set_visible(false)

func _pressed() -> void:
Expand Down
39 changes: 26 additions & 13 deletions Classes/2_Lobby/Start_Button.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ extends Button

var countdown : int
var play_screen := load("res://Screens/Play.tscn")
var min_players = 1 if OS.is_debug_build() else 4

func _ready() -> void:
if Game_Server.is_server != true:
if not Game_Server.is_server:
set_visible(false)

func _pressed() -> void:
var min_players = 1 if OS.is_debug_build() else 4
if Game_Server.is_server == true and Global.game_state.size() >= min_players:
if Game_Server.is_server and Global.game_state.size() >= min_players:
Game_Server.peer.set_refuse_new_connections(true)
rpc("start_timer")
else:
Sound.play_sfx("res://Assets/SFX/bad.wav", -3, .75)
Sound.play_sfx("res://Assets/SFX/bad.wav", -5, .75)

remotesync func start_timer() -> void:
UDP_Broadcast.request_removal()
Expand All @@ -31,16 +31,29 @@ remotesync func start_timer() -> void:
get_node("../My_IP").set_visible(false)

func _on_Timer_timeout() -> void:
if countdown == 3:
Sound.play_sfx("res://Assets/SFX/button2.wav", 0.0, 0.75)
if countdown == 2:
Sound.play_sfx("res://Assets/SFX/button2.wav", 0.0, 0.5)
if countdown > 1:
countdown -= 1
text = String(countdown)
$Start_Timer.start()
if Global.game_state.size() >= min_players:
if countdown == 3:
Sound.play_sfx("res://Assets/SFX/button2.wav", 0.0, 0.75)
if countdown == 2:
Sound.play_sfx("res://Assets/SFX/button2.wav", 0.0, 0.5)
if countdown > 1:
countdown -= 1
text = String(countdown)
$Start_Timer.start()
else:
start_game()
else:
start_game()
Sound.play_sfx("res://Assets/SFX/bad.wav", -5, .75)
$Start_Timer.stop()
text = "start"
get_node("../Back").set_visible(true)
UDP_Broadcast.broadcasting = true
if Game_Server.is_server:
get_node("../My_IP").set_visible(true)
disabled = false
else:
visible = false


func start_game() -> void:
Log.if_error(get_tree().change_scene_to(play_screen),
Expand Down
2 changes: 1 addition & 1 deletion Classes/4_End/Review/Review.gd
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func update_display(turn : int) -> void:
$Controls/Points.text = "+%s" % String(scores[played_by])
$Controls/Points.set_visible(true)
else:
Sound.play_sfx("res://Assets/SFX/bad.wav", -3, .75)
Sound.play_sfx("res://Assets/SFX/bad.wav", -5, .75)
Turn_Is_Canvas_stylebox.set_border_color(Color("#FF004D"))
Turn_stylebox.set_border_color(Color("#FF004D"))
$Controls/Points.set_visible(false)
Expand Down

0 comments on commit 9023936

Please sign in to comment.