Skip to content

Commit

Permalink
add health regen meta upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
Heidi-Negrete committed Dec 3, 2023
1 parent aa7ed58 commit b4ae174
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 10 deletions.
11 changes: 11 additions & 0 deletions project/resources/meta_upgrades/health_regen.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[gd_resource type="Resource" script_class="MetaUpgrade" load_steps=2 format=3 uid="uid://c6mexu74lkdgj"]

[ext_resource type="Script" path="res://resources/meta_upgrades/meta_upgrade.gd" id="1_ctlrh"]

[resource]
script = ExtResource("1_ctlrh")
id = "health_regen"
max_quantity = 3
experience_cost = 50
title = "Health Regen"
description = "Regenerate health slowly over time."
10 changes: 8 additions & 2 deletions project/scenes/component/health_component.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ extends Node
class_name HealthComponent

signal died
signal health_changed
signal health_decreased
signal health_increased

@export var max_health: float = 10
var current_health
Expand All @@ -14,10 +15,15 @@ func _ready():

func damage(damage_amount: float):
current_health = max(current_health - damage_amount, 0)
health_changed.emit()
health_decreased.emit()
Callable(check_death).call_deferred()


func heal(heal_amount: int):
current_health = min(current_health + heal_amount, max_health)
health_increased.emit()


func get_health_percent():
if max_health <= 0:
return 0
Expand Down
4 changes: 2 additions & 2 deletions project/scenes/component/hit_flash_component.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ extends Node
var hit_flash_tween: Tween

func _ready():
health_component.health_changed.connect(on_health_changed)
health_component.health_decreased.connect(on_health_decreased)
sprite.material = hit_flash_material

func on_health_changed():
func on_health_decreased():
if hit_flash_tween != null && hit_flash_tween.is_valid():
hit_flash_tween.kill()

Expand Down
Binary file added project/scenes/game_object/player/heal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions project/scenes/game_object/player/heal.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://8md3idjg3as2"
path="res://.godot/imported/heal.png-753d09a93bcdb9c24c182230816e1d9c.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://scenes/game_object/player/heal.png"
dest_files=["res://.godot/imported/heal.png-753d09a93bcdb9c24c182230816e1d9c.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
24 changes: 23 additions & 1 deletion project/scenes/game_object/player/player.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
extends CharacterBody2D

@export var arena_time_manager: Node

@onready var heal_animation = $HealAnimation
@onready var health_bar = $HealthBar
@onready var damage_interval_timer = $DamageIntervalTimer
@onready var health_component = $HealthComponent
Expand All @@ -14,6 +17,8 @@ var base_speed = 0
var last_received_damage = 0

func _ready():
heal_animation.hide()
arena_time_manager.arena_difficulty_increased.connect(on_arena_difficulty_increased)
base_speed = velocity_component.max_speed
GameEvents.ability_upgrade_added.connect(on_ability_upgrade_added)
sprite_2d.texture = load(character["sprite_path"])
Expand Down Expand Up @@ -68,7 +73,7 @@ func _on_damage_interval_timer_timeout():
check_deal_damage(last_received_damage)


func _on_health_component_health_changed():
func _on_health_component_health_decreased():
GameEvents.emit_player_damage()
update_health_display()
$HitRandomStreamPlayer.play_random()
Expand All @@ -89,3 +94,20 @@ func _on_collision_area_2d_area_entered(area):

func _on_collision_area_2d_area_exited(_area):
number_colliding_bodies -= 1


func on_arena_difficulty_increased(difficulty: int):
var health_regeneration_quantity = MetaProgression.get_upgrade_count("health_regen")
if health_regeneration_quantity > 0:
var is_thirty_second_interval = (difficulty % 6) == 0
if is_thirty_second_interval:
health_component.heal(health_regeneration_quantity)


func _on_health_component_health_increased():
update_health_display()
heal_animation.show()
heal_animation.play("default")
await heal_animation.animation_finished
heal_animation.stop()
heal_animation.hide()
48 changes: 46 additions & 2 deletions project/scenes/game_object/player/player.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=23 format=3 uid="uid://cq3ir5u82bhyk"]
[gd_scene load_steps=29 format=3 uid="uid://cq3ir5u82bhyk"]

[ext_resource type="Script" path="res://scenes/game_object/player/player.gd" id="1_0aune"]
[ext_resource type="Texture2D" uid="uid://dk7lp3sks48a" path="res://scenes/game_object/player/richard.png" id="1_gn467"]
Expand All @@ -13,6 +13,7 @@
[ext_resource type="AudioStream" uid="uid://chob64pqkly3n" path="res://assets/audio/impactMining_002.ogg" id="5_76qe6"]
[ext_resource type="AudioStream" uid="uid://cnsprl3nnqhwb" path="res://assets/audio/impactMining_003.ogg" id="6_b8lvt"]
[ext_resource type="AudioStream" uid="uid://hxu1rrowfiyv" path="res://assets/audio/impactMining_004.ogg" id="7_a8v34"]
[ext_resource type="Texture2D" uid="uid://8md3idjg3as2" path="res://scenes/game_object/player/heal.png" id="14_ojkwk"]

