summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/basketball.gd38
-rw-r--r--scripts/camera.gd16
-rw-r--r--scripts/leaderboard.gd6
-rw-r--r--scripts/mainmenu.gd6
-rw-r--r--scripts/optionsmenu.gd16
-rw-r--r--scripts/pausemenu.gd6
-rw-r--r--scripts/splashscreen.gd9
7 files changed, 49 insertions, 48 deletions
diff --git a/scripts/basketball.gd b/scripts/basketball.gd
index 7a50f69..7616e14 100644
--- a/scripts/basketball.gd
+++ b/scripts/basketball.gd
@@ -2,14 +2,14 @@ extends RigidBody2D
signal reset
-export var spin_speed = -1
-export var move_speed = 60
-export var power_magnitude = 10
-export var drag_radius = 30
+@export var spin_speed = -1
+@export var move_speed = 60
+@export var power_magnitude = 10
+@export var drag_radius = 30
var start_position: Vector2
var start_minimum = drag_radius
-onready var start_maximum = $"../Hoop".position.x - 40
+@onready var start_maximum = $"../Hoop".position.x - 40
var is_dragging = false
var waiting_for_shoot = true
var mouse_over_ball = false
@@ -25,21 +25,21 @@ func toggle_mode():
if waiting_for_shoot:
waiting_for_shoot = false
- var shoot_power = -$Sprite.position * power_magnitude
- apply_impulse(Vector2(2, 2), shoot_power)
+ var shoot_power = -$Sprite2D.position * power_magnitude
+ apply_impulse(shoot_power, Vector2(2, 2))
- var shootAngle = atan2($Sprite.position.y, $Sprite.position.x)
+ var shootAngle = atan2($Sprite2D.position.y, $Sprite2D.position.x)
$ReleaseIndicator.visible = false
- $ReleaseIndicator.position = $Sprite.position
+ $ReleaseIndicator.position = $Sprite2D.position
$ReleaseIndicator.rotation = shootAngle - PI / 2
is_dragging = false
$GhostSprite.visible = false
- $Sprite.position = Vector2(0, 0)
+ $Sprite2D.position = Vector2(0, 0)
else:
# Adds offset of ball's rotation to sprite AFTER the entire object has rotated from physics.
# Done to keep appearance of same rotation to add consistency when resetting the ball.
- $Sprite.rotation += rotation
+ $Sprite2D.rotation += rotation
# Hide the release indicator for the first throw in the next round
if !$"../Hoop".has_scored:
@@ -58,24 +58,24 @@ func _integrate_forces(state):
func _process(delta):
if waiting_for_shoot:
- $Sprite.rotation += spin_speed * delta
+ $Sprite2D.rotation += spin_speed * delta
$GhostSprite.rotation += spin_speed * delta
func _input(event):
if event.is_action_pressed("shoot") and mouse_over_ball and waiting_for_shoot:
is_dragging = true
- $Sprite.position = get_global_mouse_position() - start_position
+ $Sprite2D.position = get_global_mouse_position() - start_position
$GhostSprite.visible = true
- $GhostSprite.rotation = $Sprite.rotation
+ $GhostSprite.rotation = $Sprite2D.rotation
if is_dragging and event is InputEventMouseMotion:
- $Sprite.position = get_global_mouse_position() - start_position
+ $Sprite2D.position = get_global_mouse_position() - start_position
# If the mouse pointer is beyond a certain radius, don't move the sprite any further from
# the start position while still keeping it at the same angle as the mouse pointer.
- var hypot = sqrt(pow($Sprite.position.x, 2) + pow($Sprite.position.y, 2))
+ var hypot = sqrt(pow($Sprite2D.position.x, 2) + pow($Sprite2D.position.y, 2))
if hypot > drag_radius:
- var angle = atan2($Sprite.position.y, $Sprite.position.x)
- $Sprite.position = Vector2(cos(angle), sin(angle)) * drag_radius
+ var angle = atan2($Sprite2D.position.y, $Sprite2D.position.x)
+ $Sprite2D.position = Vector2(cos(angle), sin(angle)) * drag_radius
if event.is_action_released("shoot"):
if !waiting_for_shoot or is_dragging:
toggle_mode()
@@ -92,7 +92,7 @@ func position_changer():
start_position.x = clamp(start_position.x, start_minimum, start_maximum)
# Random
if phase == 2:
- start_position.x = rand_range(start_minimum, start_maximum)
+ start_position.x = randf_range(start_minimum, start_maximum)
func _on_Hoop_score():
if global_variables.score >= phase_increment[0] and global_variables.score < phase_increment[1]:
diff --git a/scripts/camera.gd b/scripts/camera.gd
index 773ff75..9204a08 100644
--- a/scripts/camera.gd
+++ b/scripts/camera.gd
@@ -1,7 +1,7 @@
extends Camera2D
-onready var basketball = $"../Basketball"
-onready var hoop = $"../Hoop"
+@onready var basketball = $"../Basketball"
+@onready var hoop = $"../Hoop"
func _process(_delta):
if !basketball.waiting_for_shoot:
@@ -16,22 +16,22 @@ func adjust_zoom():
# Min and max widths of the court we want visible on screen at once
var min_width = dist_to_hoop + basketball.drag_radius * 3
var max_width = limit_right - limit_left
-
+
var zoom_level = Vector2(1, 1)
# Zoom out the camera if we need to show more on screen
if min_width > limit_right:
- zoom_level = zoom_level * (min_width / limit_right)
+ zoom_level /= (min_width / limit_right)
# Width of the view when the zoom is set to 1
var view_width = get_viewport().get_visible_rect().size.x
# Fit the zoom level within the max width if needed
# TODO: There should also be a vertical limit
- var max_zoom = float(max_width) / float(view_width)
- zoom_level.x = clamp(zoom_level.x, 1, max_zoom)
- zoom_level.y = clamp(zoom_level.y, 1, max_zoom)
-
+ var max_zoom = float(view_width) / float(max_width)
+ zoom_level.x = clamp(zoom_level.x, max_zoom, 1)
+ zoom_level.y = clamp(zoom_level.y, max_zoom, 1)
+
set_zoom(zoom_level)
func _on_Basketball_reset():
diff --git a/scripts/leaderboard.gd b/scripts/leaderboard.gd
index 0373e44..279d3c6 100644
--- a/scripts/leaderboard.gd
+++ b/scripts/leaderboard.gd
@@ -12,7 +12,7 @@ func _ready():
else:
$Control/HBoxContainer.visible = false
$Control/LineEdit.grab_focus()
- if !global_variables.player_name.empty():
+ if !global_variables.player_name.is_empty():
$Control/LineEdit.text = global_variables.player_name
$Control/LineEdit.select_all()
$Control/Label.text = "Your score:\n" + str(global_variables.score)
@@ -26,7 +26,7 @@ func refresh_menu():
get_node(label_score).text = str(global_variables.leaderboard[i][1])
func _on_LineEdit_text_entered(new_text):
- if !new_text.empty():
+ if !new_text.is_empty():
$Control/LineEdit.release_focus()
$Control/LineEdit.focus_mode = FOCUS_NONE
$Control/LineEdit.editable = false
@@ -52,7 +52,7 @@ func _on_QuitButton_pressed():
queue_free()
else:
# warning-ignore:return_value_discarded
- get_tree().change_scene("res://scenes/mainmenu.tscn")
+ get_tree().change_scene_to_file("res://scenes/mainmenu.tscn")
get_tree().paused = false
global_variables.reset_variables()
diff --git a/scripts/mainmenu.gd b/scripts/mainmenu.gd
index c317d22..09d0504 100644
--- a/scripts/mainmenu.gd
+++ b/scripts/mainmenu.gd
@@ -8,16 +8,16 @@ func _ready():
func _on_StartButton_pressed():
# warning-ignore:return_value_discarded
- get_tree().change_scene("res://scenes/level.tscn")
+ get_tree().change_scene_to_file("res://scenes/level.tscn")
func _on_LeaderboardButton_pressed():
- add_child(load("res://scenes/leaderboard.tscn").instance())
+ add_child(load("res://scenes/leaderboard.tscn").instantiate())
func _on_HelpButton_pressed():
pass
func _on_OptionsButton_pressed():
- add_child(preload("res://scenes/optionsmenu.tscn").instance())
+ add_child(preload("res://scenes/optionsmenu.tscn").instantiate())
func _on_CreditsButton_pressed():
pass
diff --git a/scripts/optionsmenu.gd b/scripts/optionsmenu.gd
index 5376e21..e8bccbd 100644
--- a/scripts/optionsmenu.gd
+++ b/scripts/optionsmenu.gd
@@ -3,19 +3,19 @@ extends Control
const max_vol = 30
const min_vol = -30
-onready var MasterValue = $Control/VBoxContainer/GridContainer/VolumeMasterContainer/VolumeMasterValue
-onready var MasterSlider = $Control/VBoxContainer/GridContainer/VolumeMasterContainer/VolumeMasterSlider
-onready var MusicValue = $Control/VBoxContainer/GridContainer/VolumeMusicContainer/VolumeMusicValue
-onready var MusicSlider = $Control/VBoxContainer/GridContainer/VolumeMusicContainer/VolumeMusicSlider
-onready var SFXValue = $Control/VBoxContainer/GridContainer/VolumeSFXContainer/VolumeSFXValue
-onready var SFXSlider = $Control/VBoxContainer/GridContainer/VolumeSFXContainer/VolumeSFXSlider
+@onready var MasterValue = $Control/VBoxContainer/GridContainer/VolumeMasterContainer/VolumeMasterValue
+@onready var MasterSlider = $Control/VBoxContainer/GridContainer/VolumeMasterContainer/VolumeMasterSlider
+@onready var MusicValue = $Control/VBoxContainer/GridContainer/VolumeMusicContainer/VolumeMusicValue
+@onready var MusicSlider = $Control/VBoxContainer/GridContainer/VolumeMusicContainer/VolumeMusicSlider
+@onready var SFXValue = $Control/VBoxContainer/GridContainer/VolumeSFXContainer/VolumeSFXValue
+@onready var SFXSlider = $Control/VBoxContainer/GridContainer/VolumeSFXContainer/VolumeSFXSlider
func _ready():
# When scene is instanced, load the settings from singleton
refresh_menu(global_variables.volume_master, MasterValue, MasterSlider)
refresh_menu(global_variables.volume_music, MusicValue, MusicSlider)
refresh_menu(global_variables.volume_sfx, SFXValue, SFXSlider)
- $Control/VBoxContainer/GridContainer/FullscreenCheckButton.set_pressed_no_signal(OS.window_fullscreen)
+ $Control/VBoxContainer/GridContainer/FullscreenCheckButton.set_pressed_no_signal(((get_window().mode == 4) or (get_window().mode == 3)))
func _input(event):
if event.is_action_pressed("escape"):
@@ -34,7 +34,7 @@ func _on_VolumeSFXSlider_value_changed(value):
update_audio(value, 2, SFXSlider, "volume_sfx_enabled", "volume_sfx", SFXValue)
func _on_FullscreenCheckButton_toggled(_button_pressed):
- OS.window_fullscreen = !OS.window_fullscreen
+ get_window().mode = 4 if (!((get_window().mode == 4) or (get_window().mode == 3))) else 0
func update_audio(value, bus, slider, enabled_var, volume_var, valuelabel):
# Converts percentage into a range value
diff --git a/scripts/pausemenu.gd b/scripts/pausemenu.gd
index bc0d577..92e43c8 100644
--- a/scripts/pausemenu.gd
+++ b/scripts/pausemenu.gd
@@ -14,7 +14,7 @@ func _on_RestartButton_pressed():
global_variables.reset_variables()
func _on_OptionsButton_pressed():
- add_child(preload("res://scenes/optionsmenu.tscn").instance())
+ add_child(preload("res://scenes/optionsmenu.tscn").instantiate())
rename_hover_panel("PAUSED")
func _on_HelpButton_pressed():
@@ -22,10 +22,10 @@ func _on_HelpButton_pressed():
func _on_QuitButton_pressed():
if global_variables.score >= global_variables.leaderboard[9][1]:
- add_child(preload("res://scenes/leaderboard.tscn").instance())
+ add_child(preload("res://scenes/leaderboard.tscn").instantiate())
else:
# warning-ignore:return_value_discarded
- get_tree().change_scene("res://scenes/mainmenu.tscn")
+ get_tree().change_scene_to_file("res://scenes/mainmenu.tscn")
get_tree().paused = false
global_variables.reset_variables()
diff --git a/scripts/splashscreen.gd b/scripts/splashscreen.gd
index 22675a7..933528e 100644
--- a/scripts/splashscreen.gd
+++ b/scripts/splashscreen.gd
@@ -5,11 +5,12 @@ func _ready():
$AnimationPlayer.play("splashscreen")
func _on_AnimationPlayer_animation_finished(_splashscreen):
- change_scene()
+ change_scene_to_file()
func _input(event):
if event.is_action_pressed("escape"):
- change_scene()
+ change_scene_to_file()
-func change_scene():
- get_tree().change_scene("res://scenes/mainmenu.tscn")
+func change_scene_to_file():
+ # warning-ignore:return_value_discarded
+ get_tree().change_scene_to_file("res://scenes/mainmenu.tscn")