Attempt to refactor components.

This commit is contained in:
Henry Faber 2026-06-08 22:36:07 +01:00
parent e3fb082139
commit 79122a074e
15 changed files with 241 additions and 112 deletions

View file

@ -1,29 +1,24 @@
[gd_scene format=3 uid="uid://6wq3ynesnsha"]
[gd_scene format=3 uid="uid://coix5dqblmu7r"]
[ext_resource type="Script" uid="uid://dulfr27gg4evl" path="res://scripts/player_component.gd" id="1_3ef36"]
[ext_resource type="PackedScene" uid="uid://ddpclu2vdy2ve" path="res://scenes/stock_weapon.tscn" id="2_l5qtw"]
[ext_resource type="Texture2D" uid="uid://cq4we1m1yv22s" path="res://graphics/ship.png" id="3_63g5k"]
[ext_resource type="Script" uid="uid://dss0dbwr71y6m" path="res://scripts/input_component.gd" id="4_14jeh"]
[ext_resource type="Texture2D" uid="uid://b0iavxi8vaxtj" path="res://graphics/ship_thrusters.png" id="4_tg2o1"]
[ext_resource type="Texture2D" uid="uid://crmbupr3qg0j" path="res://graphics/muzzle_flash.png" id="5_ohfsq"]
[ext_resource type="Script" uid="uid://c0rikbakpcags" path="res://scripts/movement_component.gd" id="6_l5qtw"]
[ext_resource type="Script" uid="uid://bgd1hwindc2ui" path="res://scripts/shoot_component.gd" id="7_63g5k"]
[ext_resource type="Script" uid="uid://ylmao2ndp22y" path="res://scripts/weapon_component.gd" id="8_ohfsq"]
[ext_resource type="Script" uid="uid://bqxrdf7mtx0ev" path="res://scenes/player_refactor.gd" id="1_qlg0r"]
[ext_resource type="Texture2D" uid="uid://cq4we1m1yv22s" path="res://graphics/ship.png" id="2_qhqgy"]
[ext_resource type="Texture2D" uid="uid://crmbupr3qg0j" path="res://graphics/muzzle_flash.png" id="4_dqkch"]
[ext_resource type="Texture2D" uid="uid://b0iavxi8vaxtj" path="res://graphics/ship_thrusters.png" id="5_qlg0r"]
[sub_resource type="AtlasTexture" id="AtlasTexture_tuyoq"]
atlas = ExtResource("4_tg2o1")
atlas = ExtResource("5_qlg0r")
region = Rect2(28, 0, 14, 6)
[sub_resource type="AtlasTexture" id="AtlasTexture_fjrip"]
atlas = ExtResource("4_tg2o1")
atlas = ExtResource("5_qlg0r")
region = Rect2(42, 0, 14, 6)
[sub_resource type="AtlasTexture" id="AtlasTexture_smehm"]
atlas = ExtResource("4_tg2o1")
atlas = ExtResource("5_qlg0r")
region = Rect2(1, 0, 14, 6)
[sub_resource type="AtlasTexture" id="AtlasTexture_ur7pv"]
atlas = ExtResource("4_tg2o1")
atlas = ExtResource("5_qlg0r")
region = Rect2(15, 0, 14, 6)
[sub_resource type="SpriteFrames" id="SpriteFrames_y4r1p"]
@ -52,15 +47,15 @@ animations = [{
}]
[sub_resource type="AtlasTexture" id="AtlasTexture_qlg0r"]
atlas = ExtResource("5_ohfsq")
atlas = ExtResource("4_dqkch")
region = Rect2(0, 0, 15, 8)
[sub_resource type="AtlasTexture" id="AtlasTexture_y4r1p"]
atlas = ExtResource("5_ohfsq")
atlas = ExtResource("4_dqkch")
region = Rect2(15, 0, 15, 8)
[sub_resource type="AtlasTexture" id="AtlasTexture_d2wvv"]
atlas = ExtResource("5_ohfsq")
atlas = ExtResource("4_dqkch")
region = Rect2(30, 0, 15, 8)
[sub_resource type="SpriteFrames" id="SpriteFrames_3v2ag"]
@ -90,11 +85,11 @@ size = Vector2(24, 30)
size = Vector2(6, 5.75)
[node name="Player" type="Area2D" unique_id=652131079]
script = ExtResource("1_3ef36")
script = ExtResource("1_qlg0r")
[node name="Ship" type="Sprite2D" parent="." unique_id=1155866924]
unique_name_in_owner = true
texture = ExtResource("3_63g5k")
texture = ExtResource("2_qhqgy")
hframes = 3
region_rect = Rect2(0, 0, 62, 24.370766)
@ -106,7 +101,6 @@ autoplay = "fwd"
[node name="MuzzleFlash" type="AnimatedSprite2D" parent="Ship" unique_id=1584132038]
unique_name_in_owner = true
visible = false
position = Vector2(0.5, -16)
sprite_frames = SubResource("SpriteFrames_3v2ag")
animation = &"stock"
@ -131,27 +125,4 @@ debug_color = Color(0.9843137, 0, 0, 0.80784315)
[node name="WeaponCooldown" type="Timer" parent="." unique_id=269678170]
[node name="InputComponent" type="Node" parent="." unique_id=2022056363]
unique_name_in_owner = true
script = ExtResource("4_14jeh")
metadata/_custom_type_script = "uid://dss0dbwr71y6m"
[node name="MovementComponent" type="Node" parent="." unique_id=964075256 node_paths=PackedStringArray("player")]
unique_name_in_owner = true
script = ExtResource("6_l5qtw")
player = NodePath("..")
speed = 200.0
metadata/_custom_type_script = "uid://c0rikbakpcags"
[node name="ShootComponent" type="Node" parent="." unique_id=623642425]
unique_name_in_owner = true
script = ExtResource("7_63g5k")
metadata/_custom_type_script = "uid://bgd1hwindc2ui"
[node name="WeaponComponent" type="Node" parent="." unique_id=1648685183]
unique_name_in_owner = true
script = ExtResource("8_ohfsq")
weapon_current = ExtResource("2_l5qtw")
metadata/_custom_type_script = "uid://ylmao2ndp22y"
[connection signal="timeout" from="WeaponCooldown" to="." method="_on_weapon_cooldown_timeout"]

