fuzzyworld

godot-shooter / commit

Added health powerups to the map, these restore 1 health for the player.

eb5388a05741bc1c761c6da68159a4377ac81486 · Pavel Safronov · 2023-11-06 12:02:26 -0800 · parents 60dd8709e8ae

Added health powerups to the map, these restore 1 health for the player.
 Enemy.tscn       |  1 +
 HealPowerUp.gd   |  8 ++++++
 HealPowerUp.tscn | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 Player.gd        |  7 +++++
 Player.tscn      |  9 ++++---
 Theme.tres       |  4 ++-
 World.tscn       | 13 +++++++++-
 7 files changed, 115 insertions(+), 6 deletions(-)

diff --git a/Enemy.tscn b/Enemy.tscn
index 0a68bb4..ed10e26 100644
--- a/Enemy.tscn
+++ b/Enemy.tscn
@@ -68,6 +68,7 @@ max_health = 5
 [node name="Graphics" type="Node2D" parent="."]
 
 [node name="Alive" type="Sprite" parent="Graphics"]
+modulate = Color( 1, 0.537255, 0, 1 )
 texture = ExtResource( 1 )
 
 [node name="Container" type="Node2D" parent="Graphics/Alive"]
diff --git a/HealPowerUp.gd b/HealPowerUp.gd
new file mode 100644
index 0000000..c28ca49
--- /dev/null
+++ b/HealPowerUp.gd
@@ -0,0 +1,8 @@
+extends Node2D
+
+export var heal_amount = 1
+
+func _on_Area2D_body_entered(body: Node) -> void:
+	if body.has_method("heal"):
+		body.heal(heal_amount)
+		$AnimationPlayer.play("fade_out")
diff --git a/HealPowerUp.tscn b/HealPowerUp.tscn
new file mode 100644
index 0000000..478ae38
--- /dev/null
+++ b/HealPowerUp.tscn
@@ -0,0 +1,79 @@
+[gd_scene load_steps=5 format=2]
+
+[ext_resource path="res://HealPowerUp.gd" type="Script" id=1]
+[ext_resource path="res://assets/kenney_simple-space/PNG/Retina/star_tiny.png" type="Texture" id=2]
+
+[sub_resource type="Animation" id=1]
+length = 0.001
+tracks/0/type = "value"
+tracks/0/path = NodePath(".:modulate")
+tracks/0/interp = 1
+tracks/0/loop_wrap = true
+tracks/0/imported = false
+tracks/0/enabled = true
+tracks/0/keys = {
+"times": PoolRealArray( 0 ),
+"transitions": PoolRealArray( 1 ),
+"update": 0,
+"values": [ Color( 1, 1, 1, 1 ) ]
+}
+
+[sub_resource type="Animation" id=2]
+resource_name = "fade_out"
+tracks/0/type = "value"
+tracks/0/path = NodePath(".:modulate")
+tracks/0/interp = 1
+tracks/0/loop_wrap = true
+tracks/0/imported = false
+tracks/0/enabled = true
+tracks/0/keys = {
+"times": PoolRealArray( 0, 1 ),
+"transitions": PoolRealArray( 1, 1 ),
+"update": 0,
+"values": [ Color( 1, 1, 1, 1 ), Color( 1, 1, 1, 0 ) ]
+}
+tracks/1/type = "method"
+tracks/1/path = NodePath(".")
+tracks/1/interp = 1
+tracks/1/loop_wrap = true
+tracks/1/imported = false
+tracks/1/enabled = true
+tracks/1/keys = {
+"times": PoolRealArray( 1.3 ),
+"transitions": PoolRealArray( 1 ),
+"values": [ {
+"args": [  ],
+"method": "queue_free"
+} ]
+}
+tracks/2/type = "value"
+tracks/2/path = NodePath("Area2D/CollisionPolygon2D:disabled")
+tracks/2/interp = 1
+tracks/2/loop_wrap = true
+tracks/2/imported = false
+tracks/2/enabled = true
+tracks/2/keys = {
+"times": PoolRealArray( 0.1 ),
+"transitions": PoolRealArray( 1 ),
+"update": 1,
+"values": [ true ]
+}
+
+[node name="HealPowerUp" type="Node2D"]
+script = ExtResource( 1 )
+
+[node name="Area2D" type="Area2D" parent="."]
+
+[node name="Sprite" type="Sprite" parent="Area2D"]
+modulate = Color( 0, 1, 0.0156863, 1 )
+texture = ExtResource( 2 )
+
+[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="Area2D"]
+visible = false
+polygon = PoolVector2Array( 0, -15, -16, 0, 0, 16, 16, 0 )
+
+[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
+anims/RESET = SubResource( 1 )
+anims/fade_out = SubResource( 2 )
+
+[connection signal="body_entered" from="Area2D" to="." method="_on_Area2D_body_entered"]
diff --git a/Player.gd b/Player.gd
index 2cf1d89..af9d598 100644
--- a/Player.gd
+++ b/Player.gd
@@ -41,6 +41,13 @@ func kill():
 	$CanvasLayer/CenterContainer/DeathScreen.show()
 	z_index = -1
 
+func heal(amount: int = 1):
+	if dead:
+		return
+	health += amount
+	if health > max_health:
+		health = max_health
+
 func hurt(damage_amount: int = 1):
 	if dead or is_invincible:
 		return
diff --git a/Player.tscn b/Player.tscn
index 522368e..883bf7a 100644
--- a/Player.tscn
+++ b/Player.tscn
@@ -17,15 +17,16 @@ polygon = PoolVector2Array( -0.996349, -22.0002, -8.00133, 7.99867, -7.00166, 9.
 [node name="Graphics" type="Node2D" parent="."]
 
 [node name="Alive" type="Sprite" parent="Graphics"]
+modulate = Color( 0, 1, 0, 1 )
 texture = ExtResource( 1 )
 
 [node name="Control" type="Node2D" parent="Graphics/Alive"]
 
 [node name="HealthLabel" type="Label" parent="Graphics/Alive/Control"]
-margin_left = -25.0046
-margin_top = 27.9959
-margin_right = 40.9954
-margin_bottom = 51.9958
+margin_left = -48.0051
+margin_top = 30.992
+margin_right = 48.9949
+margin_bottom = 65.992
 theme = ExtResource( 5 )
 text = "HEALTH"
 align = 1
diff --git a/Theme.tres b/Theme.tres
index 9f65931..6fbeb7c 100644
--- a/Theme.tres
+++ b/Theme.tres
@@ -4,8 +4,10 @@
 
 [sub_resource type="DynamicFont" id=1]
 size = 64
-outline_size = 2
+outline_size = 3
 outline_color = Color( 1, 0, 0, 1 )
+use_mipmaps = true
+use_filter = true
 font_data = ExtResource( 1 )
 
 [resource]
diff --git a/World.tscn b/World.tscn
index 5ef8223..d7fb400 100644
--- a/World.tscn
+++ b/World.tscn
@@ -1,4 +1,4 @@
-[gd_scene load_steps=8 format=2]
+[gd_scene load_steps=9 format=2]
 
 [ext_resource path="res://assets/kenney_simple-space/PNG/Default/icon_crossLarge.png" type="Texture" id=1]
 [ext_resource path="res://Player.tscn" type="PackedScene" id=2]
@@ -6,6 +6,7 @@
 [ext_resource path="res://World.gd" type="Script" id=4]
 [ext_resource path="res://StarField.tscn" type="PackedScene" id=5]
 [ext_resource path="res://CharacterTheme.tres" type="Theme" id=6]
+[ext_resource path="res://HealPowerUp.tscn" type="PackedScene" id=7]
 
 [sub_resource type="CircleShape2D" id=1]
 radius = 29.0172
@@ -16,6 +17,7 @@ enemy_count = 3
 
 [node name="Player" parent="." groups=["player"] instance=ExtResource( 2 )]
 position = Vector2( 513, 302 )
+health = 5
 
 [node name="Destination" type="Area2D" parent="."]
 
@@ -50,6 +52,15 @@ visible = false
 
 [node name="Environment" type="Node2D" parent="."]
 
+[node name="HealPowerUp" parent="Environment" instance=ExtResource( 7 )]
+position = Vector2( 700, 514 )
+
+[node name="HealPowerUp2" parent="Environment" instance=ExtResource( 7 )]
+position = Vector2( 199, 534 )
+
+[node name="HealPowerUp3" parent="Environment" instance=ExtResource( 7 )]
+position = Vector2( 837, 158 )
+
 [node name="CanvasLayer" type="CanvasLayer" parent="."]
 
 [node name="HUD" parent="CanvasLayer" instance=ExtResource( 3 )]