mirror of
https://github.com/JohnBreaux/Boat-Battle.git
synced 2025-02-04 12:28:35 +00:00
Merge branch 'game-logic' of https://github.com/StatewideInk/Group12 into game-logic
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
extends Control
|
||||
|
||||
# Scenes
|
||||
onready var title_screen = preload("res://scenes/Title Screen.tscn")
|
||||
onready var game = preload("res://scenes/Game/Game.tscn" )
|
||||
onready var options = preload("res://scenes/Options.tscn" )
|
||||
onready var debug_menu = preload("res://scenes/Debug Menu.tscn" )
|
||||
onready var Title_Screen = preload("res://scenes/Title Screen.tscn")
|
||||
onready var Game = preload("res://scenes/Game/Game.tscn" )
|
||||
onready var Options = preload("res://scenes/Options.tscn" )
|
||||
onready var Debug_Menu = preload("res://scenes/Debug Menu.tscn" )
|
||||
|
||||
# Themes
|
||||
var lightmode = preload("res://assets/backgrounds/Background_Light.png");
|
||||
var darkmode = preload("res://assets/backgrounds/Background_Dark.png");
|
||||
|
||||
#flags
|
||||
var power_saving = true
|
||||
@@ -21,12 +25,15 @@ func _ready():
|
||||
_errno += MessageBus.connect("list_scenes" , self, "_on_scene_list" )
|
||||
_errno += MessageBus.connect("quit" , self, "_on_quit_request" )
|
||||
_errno += MessageBus.connect("return_to_title", self, "_on_title_request" )
|
||||
_errno += OptionsController.connect("change_theme", self, "_on_change_theme" )
|
||||
# Set the theme based on the config file
|
||||
_on_change_theme(OptionsController.get_theme())
|
||||
# go fullscreen
|
||||
OS.low_processor_usage_mode = power_saving
|
||||
OS.low_processor_usage_mode_sleep_usec = 6800
|
||||
OS.window_fullscreen = start_fullscreen
|
||||
if debug_enabled:
|
||||
add_child(debug_menu.instance())
|
||||
add_child(Debug_Menu.instance())
|
||||
|
||||
# Process global keybinds
|
||||
func _input(event):
|
||||
@@ -38,29 +45,33 @@ func _input(event):
|
||||
# Ensure the scene doesn't become empty
|
||||
func _process(_delta):
|
||||
# Make sure there's something running
|
||||
# Background counts as one child
|
||||
# Debug counts as one child
|
||||
if get_child_count() < 1 + int(debug_enabled):
|
||||
if get_child_count() < 2 + int(debug_enabled):
|
||||
MessageBus.emit_signal("change_scene", "Title")
|
||||
pass
|
||||
|
||||
# Creates a new instance of each menu scene
|
||||
func _on_scene_start(scene):
|
||||
var instance
|
||||
#print ("_on_scene_start(",scene,")")
|
||||
match scene:
|
||||
"Singleplayer":
|
||||
add_child (game.instance())
|
||||
instance = Game.instance()
|
||||
add_child (instance)
|
||||
return true
|
||||
"Multiplayer":
|
||||
game = game.instance()
|
||||
game.is_multiplayer = true
|
||||
add_child (game)
|
||||
# add_child (multiplayercontroller.instance())
|
||||
instance = Game.instance()
|
||||
instance.is_multiplayer = true
|
||||
add_child (instance)
|
||||
return true
|
||||
"Options":
|
||||
add_child (options.instance())
|
||||
instance = Options.instance()
|
||||
add_child (instance)
|
||||
return true
|
||||
"Title":
|
||||
add_child (title_screen.instance())
|
||||
instance = Title_Screen.instance()
|
||||
add_child (instance)
|
||||
return true
|
||||
|
||||
func _on_scene_start_by_name(scene):
|
||||
@@ -89,3 +100,9 @@ func _on_quit_request():
|
||||
# Kills the current tree and replaces it with a new one
|
||||
func _on_title_request():
|
||||
return get_tree().change_scene("res://scenes/Main.tscn")
|
||||
|
||||
func _on_change_theme(theme):
|
||||
if theme == "light":
|
||||
get_node("Background").set_texture(lightmode)
|
||||
elif theme == "dark":
|
||||
get_node("Background").set_texture(darkmode)
|
||||
|
||||
@@ -6,3 +6,6 @@ extends Node
|
||||
|
||||
# Ask for a scene change
|
||||
signal button_clicked
|
||||
signal ship_hit
|
||||
signal ship_missed
|
||||
signal ship_sunk
|
||||
|
||||
@@ -9,9 +9,22 @@ extends Control
|
||||
func _ready():
|
||||
var _errno = 0
|
||||
_errno += AudioBus.connect("button_clicked", self, "_button_clicked")
|
||||
_errno += AudioBus.connect("ship_hit", self, "_ship_hit")
|
||||
_errno += AudioBus.connect("ship_missed", self, "_ship_missed")
|
||||
_errno += AudioBus.connect("ship_sunk", self, "_ship_sunk")
|
||||
|
||||
func _button_clicked():
|
||||
$buttonSFX.play()
|
||||
|
||||
func _ship_hit():
|
||||
$shipHitSFX.play()
|
||||
|
||||
func _ship_missed():
|
||||
$shipMissedSFX.play()
|
||||
|
||||
func _ship_sunk():
|
||||
$shipSunkSFX.play()
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
#func _process(delta):
|
||||
# pass
|
||||
|
||||
@@ -33,6 +33,9 @@ func _ready():
|
||||
var setup = Setup.instance()
|
||||
setup.connect("game_ready", self, "game_setup")
|
||||
add_child(setup)
|
||||
|
||||
get_node("ConfirmationDialog").get_ok().text = "Yes"
|
||||
get_node("ConfirmationDialog").get_cancel().text = "No"
|
||||
|
||||
# TODO: Move Setup into the Player.
|
||||
func game_setup(_ships):
|
||||
@@ -57,14 +60,16 @@ func display_turn():
|
||||
|
||||
func _on_Forfeit_pressed():
|
||||
AudioBus.emit_signal("button_clicked")
|
||||
end()
|
||||
get_node("ConfirmationDialog").popup()
|
||||
|
||||
func end():
|
||||
queue_free()
|
||||
|
||||
|
||||
func _on_Button_button_down():
|
||||
AudioBus.emit_signal("button_clicked")
|
||||
var victory = Victory.instance()
|
||||
add_child(victory)
|
||||
victory.connect("exit_main", self, "end")
|
||||
|
||||
func _on_ConfirmationDialog_confirmed():
|
||||
end()
|
||||
|
||||
@@ -10,9 +10,9 @@ onready var theme_buttons = find_node("Buttons", true, true).get_children()
|
||||
func _ready():
|
||||
OptionsController.load_options()
|
||||
find_next_valid_focus().grab_focus()
|
||||
master_slider.value = OptionsController.get_mas_volume()
|
||||
music_slider.value = OptionsController.get_mus_volume()
|
||||
sound_slider.value = OptionsController.get_sfx_volume()
|
||||
master_slider.value = db2linear(OptionsController.get_mas_volume())
|
||||
music_slider.value = db2linear(OptionsController.get_mus_volume())
|
||||
sound_slider.value = db2linear(OptionsController.get_sfx_volume())
|
||||
|
||||
func _on_Button_pressed():
|
||||
AudioBus.emit_signal("button_clicked")
|
||||
@@ -20,14 +20,17 @@ func _on_Button_pressed():
|
||||
#MessageBus.emit_signal("change_scene", "Title")
|
||||
|
||||
func _on_Master_Slider_value_changed(value):
|
||||
value = linear2db(value)
|
||||
AudioBus.emit_signal("button_clicked")
|
||||
OptionsController.set_vol(value, "mas_vol")
|
||||
|
||||
func _on_Music_Slider_value_changed(value):
|
||||
value = linear2db(value)
|
||||
AudioBus.emit_signal("button_clicked")
|
||||
OptionsController.set_vol(value, "mus_vol")
|
||||
|
||||
func _on_SFX_Slider_value_changed(value):
|
||||
value = linear2db(value)
|
||||
AudioBus.emit_signal("button_clicked")
|
||||
OptionsController.set_vol(value, "sfx_vol")
|
||||
|
||||
|
||||
@@ -8,9 +8,9 @@ signal change_theme (theme)
|
||||
var f = File.new()
|
||||
var options_file = "user://options.save"
|
||||
var theme = "dark"
|
||||
var mas_vol = 0
|
||||
var mus_vol = 0
|
||||
var sfx_vol = 0
|
||||
var mas_vol = linear2db(1)
|
||||
var mus_vol = linear2db(1)
|
||||
var sfx_vol = linear2db(1)
|
||||
|
||||
func _ready():
|
||||
load_options()
|
||||
@@ -23,6 +23,7 @@ func set_theme(theme_name):
|
||||
save_options()
|
||||
emit_signal("change_theme", theme)
|
||||
save_options()
|
||||
|
||||
func set_vol(volume, type):
|
||||
if type == "mas_vol":
|
||||
mas_vol = volume
|
||||
@@ -61,7 +62,7 @@ func load_options():
|
||||
mus_vol = f.get_var()
|
||||
sfx_vol = f.get_var()
|
||||
f.close()
|
||||
AudioServer.set_bus_volume_db(AudioServer.get_bus_index("Master"), mus_vol)
|
||||
AudioServer.set_bus_volume_db(AudioServer.get_bus_index("Master"), mas_vol)
|
||||
AudioServer.set_bus_volume_db(AudioServer.get_bus_index("BGM"), mus_vol)
|
||||
AudioServer.set_bus_volume_db(AudioServer.get_bus_index("SFX"), sfx_vol)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user