View file

@ -1,9 +1,14 @@
[gd_scene format=3 uid="uid://coix5dqblmu7r"]
[gd_scene format=3 uid="uid://6wq3ynesnsha"]
[ext_resource type="Script" uid="uid://bqxrdf7mtx0ev" path="res://scenes/player_refactor.gd" id="1_qlg0r"]
[ext_resource type="Script" uid="uid://dulfr27gg4evl" path="res://scenes/player_component.gd" id="1_ur7pv"]
[ext_resource type="Texture2D" uid="uid://cq4we1m1yv22s" path="res://graphics/ship.png" id="2_qhqgy"]
[ext_resource type="Texture2D" uid="uid://crmbupr3qg0j" path="res://graphics/muzzle_flash.png" id="4_dqkch"]
[ext_resource type="Script" uid="uid://dss0dbwr71y6m" path="res://scripts/input_component.gd" id="4_smehm"]
[ext_resource type="Texture2D" uid="uid://b0iavxi8vaxtj" path="res://graphics/ship_thrusters.png" id="5_qlg0r"]
[ext_resource type="Script" uid="uid://c0rikbakpcags" path="res://scripts/movement_component.gd" id="5_ur7pv"]
[ext_resource type="Script" uid="uid://bgd1hwindc2ui" path="res://scripts/shoot_component.gd" id="6_y4r1p"]
[ext_resource type="Script" uid="uid://ylmao2ndp22y" path="res://scripts/weapon_component.gd" id="7_d2wvv"]
[ext_resource type="PackedScene" uid="uid://ddpclu2vdy2ve" path="res://scenes/stock_weapon.tscn" id="8_3v2ag"]
[sub_resource type="AtlasTexture" id="AtlasTexture_tuyoq"]
atlas = ExtResource("5_qlg0r")
@ -84,45 +89,70 @@ size = Vector2(24, 30)
[sub_resource type="RectangleShape2D" id="RectangleShape2D_dqkch"]
size = Vector2(6, 5.75)
[node name="Player" type="Area2D" unique_id=652131079]
script = ExtResource("1_qlg0r")
[node name="PlayerComponent" type="Node" unique_id=1732759225]
[node name="Ship" type="Sprite2D" parent="." unique_id=1155866924]
[node name="Player" type="Area2D" parent="." unique_id=652131079]
script = ExtResource("1_ur7pv")
[node name="Ship" type="Sprite2D" parent="Player" unique_id=1155866924]
unique_name_in_owner = true
texture = ExtResource("2_qhqgy")
hframes = 3
region_rect = Rect2(0, 0, 62, 24.370766)
[node name="Thrusters" type="AnimatedSprite2D" parent="Ship" unique_id=2096876587]
[node name="Thrusters" type="AnimatedSprite2D" parent="Player/Ship" unique_id=2096876587]
position = Vector2(0, 15)
sprite_frames = SubResource("SpriteFrames_y4r1p")
animation = &"fwd"
autoplay = "fwd"
[node name="MuzzleFlash" type="AnimatedSprite2D" parent="Ship" unique_id=1584132038]
[node name="MuzzleFlash" type="AnimatedSprite2D" parent="Player/Ship" unique_id=1584132038]
unique_name_in_owner = true
visible = false
position = Vector2(0.5, -16)
sprite_frames = SubResource("SpriteFrames_3v2ag")
animation = &"stock"
autoplay = "stock"
[node name="MuzzleBox" type="CollisionShape2D" parent="." unique_id=1042837273]
[node name="MuzzleBox" type="CollisionShape2D" parent="Player" unique_id=1042837273]
unique_name_in_owner = true
position = Vector2(0, -17)
shape = SubResource("RectangleShape2D_qlg0r")
disabled = true
debug_color = Color(1, 0.5058824, 0.21960784, 0.41960785)
[node name="HelpBox" type="CollisionShape2D" parent="." unique_id=938667427]
[node name="HelpBox" type="CollisionShape2D" parent="Player" unique_id=938667427]
position = Vector2(0, 3)
shape = SubResource("RectangleShape2D_tuyoq")
debug_color = Color(0, 1, 0, 0.41960785)
[node name="HitBox" type="CollisionShape2D" parent="." unique_id=485826453]
[node name="HitBox" type="CollisionShape2D" parent="Player" unique_id=485826453]
position = Vector2(0, 2)
shape = SubResource("RectangleShape2D_dqkch")
debug_color = Color(0.9843137, 0, 0, 0.80784315)
[node name="WeaponCooldown" type="Timer" parent="." unique_id=269678170]
[node name="WeaponCooldown" type="Timer" parent="Player" unique_id=269678170]
[connection signal="timeout" from="WeaponCooldown" to="." method="_on_weapon_cooldown_timeout"]
[node name="InputComponent" type="Node" parent="." unique_id=2022056363]
unique_name_in_owner = true
script = ExtResource("4_smehm")
metadata/_custom_type_script = "uid://dss0dbwr71y6m"
[node name="MovementComponent" type="Node" parent="." unique_id=964075256]
unique_name_in_owner = true
script = ExtResource("5_ur7pv")
speed = 200.0
metadata/_custom_type_script = "uid://c0rikbakpcags"
[node name="ShootComponent" type="Node" parent="." unique_id=623642425]
unique_name_in_owner = true
script = ExtResource("6_y4r1p")
metadata/_custom_type_script = "uid://bgd1hwindc2ui"
[node name="WeaponComponent" type="Node" parent="." unique_id=1648685183]
unique_name_in_owner = true
script = ExtResource("7_d2wvv")
weapon_current = ExtResource("8_3v2ag")
metadata/_custom_type_script = "uid://ylmao2ndp22y"
[connection signal="timeout" from="Player/WeaponCooldown" to="Player" method="_on_weapon_cooldown_timeout"]

