diff options
author | Logan <logan@cflip.net> | 2022-09-27 12:39:47 -0600 |
---|---|---|
committer | Logan <logan@cflip.net> | 2022-09-27 12:39:47 -0600 |
commit | 70bcca81567d569ee5a17adc3447ac7bbd2f3d6e (patch) | |
tree | 812a7e2fc5d93454c82a52b8a51928b3f1e93d27 | |
parent | 215c67a3aa6a07af05f3af6268bbc82d60925bcc (diff) |
Add camera node and basic camera logic.
-rw-r--r-- | scenes/level.tscn | 12 | ||||
-rw-r--r-- | scripts/basketball.gd | 6 | ||||
-rw-r--r-- | scripts/camera.gd | 4 |
3 files changed, 18 insertions, 4 deletions
diff --git a/scenes/level.tscn b/scenes/level.tscn index 5dc83ea..0b8324f 100644 --- a/scenes/level.tscn +++ b/scenes/level.tscn @@ -1,10 +1,11 @@ -[gd_scene load_steps=8 format=2] +[gd_scene load_steps=9 format=2] [ext_resource path="res://textures/court_lines.png" type="Texture" id=1] [ext_resource path="res://scenes/hoop.tscn" type="PackedScene" id=2] [ext_resource path="res://scenes/basketball.tscn" type="PackedScene" id=3] [ext_resource path="res://scenes/interface.tscn" type="PackedScene" id=4] [ext_resource path="res://textures/court_tile.png" type="Texture" id=5] +[ext_resource path="res://scripts/camera.gd" type="Script" id=6] [sub_resource type="LineShape2D" id=1] d = 10.0 @@ -14,6 +15,15 @@ normal = Vector2( -1, 0 ) [node name="Node2D" type="Node2D"] +[node name="Camera2D" type="Camera2D" parent="."] +position = Vector2( 123, 73 ) +current = true +limit_left = -202 +limit_top = -150 +limit_right = 214 +limit_bottom = 120 +script = ExtResource( 6 ) + [node name="Interface" parent="." instance=ExtResource( 4 )] [node name="Background" type="StaticBody2D" parent="."] diff --git a/scripts/basketball.gd b/scripts/basketball.gd index cc9dfa6..cc794ce 100644 --- a/scripts/basketball.gd +++ b/scripts/basketball.gd @@ -11,7 +11,7 @@ var waiting_for_shoot = true var mouse_over_ball = false func _ready(): - start_position = position + start_position = global_position # This function toggles between dragging the ball for a shot and allowing the physics engine to move # the ball, setting any necessary properties along the way. @@ -48,11 +48,11 @@ func _process(delta): func _input(event): if event.is_action_pressed("shoot") and mouse_over_ball and waiting_for_shoot: is_dragging = true - $Sprite.position = event.position - start_position + $Sprite.position = get_global_mouse_position() - start_position $GhostSprite.visible = true $GhostSprite.rotation = $Sprite.rotation if is_dragging and event is InputEventMouseMotion: - $Sprite.position = event.position - start_position + $Sprite.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. diff --git a/scripts/camera.gd b/scripts/camera.gd new file mode 100644 index 0000000..264bc68 --- /dev/null +++ b/scripts/camera.gd @@ -0,0 +1,4 @@ +extends Camera2D + +func _process(_delta): + position = ($"../Basketball".position + $"../Hoop".position) / 2 |