Compare commits

...

2 Commits

Author SHA1 Message Date
edgul
3805756269 added labels for health and time 2026-06-01 21:08:48 -04:00
edgul
5050fa8cd8 added player death and custom resources 2026-06-01 20:13:28 -04:00
17 changed files with 356 additions and 22 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://b0kep0pa3fgop"
path="res://.godot/imported/Player Death 64x64.png-a1335d3f0d31c2c547d022fdb8875398.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/graphics/player/dead/Player Death 64x64.png"
dest_files=["res://.godot/imported/Player Death 64x64.png-a1335d3f0d31c2c547d022fdb8875398.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: 1.4 KiB

View File

@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://cw3itaxh0fjob"
path="res://.godot/imported/Player Hurt 48x48.png-a720e51cb19103e76b22ab6c1b81302d.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/graphics/player/hurt/Player Hurt 48x48.png"
dest_files=["res://.godot/imported/Player Hurt 48x48.png-a720e51cb19103e76b22ab6c1b81302d.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

View File

@ -27,12 +27,6 @@ window/size/window_width_override=960
window/size/window_height_override=540
window/stretch/mode="viewport"
[file_customization]
folder_colors={
"res://scripts/": "red"
}
[input]
shove={

View File

@ -6,6 +6,7 @@
[ext_resource type="PackedScene" uid="uid://bhsvqyhsemekq" path="res://scenes/player.tscn" id="3_k3dxm"]
[ext_resource type="Script" uid="uid://gkpbb5sf4gu7" path="res://scripts/area_2d.gd" id="3_v0i7m"]
[ext_resource type="PackedScene" uid="uid://dvdwk2je7ryqr" path="res://scenes/slime.tscn" id="6_6sh32"]
[ext_resource type="PackedScene" uid="uid://nprvldtu15fe" path="res://scenes/ui.tscn" id="7_ejswk"]
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_8ifkp"]
texture = ExtResource("3_eh8dd")
@ -431,5 +432,9 @@ position = Vector2(204, 371)
[node name="Slime2" parent="Enemies" unique_id=2077610743 instance=ExtResource("6_6sh32")]
position = Vector2(705, 243)
[node name="UI" type="CanvasLayer" parent="." unique_id=1754077689]
[node name="Control" parent="UI" unique_id=1267369317 instance=ExtResource("7_ejswk")]
[connection signal="body_entered" from="area" to="area" method="_on_body_entered"]
[connection signal="triggerActiveSignal" from="area" to="." method="_on_area_2d_trigger_active_signal"]

View File

@ -4,6 +4,8 @@
[ext_resource type="Texture2D" uid="uid://d2e455oxjbsf5" path="res://assets/graphics/player/jump/player jump 48x48.png" id="2_dqkch"]
[ext_resource type="Texture2D" uid="uid://dio2ufnpnihce" path="res://assets/graphics/player/idle/Player Idle 48x48.png" id="2_g2els"]
[ext_resource type="Texture2D" uid="uid://bl7p2n2kgw2qx" path="res://assets/graphics/player/idle/player run 48x48.png" id="3_qhqgy"]
[ext_resource type="Texture2D" uid="uid://cw3itaxh0fjob" path="res://assets/graphics/player/hurt/Player Hurt 48x48.png" id="3_qlg0r"]
[ext_resource type="Texture2D" uid="uid://b0kep0pa3fgop" path="res://assets/graphics/player/dead/Player Death 64x64.png" id="3_tuyoq"]
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_elsnr"]
@ -11,10 +13,66 @@
atlas = ExtResource("2_dqkch")
region = Rect2(48, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_pf23h"]
atlas = ExtResource("3_tuyoq")
region = Rect2(0, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_dt7fs"]
atlas = ExtResource("3_tuyoq")
region = Rect2(48, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_wqfne"]
atlas = ExtResource("3_tuyoq")
region = Rect2(96, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_wnwbv"]
atlas = ExtResource("3_tuyoq")
region = Rect2(144, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_gl8cc"]
atlas = ExtResource("3_tuyoq")
region = Rect2(192, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_487ah"]
atlas = ExtResource("3_tuyoq")
region = Rect2(240, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_md1ol"]
atlas = ExtResource("3_tuyoq")
region = Rect2(288, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_bj30b"]
atlas = ExtResource("3_tuyoq")
region = Rect2(336, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_jc3p3"]
atlas = ExtResource("3_tuyoq")
region = Rect2(384, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_hax0n"]
atlas = ExtResource("3_tuyoq")
region = Rect2(432, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_i4ail"]
atlas = ExtResource("2_dqkch")
region = Rect2(96, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_l71n6"]
atlas = ExtResource("3_qlg0r")
region = Rect2(0, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_ke2ow"]
atlas = ExtResource("3_qlg0r")
region = Rect2(48, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_ujl30"]
atlas = ExtResource("3_qlg0r")
region = Rect2(96, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_31cv2"]
atlas = ExtResource("3_qlg0r")
region = Rect2(144, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_qhqgy"]
atlas = ExtResource("2_g2els")
region = Rect2(0, 0, 48, 48)
@ -103,6 +161,41 @@ animations = [{
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_pf23h")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_dt7fs")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_wqfne")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_wnwbv")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_gl8cc")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_487ah")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_md1ol")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_bj30b")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_jc3p3")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_hax0n")
}],
"loop": false,
"name": &"dead",
"speed": 12.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_i4ail")
}],
"loop": false,
@ -111,6 +204,23 @@ animations = [{
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_l71n6")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_ke2ow")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_ujl30")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_31cv2")
}],
"loop": false,
"name": &"hurt",
"speed": 12.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_qhqgy")
}, {
"duration": 1.0,
@ -206,7 +316,7 @@ position = Vector2(-10, -12)
texture_filter = 1
position = Vector2(0, -1)
sprite_frames = SubResource("SpriteFrames_jej6c")
animation = &"apex"
animation = &"dead"
autoplay = "idle"
[node name="Camera2D" type="Camera2D" parent="." unique_id=1215632070]

46
scenes/ui.tscn Normal file
View File

@ -0,0 +1,46 @@
[gd_scene format=3 uid="uid://nprvldtu15fe"]
[ext_resource type="Script" uid="uid://c6402h5oth0i3" path="res://scripts/ui.gd" id="1_nt7q6"]
[node name="Control" type="Control" unique_id=1267369317]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_nt7q6")
[node name="VBoxContainer" type="VBoxContainer" parent="." unique_id=1912230201]
layout_mode = 1
anchors_preset = 10
anchor_right = 1.0
offset_bottom = 23.0
grow_horizontal = 2
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer" unique_id=1969892715]
layout_mode = 2
[node name="MarginContainer" type="MarginContainer" parent="VBoxContainer/HBoxContainer" unique_id=718250745]
layout_mode = 2
size_flags_horizontal = 3
[node name="health" type="Label" parent="VBoxContainer/HBoxContainer/MarginContainer" unique_id=135697385]
layout_mode = 2
text = "health: "
[node name="MarginContainer3" type="MarginContainer" parent="VBoxContainer/HBoxContainer" unique_id=1151577280]
layout_mode = 2
size_flags_horizontal = 3
[node name="time" type="Label" parent="VBoxContainer/HBoxContainer/MarginContainer3" unique_id=194025908]
layout_mode = 2
text = "time: "
[node name="MarginContainer2" type="MarginContainer" parent="VBoxContainer/HBoxContainer" unique_id=2064326436]
layout_mode = 2
size_flags_horizontal = 3
[node name="crates" type="Label" parent="VBoxContainer/HBoxContainer/MarginContainer2" unique_id=1419249039]
layout_mode = 2
text = "crates: "

View File

@ -2,6 +2,8 @@ extends Node2D
signal destroy(body)
signal level_change_signal(level)
signal damage_player_signal(damage, player_health)
signal time_change(remaining_time)
var levels = ["res://scenes/level1.tscn","res://scenes/level2.tscn","res://scenes/level3.tscn"]
var current_level_index = 0
@ -12,8 +14,13 @@ var timer = Timer.new()
var player:Player;
var enemies = {}
var enemy_stats:CharacterStats
var player_stats:CharacterStats
func _ready():
get_window().grab_focus() # Replace with function body.
get_window().grab_focus()
enemy_stats = load("res://scripts/resources/slime_stats.tres")
player_stats = load("res://scripts/resources/player_stats.tres")
reset()
add_child(timer)
timer.wait_time = 1
@ -23,15 +30,17 @@ func _ready():
func timer_tick():
time_available -= 1
time_change.emit(time_available)
if time_available <= 0:
print("you lose")
level_change_signal.emit(levels[current_level_index])
reset()
func reset():
print("reset")
time_available = level_times[current_level_index]
if player:
player.health = 5
player.set_health(player_stats.starting_health)
func stop():
timer.stop()
@ -47,7 +56,6 @@ func _on_area_2d_trigger_active_signal(body, intentMessage):
var crate_num : int = 0
func set_crate_num(count: int):
crate_num = count
# print("number of crates: " + str(crate_num))
if crate_num <= 0:
current_level_index += 1
if current_level_index == levels.size():
@ -58,18 +66,18 @@ func set_crate_num(count: int):
reset()
func _on_slime_damage(body, slime):
print("game controller sees slime damage")
player.health -= enemies[slime]["damage"]
if player.health <= 0:
print("dead")
level_change_signal.emit(levels[current_level_index])
damage_player_signal.emit(enemies[slime]["damage"], player.health)
func add_enemy(slime):
var enemy_stat = {
"health": 5,
"damage": 3
"health": enemy_stats.starting_health,
"damage": enemy_stats.melee_damage
}
enemies[slime] = enemy_stat
func _on_slime_struck(body, slime):
print("game controller sees slime struck")
func _on_player_dead(player):
print("game controller sees dead player")
level_change_signal.emit(levels[current_level_index])

View File

@ -7,6 +7,7 @@ class_name Player extends CharacterBody2D
@onready var graphic: AnimatedSprite2D = $graphic
signal new_player(player)
signal player_dead(player)
const SPEED = 300.0
const JUMP_VELOCITY = -400.0
@ -14,15 +15,16 @@ var direction : float = 0
enum FaceDirection { LEFT, RIGHT }
var facing: FaceDirection = FaceDirection.LEFT
var shove_target: RigidBody2D
enum State { IDLE, RUN, JUMP, APEX, FALL }
enum State { IDLE, RUN, JUMP, APEX, FALL, HURT, DYING, DEAD }
var state: State = State.IDLE
var up_jump:bool = false
var health:int = 4
var health:int = 0;
func _ready():
new_player.emit(self)
func _physics_process(delta: float):
if self.state != State.HURT and self.state != State.DEAD:
handle_input()
handle_movement(delta)
handle_state()
@ -105,9 +107,38 @@ func handle_animation():
graphic.play("apex")
State.FALL:
graphic.play("fall")
State.HURT:
graphic.play("hurt")
State.DYING:
graphic.play("dead")
State.DEAD:
pass
func _on_graphic_animation_finished() -> void:
# switch state from apex to fall
match state:
State.APEX:
State.APEX: # switch state from apex to fall
state = State.FALL
State.HURT: # switch state from hurt to idle
state = State.IDLE
State.DYING:
print("firing dead signal")
state = State.DEAD
player_dead.emit(self)
State.DEAD:
pass
func damage_player(damage: int):
print("player::damager_player: " + str(damage) + " health: " + str(self.health))
if self.state != State.DYING and self.state != State.DEAD:
self.health -= damage
if self.health <= 0:
print("DEAD")
self.state = State.DYING
else:
print("player hurt")
self.state = State.HURT
func set_health(health: int):
print("setting health: " + str(health))
self.health = health

View File

@ -0,0 +1,8 @@
class_name CharacterStats extends Resource
@export var health:int = 100;
@export var max_health:int = 120;
@export var starting_health:int = 100;
@export var melee_damage:int = 10;
@export var range_damage:int = 5;

View File

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

View File

@ -0,0 +1,10 @@
[gd_resource type="Resource" script_class="CharacterStats" format=3 uid="uid://ffycoj1dt84h"]
[ext_resource type="Script" uid="uid://v5se2t1jjaat" path="res://scripts/resources/character_stats.gd" id="1_r32g3"]
[resource]
script = ExtResource("1_r32g3")
health = 30
max_health = 50
starting_health = 30
metadata/_custom_type_script = "uid://v5se2t1jjaat"

View File

@ -0,0 +1,11 @@
[gd_resource type="Resource" script_class="CharacterStats" format=3 uid="uid://cxkrcxxmgtyyr"]
[ext_resource type="Script" uid="uid://v5se2t1jjaat" path="res://scripts/resources/character_stats.gd" id="1_l0etv"]
[resource]
script = ExtResource("1_l0etv")
health = 10
max_health = 15
starting_health = 10
range_damage = 0
metadata/_custom_type_script = "uid://v5se2t1jjaat"

View File

@ -4,11 +4,15 @@ class_name SceneManager extends Node2D
var grenade = preload("res://scenes/grenade.tscn")
@onready var enemies = $"../Enemies"
@onready var player = $"../player"
@onready var control: Control = $"../UI/Control"
func _ready() -> void:
print("scene manager is ready")
GameController.destroy.connect(destroy)
GameController.level_change_signal.connect(change_scene)
GameController.damage_player_signal.connect(damage_player)
GameController.damage_player_signal.connect(control.update_health)
GameController.time_change.connect(control.update_time)
build_level()
func _process(delta: float) -> void:
@ -20,6 +24,12 @@ func build_level() -> void:
update_enemies()
if player:
GameController.player = player
player.set_health(GameController.player_stats.health)
# todo: bug, calling too early I think
# control.update_health(1, GameController.player_stats.health)
if not player.player_dead.is_connected(GameController._on_player_dead):
print("hooking up player dead signal")
player.player_dead.connect(GameController._on_player_dead)
func update_enemies():
for enemy in enemies.get_children():
@ -52,3 +62,6 @@ func update_crates() -> void:
func destroy(body):
if body is BrownBox:
body.queue_free()
func damage_player(damage: int, _health:int):
player.damage_player(damage)

16
scripts/ui.gd Normal file
View File

@ -0,0 +1,16 @@
extends Control
@onready var health_label: Label = $VBoxContainer/HBoxContainer/MarginContainer/health
@onready var time: Label = $VBoxContainer/HBoxContainer/MarginContainer3/time
@onready var crates: Label = $VBoxContainer/HBoxContainer/MarginContainer2/crates
func _ready() -> void:
pass
func _process(delta: float) -> void:
pass
func update_health(damage:int, health:int):
self.health_label.text = "health: " + str(health)
func update_time(remaining_time: int):
self.time.text = "time: " + str(remaining_time)

1
scripts/ui.gd.uid Normal file
View File

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