View file

@ -0,0 +1,34 @@
class_name Player extends Node
# Components managed by Player
@onready var input_component: InputComponent = %InputComponent
@onready var movement_component: MovementComponent = %MovementComponent
@onready var shoot_component: ShootComponent = %ShootComponent
@onready var weapon_component: WeaponComponent = %WeaponComponent
# Variables for Player shooting status
@export var can_shoot: bool = true
@export var is_shooting: bool = false
# Variables for Player position calculations for equidistant bullets
var previous_position: Vector2
var ship_displacement: float
var travel: float = 0
func _process(delta) -> void:
# Read Controls
input_component.update()
# Read Shooting
if input_component.shooting:
is_shooting = true
else: is_shooting = false
if is_shooting == true:
shoot_component.shoot()
# Read Movement Component
movement_component.input = input_component.move_dir
movement_component.tick(delta)

View file

@ -0,0 +1 @@
uid://dulfr27gg4evl

View file

@ -101,7 +101,7 @@ func shoot():
# Instantiate the bullets
var bullet = weapon_current.instantiate()
get_tree().root.add_child(bullet)
prints(bullet_resource.speed,bullet_resource.projectiles, bullet_resource.projectile_spacing)
#prints(bullet.speed,bullet.projectiles, bullet.projectile_spacing)
bullet.position = position + Vector2((b - (projectiles- 1) / 2.0) * PROJECTILE_SPACING /2, MUZZLE_HEIGHT)
# Get weapon speed and spacing for equidistant calculations
@ -110,6 +110,6 @@ func shoot():
#bullet_speed = bullet_resource.speed
# Print which weapon is firing
prints(bullet.shot_data.shot_name, "weapon fired")
#prints(bullet.shot_data.shot_name, "weapon fired")
#travel -= weapon_spacing

