Refactor enemy and shooting components to improve bullet spawn logic and adjust enemy size

This commit is contained in:
2025-04-26 03:17:42 +02:00
parent f01645c094
commit d95176fba0
25 changed files with 439 additions and 83 deletions

42
objects/bg.tscn Normal file
View File

@@ -0,0 +1,42 @@
[gd_scene load_steps=8 format=3 uid="uid://dtjrpkhssq32a"]
[ext_resource type="Texture2D" uid="uid://t7mulx3226o0" path="res://sprites/backgrounds/Background_2.png" id="1_w23vv"]
[ext_resource type="Texture2D" uid="uid://c7i1ariim7idx" path="res://sprites/backgrounds/Background_1.png" id="2_pm10e"]
[ext_resource type="Texture2D" uid="uid://bnsghs5y3pw5s" path="res://sprites/backgrounds/8.png" id="3_cvs3x"]
[ext_resource type="Texture2D" uid="uid://tk2bj7w1jxgj" path="res://sprites/backgrounds/background1.png" id="4_4j3tt"]
[ext_resource type="Texture2D" uid="uid://dwxbabw207t3r" path="res://sprites/backgrounds/background2.png" id="5_mgjfj"]
[ext_resource type="Texture2D" uid="uid://j0d5cqrrftjj" path="res://sprites/backgrounds/background3.png" id="6_le8kl"]
[ext_resource type="Texture2D" uid="uid://cj2yaw03r4q82" path="res://sprites/backgrounds/background4a.png" id="7_nkaxn"]
[node name="BG" type="Node2D"]
metadata/_edit_group_ = true
[node name="Sprite2D" type="Sprite2D" parent="."]
texture = ExtResource("1_w23vv")
[node name="Sprite2D2" type="Sprite2D" parent="."]
texture = ExtResource("2_pm10e")
[node name="8" type="Sprite2D" parent="."]
position = Vector2(-30, -25)
texture = ExtResource("3_cvs3x")
[node name="Background1" type="Sprite2D" parent="."]
visible = false
position = Vector2(14, 335)
texture = ExtResource("4_4j3tt")
[node name="Background2" type="Sprite2D" parent="."]
visible = false
position = Vector2(14, 335)
texture = ExtResource("5_mgjfj")
[node name="Background3" type="Sprite2D" parent="."]
visible = false
position = Vector2(10, 355)
texture = ExtResource("6_le8kl")
[node name="Background4a" type="Sprite2D" parent="."]
visible = false
position = Vector2(10, 355)
texture = ExtResource("7_nkaxn")

View File

@@ -21,7 +21,6 @@ shape = SubResource("RectangleShape2D_dj5g5")
[node name="Root" type="Node2D" parent="."]
[node name="Body" type="Node2D" parent="Root"]
scale = Vector2(0.5, 0.5)
[node name="Base" type="Sprite2D" parent="Root/Body"]
texture = ExtResource("1_jcisc")
@@ -37,7 +36,7 @@ texture = ExtResource("3_k41y7")
hframes = 2
[node name="Sprite2D" type="Sprite2D" parent="Root"]
position = Vector2(6, 1)
position = Vector2(3, 1)
rotation = 0.785398
texture = ExtResource("4_vq1oq")

View File

