Added shield and score UI; player collision signal connected to enemy

This commit is contained in:
Henry 2025-12-07 09:54:50 +00:00
parent 996a0bb8f7
commit 8175e1469d
17 changed files with 321 additions and 15 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 599 B

View file

@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://dkv6xa8ir2j27"
path="res://.godot/imported/bar_background.png-35ce8beb14ccfaf777d8509da9ea057d.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://resources/bar_background.png"
dest_files=["res://.godot/imported/bar_background.png-35ce8beb14ccfaf777d8509da9ea057d.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
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/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
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: 629 B

View file

@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://cs0do05fosv40"
path="res://.godot/imported/bar_foreground.png-43a726296b8c8f0bd9259ff035b044ae.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://resources/bar_foreground.png"
dest_files=["res://.godot/imported/bar_foreground.png-43a726296b8c8f0bd9259ff035b044ae.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
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/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
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

17
scenes/EnemyBullet.gd Normal file
View file

@ -0,0 +1,17 @@
extends Area2D
@export var speed = 150
func start(pos):
position = pos
func _process(delta):
position.y += speed * delta
func _on_visible_on_screen_notifier_2d_screen_exited():
queue_free()
func _on_area_entered(area):
if area.name == "Player":
queue_free()
area.shield -= 1

View file

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

22
scenes/EnemyBullet.tscn Normal file
View file

@ -0,0 +1,22 @@
[gd_scene load_steps=4 format=3 uid="uid://pwikm8fsvc2p"]
[ext_resource type="Script" uid="uid://denqaif0c3kk2" path="res://scenes/EnemyBullet.gd" id="1_s6wdq"]
[ext_resource type="Texture2D" uid="uid://dubjbfdp6ep34" path="res://resources/Mini Pixel Pack 3/Projectiles/Enemy_projectile (16 x 16).png" id="2_la4vt"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_eoqba"]
size = Vector2(6, 6)
[node name="EnemyBullet" type="Area2D"]
script = ExtResource("1_s6wdq")
[node name="Sprite2D" type="Sprite2D" parent="."]
texture = ExtResource("2_la4vt")
hframes = 4
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("RectangleShape2D_eoqba")
[node name="VisibleOnScreenNotifier2D" type="VisibleOnScreenNotifier2D" parent="."]
[connection signal="area_entered" from="." to="." method="_on_area_entered"]
[connection signal="screen_exited" from="VisibleOnScreenNotifier2D" to="." method="_on_visible_on_screen_notifier_2d_screen_exited"]

View file

@ -1,5 +1,6 @@
extends Area2D extends Area2D
var bullet_scene = preload("res://scenes/EnemyBullet.tscn")
signal died signal died
var start_pos = Vector2.ZERO var start_pos = Vector2.ZERO
@ -24,6 +25,9 @@ func _on_timer_timeout():
speed = randf_range(75, 100) speed = randf_range(75, 100)
func _on_shoot_timer_timeout(): func _on_shoot_timer_timeout():
var b = bullet_scene.instantiate()
get_tree().root.add_child(b)
b.start(position)
$ShootTimer.wait_time = randf_range(4, 20) $ShootTimer.wait_time = randf_range(4, 20)
$ShootTimer.start() $ShootTimer.start()

View file

@ -18,3 +18,4 @@ func spawn_enemies():
func _on_enemy_died(value): func _on_enemy_died(value):
score += value score += value
$CanvasLayer/UI.update_score(score)

View file

@ -1,9 +1,10 @@
[gd_scene load_steps=8 format=3 uid="uid://ce5rw02b3373d"] [gd_scene load_steps=9 format=3 uid="uid://ce5rw02b3373d"]
[ext_resource type="Script" uid="uid://b2tub370i3s3v" path="res://scenes/main.gd" id="1_jyhfs"] [ext_resource type="Script" uid="uid://b2tub370i3s3v" path="res://scenes/main.gd" id="1_jyhfs"]
[ext_resource type="Texture2D" uid="uid://jj8b7vqj3ihx" path="res://resources/Mini Pixel Pack 3/Space_BG (2 frames) (64 x 64).png" id="2_tbgi4"] [ext_resource type="Texture2D" uid="uid://jj8b7vqj3ihx" path="res://resources/Mini Pixel Pack 3/Space_BG (2 frames) (64 x 64).png" id="2_tbgi4"]
[ext_resource type="PackedScene" uid="uid://bkuucjejc7p2v" path="res://scenes/player.tscn" id="3_tefeu"] [ext_resource type="PackedScene" uid="uid://bkuucjejc7p2v" path="res://scenes/player.tscn" id="3_tefeu"]
[ext_resource type="PackedScene" uid="uid://c4vq2ytntfvoj" path="res://scenes/enemy.tscn" id="4_o6xl0"] [ext_resource type="PackedScene" uid="uid://c4vq2ytntfvoj" path="res://scenes/enemy.tscn" id="4_o6xl0"]
[ext_resource type="PackedScene" uid="uid://k0yw686ys6ug" path="res://scenes/ui.tscn" id="5_tbgi4"]
[sub_resource type="Animation" id="Animation_vcsgt"] [sub_resource type="Animation" id="Animation_vcsgt"]
length = 0.001 length = 0.001
@ -62,3 +63,11 @@ libraries = {
autoplay = "scroll" autoplay = "scroll"
[node name="Enemy" parent="." instance=ExtResource("4_o6xl0")] [node name="Enemy" parent="." instance=ExtResource("4_o6xl0")]
position = Vector2(-13, 3)
[node name="CanvasLayer" type="CanvasLayer" parent="."]
[node name="UI" parent="CanvasLayer" instance=ExtResource("5_tbgi4")]
[connection signal="area_entered" from="Player" to="Player" method="_on_area_entered"]
[connection signal="shield_changed" from="Player" to="CanvasLayer/UI" method="update_shield"]

View file

@ -1,5 +1,12 @@
extends Area2D extends Area2D
signal died
signal shield_changed
@export var max_shield = 10
var shield = max_shield:
set = set_shield
@export var speed = 150 @export var speed = 150
@export var cooldown = 0.25 @export var cooldown = 0.25
@export var bullet_scene : PackedScene @export var bullet_scene : PackedScene
@ -26,6 +33,18 @@ func shoot():
func _on_gun_cooldown_timeout(): func _on_gun_cooldown_timeout():
can_shoot = true can_shoot = true
func set_shield(value):
shield = min(max_shield, value)
shield_changed.emit(max_shield, shield)
if shield <= 0:
hide()
died.emit()
func _on_area_entered(area):
if area.is_in_group("enemies"):
area.explode()
shield -= max_shield / 2
func _process(delta): func _process(delta):
var input = Input.get_vector("left", "right", "up", "down") var input = Input.get_vector("left", "right", "up", "down")
if input.x > 0: if input.x > 0:

20
scenes/score_counter.gd Normal file
View file

@ -0,0 +1,20 @@
extends HBoxContainer
var digit_coords = {
1: Vector2(0, 0),
2: Vector2(8, 0),
3: Vector2(16, 0),
4: Vector2(24, 0),
5: Vector2(32, 0),
6: Vector2(0, 8),
7: Vector2(8, 8),
8: Vector2(16, 8),
9: Vector2(24, 8),
0: Vector2(32, 8)
}
func display_digits(n):
var s = "%08d" % n
for i in 8:
get_child(i).texture.region = Rect2(digit_coords[int(s[i])],
Vector2(8, 8))

View file

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

84
scenes/score_counter.tscn Normal file
View file

@ -0,0 +1,84 @@
[gd_scene load_steps=11 format=3 uid="uid://b3rcs8xlsvm02"]
[ext_resource type="Script" uid="uid://dgcss5ggpd777" path="res://scenes/score_counter.gd" id="1_ep32e"]
[ext_resource type="Texture2D" uid="uid://ddh7mk2ekhq3u" path="res://resources/Mini Pixel Pack 3/UI objects/Number_font (8 x 8).png" id="2_f43bp"]
[sub_resource type="AtlasTexture" id="AtlasTexture_ep32e"]
atlas = ExtResource("2_f43bp")
region = Rect2(32, 8, 8, 8)
[sub_resource type="AtlasTexture" id="AtlasTexture_f43bp"]
atlas = ExtResource("2_f43bp")
region = Rect2(32, 8, 8, 8)
[sub_resource type="AtlasTexture" id="AtlasTexture_kry78"]
atlas = ExtResource("2_f43bp")
region = Rect2(32, 8, 8, 8)
[sub_resource type="AtlasTexture" id="AtlasTexture_lqfp5"]
atlas = ExtResource("2_f43bp")
region = Rect2(32, 8, 8, 8)
[sub_resource type="AtlasTexture" id="AtlasTexture_2qpgf"]
atlas = ExtResource("2_f43bp")
region = Rect2(32, 8, 8, 8)
[sub_resource type="AtlasTexture" id="AtlasTexture_vbwnf"]
atlas = ExtResource("2_f43bp")
region = Rect2(32, 8, 8, 8)
[sub_resource type="AtlasTexture" id="AtlasTexture_3wgod"]
atlas = ExtResource("2_f43bp")
region = Rect2(32, 8, 8, 8)
[sub_resource type="AtlasTexture" id="AtlasTexture_quku1"]
atlas = ExtResource("2_f43bp")
region = Rect2(32, 8, 8, 8)
[node name="ScoreCounter" type="HBoxContainer"]
anchors_preset = 10
anchor_right = 1.0
grow_horizontal = 2
size_flags_horizontal = 8
theme_override_constants/separation = 0
script = ExtResource("1_ep32e")
[node name="Digit0" type="TextureRect" parent="."]
layout_mode = 2
texture = SubResource("AtlasTexture_ep32e")
stretch_mode = 5
[node name="Digit1" type="TextureRect" parent="."]
layout_mode = 2
texture = SubResource("AtlasTexture_f43bp")
stretch_mode = 5
[node name="Digit2" type="TextureRect" parent="."]
layout_mode = 2
texture = SubResource("AtlasTexture_kry78")
stretch_mode = 5
[node name="Digit3" type="TextureRect" parent="."]
layout_mode = 2
texture = SubResource("AtlasTexture_lqfp5")
stretch_mode = 5
[node name="Digit4" type="TextureRect" parent="."]
layout_mode = 2
texture = SubResource("AtlasTexture_2qpgf")
stretch_mode = 5
[node name="Digit5" type="TextureRect" parent="."]
layout_mode = 2
texture = SubResource("AtlasTexture_vbwnf")
stretch_mode = 5
[node name="Digit6" type="TextureRect" parent="."]
layout_mode = 2
texture = SubResource("AtlasTexture_3wgod")
stretch_mode = 5
[node name="Digit7" type="TextureRect" parent="."]
layout_mode = 2
texture = SubResource("AtlasTexture_quku1")
stretch_mode = 5

12
scenes/ui.gd Normal file
View file

@ -0,0 +1,12 @@
extends MarginContainer
@onready var shield_bar = $HBoxContainer/ShieldBar
@onready var score_counter = $HBoxContainer/ScoreCounter
func update_score(value):
score_counter.display_digits(value)
func update_shield(max_value, value):
shield_bar.max_value = max_value
shield_bar.value = value

1
scenes/ui.gd.uid Normal file
View file

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

35
scenes/ui.tscn Normal file
View file

@ -0,0 +1,35 @@
[gd_scene load_steps=5 format=3 uid="uid://k0yw686ys6ug"]
[ext_resource type="Script" uid="uid://dv6s1gx40k0v1" path="res://scenes/ui.gd" id="1_gdt2y"]
[ext_resource type="Texture2D" uid="uid://dkv6xa8ir2j27" path="res://resources/bar_background.png" id="1_x4jx1"]
[ext_resource type="Texture2D" uid="uid://cs0do05fosv40" path="res://resources/bar_foreground.png" id="2_yev5y"]
[ext_resource type="PackedScene" uid="uid://b3rcs8xlsvm02" path="res://scenes/score_counter.tscn" id="4_wm3ai"]
[node name="UI" type="MarginContainer"]
anchors_preset = 10
anchor_right = 1.0
offset_bottom = 10.0
grow_horizontal = 2
theme_override_constants/margin_left = 10
theme_override_constants/margin_top = 10
theme_override_constants/margin_right = 10
theme_override_constants/margin_bottom = 10
script = ExtResource("1_gdt2y")
[node name="HBoxContainer" type="HBoxContainer" parent="."]
layout_mode = 2
[node name="ShieldBar" type="TextureProgressBar" parent="HBoxContainer"]
custom_minimum_size = Vector2(80, 16)
layout_mode = 2
value = 100.0
nine_patch_stretch = true
stretch_margin_left = 3
stretch_margin_top = 3
stretch_margin_right = 3
stretch_margin_bottom = 3
texture_under = ExtResource("1_x4jx1")
texture_progress = ExtResource("2_yev5y")
[node name="ScoreCounter" parent="HBoxContainer" instance=ExtResource("4_wm3ai")]
layout_mode = 2