[sub_resource type="Animation" id="Animation_dv3m0"]
length = 0.001
Expand Down Expand Up @@ -99,6 +100,42 @@ _data = {
"walk": SubResource("Animation_yff7g")
}

[sub_resource type="AtlasTexture" id="AtlasTexture_ct71q"]
atlas = ExtResource("14_ojkwk")
region = Rect2(0, 0, 16, 16)

[sub_resource type="AtlasTexture" id="AtlasTexture_xavto"]
atlas = ExtResource("14_ojkwk")
region = Rect2(16, 0, 16, 16)

[sub_resource type="AtlasTexture" id="AtlasTexture_qb63k"]
atlas = ExtResource("14_ojkwk")
region = Rect2(32, 0, 16, 16)

[sub_resource type="AtlasTexture" id="AtlasTexture_d6sje"]
atlas = ExtResource("14_ojkwk")
region = Rect2(48, 0, 16, 16)

[sub_resource type="SpriteFrames" id="SpriteFrames_1xxkw"]
animations = [{
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_ct71q")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_xavto")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_qb63k")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_d6sje")
}],
"loop": false,
"name": &"default",
"speed": 5.0
}]

[sub_resource type="ShaderMaterial" id="ShaderMaterial_opwfu"]
resource_local_to_scene = true
shader = ExtResource("4_s1i5b")
Expand Down Expand Up @@ -135,6 +172,12 @@ libraries = {
"": SubResource("AnimationLibrary_1ko5t")
}

[node name="HealAnimation" type="AnimatedSprite2D" parent="."]
position = Vector2(23, -20)
sprite_frames = SubResource("SpriteFrames_1xxkw")
frame = 3
frame_progress = 1.0

[node name="HitRandomStreamPlayer" parent="." instance=ExtResource("2_pr1qx")]
streams = Array[AudioStream]([ExtResource("3_pdltg"), ExtResource("4_awv8h"), ExtResource("5_76qe6"), ExtResource("6_b8lvt"), ExtResource("7_a8v34")])

Expand Down Expand Up @@ -199,7 +242,8 @@ shape = SubResource("CircleShape2D_nloqt")
position = Vector2(0, -5)
shape = SubResource("CircleShape2D_pyhhq")

[connection signal="health_changed" from="HealthComponent" to="." method="_on_health_component_health_changed"]
[connection signal="health_decreased" from="HealthComponent" to="." method="_on_health_component_health_decreased"]
[connection signal="health_increased" from="HealthComponent" to="." method="_on_health_component_health_increased"]
[connection signal="timeout" from="DamageIntervalTimer" to="." method="_on_damage_interval_timer_timeout"]
[connection signal="area_entered" from="CollisionArea2D" to="." method="_on_collision_area_2d_area_entered"]
[connection signal="area_exited" from="CollisionArea2D" to="." method="_on_collision_area_2d_area_exited"]
Expand Down
3 changes: 2 additions & 1 deletion project/scenes/main/main.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ layer_0/tile_data = PackedInt32Array(1, 65536, 4, 0, 0, 4, 65549, 0, 4, 65548, 0

[node name="Entities" type="Node" parent="." groups=["entities_layer"]]

[node name="Player" parent="Entities" instance=ExtResource("1_npe2k")]
[node name="Player" parent="Entities" node_paths=PackedStringArray("arena_time_manager") instance=ExtResource("1_npe2k")]
unique_name_in_owner = true
y_sort_enabled = true
position = Vector2(302, 188)
arena_time_manager = NodePath("../../ArenaTimeManager")

[node name="Foreground" type="Node" parent="." groups=["foreground_layer"]]

Expand Down
5 changes: 3 additions & 2 deletions project/scenes/user_interface/meta_menu.tscn
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
[gd_scene load_steps=5 format=3 uid="uid://clihp56hepafs"]
[gd_scene load_steps=6 format=3 uid="uid://clihp56hepafs"]

[ext_resource type="Script" path="res://scenes/user_interface/meta_menu.gd" id="1_l38il"]
[ext_resource type="Resource" uid="uid://bp7xek16yavrd" path="res://resources/meta_upgrades/experience_gain.tres" id="2_otbt2"]
[ext_resource type="TileSet" uid="uid://bu6t2f3c06o87" path="res://resources/tile_set.tres" id="2_sprq2"]
[ext_resource type="Resource" uid="uid://c6mexu74lkdgj" path="res://resources/meta_upgrades/health_regen.tres" id="3_e6kfk"]
[ext_resource type="PackedScene" uid="uid://cubne56e2iung" path="res://scenes/user_interface/vignette.tscn" id="3_f7ehk"]

[node name="MetaMenu" type="CanvasLayer"]
layer = 2
script = ExtResource("1_l38il")
upgrades = Array[Resource("res://resources/meta_upgrades/meta_upgrade.gd")]([ExtResource("2_otbt2")])
upgrades = Array[Resource("res://resources/meta_upgrades/meta_upgrade.gd")]([ExtResource("2_otbt2"), ExtResource("3_e6kfk")])

[node name="TileMap" type="TileMap" parent="."]
tile_set = ExtResource("2_sprq2")
Expand Down

0 comments on commit b4ae174

Please sign in to comment.