@@ -1,7 +1,7 @@
[gd_scene load_steps=18 format=3 uid="uid://bwdlmualj6xbw"]
[ext_resource type="Shader" uid="uid://bs4xvm4qkurpr" path="res://shaders/hit_flash.tres" id="1_ep4yr"]
[ext_resource type="Texture2D" uid="uid://xes6mt2dd5gu" path="res://sprites/robot_cutout.png" id="1_uh38l"]
[ext_resource type="Texture2D" uid="uid://cu72810eyk4dx" path="res://sprites/enemy-robot.png" id="2_hjtwe"]
[ext_resource type="Script" path="res://scripts/components/health.gd" id="2_o170m"]
[ext_resource type="Script" path="res://scripts/components/damage_component.gd" id="4_4eajk"]
[ext_resource type="Script" path="res://scripts/components/side_to_side_movement.gd" id="4_gbsq8"]
@@ -16,7 +16,7 @@
[ext_resource type="AudioStream" uid="uid://dyev46uqusimi" path="res://sfx/shoot.wav" id="14_tdjks"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_pwwji"]
size = Vector2(18, 27)
size = Vector2(25, 31)
[sub_resource type="ShaderMaterial" id="ShaderMaterial_j18j0"]
shader = ExtResource("1_ep4yr")
@@ -24,18 +24,24 @@ shader_parameter/enabled = false
shader_parameter/tint = Color(1, 1, 1, 1)
[sub_resource type="RectangleShape2D" id="RectangleShape2D_ejbqt"]
size = Vector2(18, 27)
size = Vector2(25, 31)
[node name="Enemy" type="CharacterBody2D"]
collision_layer = 8
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2(0, 0.5)
position = Vector2(-1.5, 0.5)
shape = SubResource("RectangleShape2D_pwwji")
[node name="Sprite2D" type="Sprite2D" parent="."]
material = SubResource("ShaderMaterial_j18j0")
texture = ExtResource("1_uh38l")
texture = ExtResource("2_hjtwe")
[node name="right bullet spawn" type="Node2D" parent="Sprite2D"]
position = Vector2(16, 7)
[node name="left bullet spawn" type="Node2D" parent="Sprite2D"]
position = Vector2(-17, 7)
[node name="HealthComponent" type="Node" parent="." node_paths=PackedStringArray("hurt_fx")]
script = ExtResource("2_o170m")
@@ -54,11 +60,13 @@ wait_time = 0.5
left_ray = NodePath("../Left Ray")
right_ray = NodePath("../Right Ray")
[node name="PeriodicShootingComponent" type="Node" parent="." node_paths=PackedStringArray("side_to_side_movement", "root")]
[node name="PeriodicShootingComponent" type="Node" parent="." node_paths=PackedStringArray("side_to_side_movement", "root", "bullet_spawn_right", "bullet_spawn_left")]
process_mode = 3
script = ExtResource("5_m03v0")
side_to_side_movement = NodePath("../SideToSideMovement")
root = NodePath("..")
bullet_spawn_right = NodePath("../Sprite2D/right bullet spawn")
bullet_spawn_left = NodePath("../Sprite2D/left bullet spawn")
[node name="EnemyDeathComponent" type="Node" parent="." node_paths=PackedStringArray("root", "collision_shape_2d", "health_component")]
script = ExtResource("6_6p3gr")
@@ -72,7 +80,7 @@ collision_layer = 8
collision_mask = 20
[node name="CollisionShape2D" type="CollisionShape2D" parent="Hitbox"]
position = Vector2(0, 0.5)
position = Vector2(-1.5, 0.5)
shape = SubResource("RectangleShape2D_ejbqt")
debug_color = Color(0.913521, 0.265052, 0.323172, 0.42)

File diff suppressed because one or more lines are too long

View File

@@ -6,6 +6,8 @@ extends Node
@export var shoot_direction: Vector2 = Vector2.RIGHT
@export var side_to_side_movement: SideToSideMovement
@export var root: Node2D
@export var bullet_spawn_right: Node2D
@export var bullet_spawn_left: Node2D
var timer: Timer
@@ -19,13 +21,15 @@ func _process(_delta: float) -> void:
if side_to_side_movement:
shoot_direction = side_to_side_movement.direction if side_to_side_movement.direction != Vector2.ZERO else Vector2.RIGHT
func shoot() -> void:
if shoot_direction == Vector2.ZERO:
return
var bullet_instance: Node2D = bullet_scene.instantiate()
var bullet_instance: Node2D = bullet_scene.instantiate()
var bullet_component: BulletComponent = bullet_instance.get_node("BulletComponent")
bullet_instance.position = root.position
var spawn_position: Vector2 = bullet_spawn_right.global_position if shoot_direction == Vector2.RIGHT else bullet_spawn_left.global_position
bullet_instance.position = spawn_position
bullet_component.direction = shoot_direction
get_tree().current_scene.add_child(bullet_instance)

BIN
sprites/backgrounds/10.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

@@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://ce4mcgldseibw"
path="res://.godot/imported/10.png-8cbdefc501d229cc1669c9179471009c.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://sprites/backgrounds/10.png"
dest_files=["res://.godot/imported/10.png-8cbdefc501d229cc1669c9179471009c.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

BIN
sprites/backgrounds/8.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

View File

@@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://bnsghs5y3pw5s"
path="res://.godot/imported/8.png-bb71f6c7376cbea021f2f20e37aa177e.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://sprites/backgrounds/8.png"
dest_files=["res://.godot/imported/8.png-bb71f6c7376cbea021f2f20e37aa177e.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

View File

@@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://c7i1ariim7idx"
path="res://.godot/imported/Background_1.png-88e643953fc13fa1e70ac0244fbc5898.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://sprites/backgrounds/Background_1.png"
dest_files=["res://.godot/imported/Background_1.png-88e643953fc13fa1e70ac0244fbc5898.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

@@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://t7mulx3226o0"
path="res://.godot/imported/Background_2.png-45fff0e5ddcf2e05dd3fb71a1e9317df.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://sprites/backgrounds/Background_2.png"
dest_files=["res://.godot/imported/Background_2.png-45fff0e5ddcf2e05dd3fb71a1e9317df.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.5 KiB

View File

@@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://tk2bj7w1jxgj"
path="res://.godot/imported/background1.png-66b0cc47140b57ad868cebfe69504a41.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://sprites/backgrounds/background1.png"
dest_files=["res://.godot/imported/background1.png-66b0cc47140b57ad868cebfe69504a41.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View File

@@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://dwxbabw207t3r"
path="res://.godot/imported/background2.png-c2f477c59f01bc7791842fd920b60236.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://sprites/backgrounds/background2.png"
dest_files=["res://.godot/imported/background2.png-c2f477c59f01bc7791842fd920b60236.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

View File

@@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://j0d5cqrrftjj"
path="res://.godot/imported/background3.png-54eb463beb4342c4c4342bfb58567576.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://sprites/backgrounds/background3.png"
dest_files=["res://.godot/imported/background3.png-54eb463beb4342c4c4342bfb58567576.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

View File

@@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://cj2yaw03r4q82"
path="res://.godot/imported/background4a.png-295c4f69d4814e4bce97ab0b89905e75.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://sprites/backgrounds/background4a.png"
dest_files=["res://.godot/imported/background4a.png-295c4f69d4814e4bce97ab0b89905e75.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

View File

@@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://derf8j6ihurdc"
path="res://.godot/imported/background4b.png-8b357b080110e3ab0e78ebabebea8d71.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://sprites/backgrounds/background4b.png"
dest_files=["res://.godot/imported/background4b.png-8b357b080110e3ab0e78ebabebea8d71.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

BIN
sprites/enemy-robot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 557 B

View File

@@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://cu72810eyk4dx"
path="res://.godot/imported/enemy-robot.png-12e72aa25aae71e346ad716199f60b58.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://sprites/enemy-robot.png"
dest_files=["res://.godot/imported/enemy-robot.png-12e72aa25aae71e346ad716199f60b58.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1