Skip to content

Commit

Permalink
hero life
Browse files Browse the repository at this point in the history
  • Loading branch information
ricargoes committed Feb 13, 2024
1 parent faece45 commit 4603d93
Show file tree
Hide file tree
Showing 11 changed files with 151 additions and 10 deletions.
Binary file added resources/ui/bar_v_border.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 resources/ui/bar_v_border.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://vt87ye3ybyhb"
path="res://.godot/imported/bar_v_border.png-40c2137a9d2c98e2faf8333bee69eff6.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://resources/ui/bar_v_border.png"
dest_files=["res://.godot/imported/bar_v_border.png-40c2137a9d2c98e2faf8333bee69eff6.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 added resources/ui/empty_v_bar.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 resources/ui/empty_v_bar.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://bd5pw0yjs0ft3"
path="res://.godot/imported/empty_v_bar.png-5baa32855ac4bf6dfcfde1e01fcb38d3.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://resources/ui/empty_v_bar.png"
dest_files=["res://.godot/imported/empty_v_bar.png-5baa32855ac4bf6dfcfde1e01fcb38d3.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 added resources/ui/full_fuel_bar.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 resources/ui/full_fuel_bar.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://b58k1lvplemds"
path="res://.godot/imported/full_fuel_bar.png-7d49b4e05bba3587dd57840f796485f2.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://resources/ui/full_fuel_bar.png"
dest_files=["res://.godot/imported/full_fuel_bar.png-7d49b4e05bba3587dd57840f796485f2.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
13 changes: 9 additions & 4 deletions scenes/enermy.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ extends CharacterBody2D


@export
var xp_value = 200
var xp_value: int = 200

@export
var life_points = 100
var life_points: float = 100.0

@export
var contact_dps = 20
var contact_dps: float = 50.0

signal defeated(who)

Expand All @@ -24,7 +24,12 @@ func _process(delta: float) -> void:

for body in $ContactDamageArea.get_overlapping_bodies():
if body.has_method("hurt"):
body.hurt(contact_dps)
body.hurt(contact_dps*delta)

func hurt(damage: float):
life_points -= damage
if life_points <= 0:
die()

func die():
defeated.emit(self)
Expand Down
1 change: 0 additions & 1 deletion scenes/game.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ position = Vector2(1073, 521)

[node name="Hero" parent="." instance=ExtResource("1_2n3he")]
position = Vector2(718, 641)
player_speed = 200

[node name="StaticBody2D" type="StaticBody2D" parent="."]
position = Vector2(719, 783)
Expand Down
14 changes: 10 additions & 4 deletions scenes/hero.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ const JUMP_FORCE = 3000
const MAX_JUMP_IMPULSE_TIME: float = 0.3

@export
var player_speed = 20
var player_speed: int = 200
@export
var life_points: float = 100

var jump_impulse_time: float = 0.0

func _ready() -> void:
velocity.x = player_speed
$UI.sync_life(life_points)

func _process(delta: float) -> void:

Expand All @@ -25,10 +28,13 @@ func _process(delta: float) -> void:
move_and_slide()

if global_position.y > GameConstants.DEATH_GLOBAL_Y_POSITION:
die()
hurt(1000)

func hurt(damage):
die()
func hurt(damage: float):
life_points -= damage
$UI.sync_life(life_points)
if life_points <= 0:
die()

func die():
get_tree().quit()
26 changes: 25 additions & 1 deletion scenes/hero.tscn
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
[gd_scene load_steps=4 format=3 uid="uid://f31q7ameb6hm"]
[gd_scene load_steps=8 format=3 uid="uid://f31q7ameb6hm"]

[ext_resource type="Texture2D" uid="uid://5rou5wm7frds" path="res://resources/icon.svg" id="1_06r7y"]
[ext_resource type="Script" path="res://scenes/hero.gd" id="1_omy4t"]
[ext_resource type="Script" path="res://scenes/ui.gd" id="3_fjqen"]
[ext_resource type="Texture2D" uid="uid://bd5pw0yjs0ft3" path="res://resources/ui/empty_v_bar.png" id="3_kjtew"]
[ext_resource type="Texture2D" uid="uid://b58k1lvplemds" path="res://resources/ui/full_fuel_bar.png" id="4_5m4m8"]
[ext_resource type="Texture2D" uid="uid://vt87ye3ybyhb" path="res://resources/ui/bar_v_border.png" id="4_r372t"]

[sub_resource type="RectangleShape2D" id="RectangleShape2D_ihnas"]
size = Vector2(128, 128)
Expand All @@ -21,3 +25,23 @@ shape = SubResource("RectangleShape2D_ihnas")
offset = Vector2(0, -270)
limit_top = 270
limit_bottom = 1080

[node name="UI" type="CanvasLayer" parent="."]
script = ExtResource("3_fjqen")

[node name="LifeBar" type="TextureProgressBar" parent="UI"]
unique_name_in_owner = true
offset_left = 35.0
offset_top = 25.0
offset_right = 72.0
offset_bottom = 180.0
value = 50.0
fill_mode = 3
nine_patch_stretch = true
stretch_margin_left = 3
stretch_margin_top = 3
stretch_margin_right = 3
stretch_margin_bottom = 3
texture_under = ExtResource("3_kjtew")
texture_over = ExtResource("4_r372t")
texture_progress = ExtResource("4_5m4m8")
5 changes: 5 additions & 0 deletions scenes/ui.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
extends CanvasLayer


func sync_life(actual_value: float):
%LifeBar.value = actual_value

0 comments on commit 4603d93

Please sign in to comment.