From 07c63f4122192d208c7f9cf9c1c00858de9800f9 Mon Sep 17 00:00:00 2001 From: Henry Date: Sat, 21 Mar 2026 18:30:26 +0000 Subject: [PATCH] Attempting to set up equidistant bullets based on player movement. --- scenes/game.tscn | 2 +- scenes/stock_weapon.tscn | 6 ++++++ scripts/player.gd | 17 +++++++++++++++-- scripts/stock_weapon.gd | 4 +++- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/scenes/game.tscn b/scenes/game.tscn index 8adc7d2..1867300 100644 --- a/scenes/game.tscn +++ b/scenes/game.tscn @@ -2,6 +2,6 @@ [ext_resource type="PackedScene" uid="uid://bj4fytc3sy482" path="res://scenes/world.tscn" id="1_uwrxv"] -[node name="Game" type="Node2D" unique_id=1673976895] +[node name="Main" type="Node2D" unique_id=1673976895] [node name="World" parent="." unique_id=1317852169 instance=ExtResource("1_uwrxv")] diff --git a/scenes/stock_weapon.tscn b/scenes/stock_weapon.tscn index 98e8b10..f92dfc5 100644 --- a/scenes/stock_weapon.tscn +++ b/scenes/stock_weapon.tscn @@ -4,9 +4,15 @@ [ext_resource type="Resource" uid="uid://cels8t3hqjtsu" path="res://resources/shot_stock.tres" id="2_ckjv1"] [ext_resource type="Texture2D" uid="uid://ti1uy42vnnhw" path="res://graphics/shot.png" id="3_mvdrj"] +[sub_resource type="RectangleShape2D" id="RectangleShape2D_mvdrj"] +size = Vector2(12, 8) + [node name="StockWeapon" type="Area2D" unique_id=1832200900] script = ExtResource("1_hsma2") shot_data = ExtResource("2_ckjv1") [node name="Sprite2D" type="Sprite2D" parent="." unique_id=2134507225] texture = ExtResource("3_mvdrj") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=1890946059] +shape = SubResource("RectangleShape2D_mvdrj") diff --git a/scripts/player.gd b/scripts/player.gd index 78ae529..5c40694 100644 --- a/scripts/player.gd +++ b/scripts/player.gd @@ -46,7 +46,7 @@ func _process(delta): if is_shooting == false: return -func shield_set(_sdvalue: int): +func shield_set(_value: int): return @@ -64,9 +64,22 @@ func shoot(): bullet.position = self.position + Vector2(0,-12) get_tree().root.add_child(bullet) weapon_rate = bullet.shot_data.rate - print(bullet.shot_data.shot_name, " weapon fired") #Print which weapon is firing + prints(bullet.shot_data.shot_name, "weapon fired") #Print which weapon is firing #weapon_cooldown = $WeaponCooldown #weapon_cooldown.wait_time = bullet.shot_data.cooldown #weapon_cooldown.start() #can_shoot = not can_shoot + + + +#I track the vertical distance the last bullet traveled relative to the ship: +# +#travel += bulletSpeed*dt + (Ship.y - prevShipY) +#set prevShipY to Ship.y +# +#when travel > spacing -> fire bullet and +# +#set travel -= spacing +# +#(where spacing is the distance you want bullets to be apart, in pixels) diff --git a/scripts/stock_weapon.gd b/scripts/stock_weapon.gd index 7f3417f..1a50d7e 100644 --- a/scripts/stock_weapon.gd +++ b/scripts/stock_weapon.gd @@ -6,4 +6,6 @@ extends Area2D func _process(delta): - position.y += shot_data.speed * delta + #position.y += shot_data.speed * delta #This works normally + var player_position = get_node("../Player").position + position.y += player_position.y * shot_data.speed * delta