diff options
author | Logan <logan@cflip.net> | 2023-04-30 18:51:05 -0600 |
---|---|---|
committer | Logan <logan@cflip.net> | 2023-04-30 18:51:05 -0600 |
commit | f4381c59c1d239400fbd787fe3a5247f0c535460 (patch) | |
tree | 8dfc62aaf276e7f8438e96fec4467bcde917d286 /scripts/basketball.gd | |
parent | f30fbd753b23be1f71b4bada5e7063ac00215c33 (diff) |
Move to Godot 4 and fixes
Diffstat (limited to 'scripts/basketball.gd')
-rw-r--r-- | scripts/basketball.gd | 38 |
1 files changed, 19 insertions, 19 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]: |