View file

@ -2,13 +2,14 @@ extends Area2D
@onready var bullet: PackedScene = load("res://scenes/stock_weapon.tscn")
@export var shot_data: PlayerShot
@export var shot_data: WeaponShot
func _process(delta):
#Calculation position along Y axis
position.y -= shot_data.speed * delta
#Calculation position along Y axis
position.y -= shot_data.speed * delta # Original Speed
#position.y -= 330 * delta # non-shot_data testing
func _on_visible_on_screen_notifier_2d_screen_exited() -> void:
queue_free()
queue_free()

View file

@ -9,7 +9,6 @@ script = ExtResource("2_5286c")
shot_name = "Stock"
speed = 350
projectiles = 3
projectile_spacing = 10.0
metadata/_custom_type_script = "uid://ccdohs4gduee5"
[sub_resource type="RectangleShape2D" id="RectangleShape2D_mvdrj"]

View file

@ -2,7 +2,7 @@
[ext_resource type="PackedScene" uid="uid://14fhj8834pkq" path="res://scenes/ui.tscn" id="1_nnsk1"]
[ext_resource type="Texture2D" uid="uid://b3dqvd23nbmrm" path="res://graphics/cloud layers.png" id="3_4wyf3"]
[ext_resource type="PackedScene" uid="uid://6wq3ynesnsha" path="res://scenes/player_revision.tscn" id="3_k0juu"]
[ext_resource type="PackedScene" uid="uid://6wq3ynesnsha" path="res://scenes/player.tscn" id="3_k0juu"]
[node name="World" type="Node2D" unique_id=1317852169]
@ -78,4 +78,3 @@ hframes = 4
frame = 3
[node name="Player" parent="Level" unique_id=652131079 instance=ExtResource("3_k0juu")]
position = Vector2(106, 312)