Week 6: player health, damage animation, enemy damage
This commit is contained in:
parent
94ad4f45cc
commit
77eccef08c
BIN
assets/graphics/player/death/Player Death 64x64.png
Normal file
BIN
assets/graphics/player/death/Player Death 64x64.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.5 KiB |
34
assets/graphics/player/death/Player Death 64x64.png.import
Normal file
34
assets/graphics/player/death/Player Death 64x64.png.import
Normal file
@ -0,0 +1,34 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://bf0ysio1qxdu"
|
||||
path="res://.godot/imported/Player Death 64x64.png-0c6ff54e7d9aad74b66dce47376541f8.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://assets/graphics/player/death/Player Death 64x64.png"
|
||||
dest_files=["res://.godot/imported/Player Death 64x64.png-0c6ff54e7d9aad74b66dce47376541f8.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
|
BIN
assets/graphics/player/hurt/Player Hurt 48x48.png
Normal file
BIN
assets/graphics/player/hurt/Player Hurt 48x48.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
34
assets/graphics/player/hurt/Player Hurt 48x48.png.import
Normal file
34
assets/graphics/player/hurt/Player Hurt 48x48.png.import
Normal file
@ -0,0 +1,34 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://cwid3ull01xog"
|
||||
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/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
|
@ -14,8 +14,11 @@ func setSpeed(value):
|
||||
if speed > 0:
|
||||
bullet_image.flip_h = false
|
||||
|
||||
|
||||
func _on_body_entered(body: Node2D) -> void:
|
||||
if not body is Player:
|
||||
print("bullet hit!")
|
||||
bulletHit.emit(body, self)
|
||||
|
||||
func _on_area_entered(area: Area2D) -> void:
|
||||
print("bullet hit!")
|
||||
bulletHit.emit(area, self)
|
||||
|
@ -1,7 +1,7 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://cy02yf4v8q5v6"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://wmy17yj81te8" path="res://bullet.gd" id="1_mkf8s"]
|
||||
[ext_resource type="Texture2D" uid="uid://dwn36dqvridjp" path="res://assets/graphics/projectiles/pixel_bullet.png" id="2_y25gk"]
|
||||
[ext_resource type="Texture2D" uid="uid://c1a615uhr2yfd" path="res://assets/graphics/projectiles/pixel_bullet.png" id="2_y25gk"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_y25gk"]
|
||||
size = Vector2(34, 8)
|
||||
@ -19,4 +19,5 @@ position = Vector2(-8, 5)
|
||||
scale = Vector2(-0.25, 0.225)
|
||||
texture = ExtResource("2_y25gk")
|
||||
|
||||
[connection signal="area_entered" from="." to="." method="_on_area_entered"]
|
||||
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
|
||||
|
@ -1,5 +1,6 @@
|
||||
[gd_scene load_steps=18 format=4 uid="uid://bvs868ncmeoj5"]
|
||||
[gd_scene load_steps=19 format=4 uid="uid://bvs868ncmeoj5"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://b41kay5ja3tlt" path="res://scenes/ui.tscn" id="1_kvuet"]
|
||||
[ext_resource type="Script" uid="uid://bijvpac45v6s1" path="res://scripts/scene_manager.gd" id="2_lbhrr"]
|
||||
[ext_resource type="PackedScene" uid="uid://c5a5u2c250g6" path="res://scenes/player.tscn" id="2_lnu2h"]
|
||||
[ext_resource type="Texture2D" uid="uid://bsw50wv55u4rt" path="res://assets/graphics/terrain/vegetation/mushroom_32x64.png" id="3_0tnpc"]
|
||||
@ -386,6 +387,10 @@ sources/2 = SubResource("TileSetAtlasSource_dinhu")
|
||||
|
||||
[node name="Game" type="Node2D"]
|
||||
|
||||
[node name="CanvasLayer" type="CanvasLayer" parent="."]
|
||||
|
||||
[node name="Control" parent="CanvasLayer" instance=ExtResource("1_kvuet")]
|
||||
|
||||
[node name="SceneManager" type="Node" parent="."]
|
||||
unique_name_in_owner = true
|
||||
script = ExtResource("2_lbhrr")
|
||||
@ -474,10 +479,10 @@ position = Vector2(391, 92)
|
||||
[node name="Enemies" type="Node2D" parent="."]
|
||||
|
||||
[node name="e1" parent="Enemies" instance=ExtResource("12_dinhu")]
|
||||
position = Vector2(376, 525)
|
||||
position = Vector2(356, 519)
|
||||
|
||||
[node name="e2" parent="Enemies" instance=ExtResource("12_dinhu")]
|
||||
position = Vector2(536, 110)
|
||||
position = Vector2(478, 78)
|
||||
|
||||
[connection signal="triggerFired" from="Triggers/Trigger" to="." method="_on_trigger_trigger_fired"]
|
||||
[connection signal="triggerFired" from="Triggers/Trigger2" to="." method="_on_trigger_trigger_fired"]
|
||||
|
@ -1,18 +1,76 @@
|
||||
[gd_scene load_steps=35 format=3 uid="uid://c5a5u2c250g6"]
|
||||
[gd_scene load_steps=51 format=3 uid="uid://c5a5u2c250g6"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://c3vqmu6nc4gb0" path="res://scripts/player.gd" id="1_3vyb7"]
|
||||
[ext_resource type="Texture2D" uid="uid://de6p78arhau1m" path="res://assets/graphics/player/jump/player jump 48x48.png" id="2_dqkch"]
|
||||
[ext_resource type="Texture2D" uid="uid://bf0ysio1qxdu" path="res://assets/graphics/player/death/Player Death 64x64.png" id="2_fjrip"]
|
||||
[ext_resource type="Texture2D" uid="uid://dv34fblpejy5x" path="res://assets/graphics/player/idle/Player Idle 48x48.png" id="2_g2els"]
|
||||
[ext_resource type="Texture2D" uid="uid://bs8k1b6xj3gxb" path="res://assets/graphics/player/run/player run 48x48.png" id="3_qhqgy"]
|
||||
[ext_resource type="Texture2D" uid="uid://bkgyjj5bbx7r0" path="res://assets/graphics/player/melee/Player Punch 64x64.png" id="4_qlg0r"]
|
||||
[ext_resource type="Texture2D" uid="uid://cwid3ull01xog" path="res://assets/graphics/player/hurt/Player Hurt 48x48.png" id="4_smehm"]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_8cj0n"]
|
||||
radius = 21.2132
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_pf23h"]
|
||||
atlas = ExtResource("2_fjrip")
|
||||
region = Rect2(0, 0, 48, 48)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_dt7fs"]
|
||||
atlas = ExtResource("2_fjrip")
|
||||
region = Rect2(48, 0, 48, 48)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_wqfne"]
|
||||
atlas = ExtResource("2_fjrip")
|
||||
region = Rect2(96, 0, 48, 48)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_wnwbv"]
|
||||
atlas = ExtResource("2_fjrip")
|
||||
region = Rect2(144, 0, 48, 48)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_gl8cc"]
|
||||
atlas = ExtResource("2_fjrip")
|
||||
region = Rect2(192, 0, 48, 48)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_487ah"]
|
||||
atlas = ExtResource("2_fjrip")
|
||||
region = Rect2(240, 0, 48, 48)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_md1ol"]
|
||||
atlas = ExtResource("2_fjrip")
|
||||
region = Rect2(288, 0, 48, 48)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_bj30b"]
|
||||
atlas = ExtResource("2_fjrip")
|
||||
region = Rect2(336, 0, 48, 48)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_jc3p3"]
|
||||
atlas = ExtResource("2_fjrip")
|
||||
region = Rect2(384, 0, 48, 48)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_hax0n"]
|
||||
atlas = ExtResource("2_fjrip")
|
||||
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_t4otl"]
|
||||
atlas = ExtResource("4_smehm")
|
||||
region = Rect2(0, 0, 48, 48)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_j2b1d"]
|
||||
atlas = ExtResource("4_smehm")
|
||||
region = Rect2(48, 0, 48, 48)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_cs1tg"]
|
||||
atlas = ExtResource("4_smehm")
|
||||
region = Rect2(96, 0, 48, 48)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_2dvfe"]
|
||||
atlas = ExtResource("4_smehm")
|
||||
region = Rect2(144, 0, 48, 48)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_qhqgy"]
|
||||
atlas = ExtResource("2_g2els")
|
||||
region = Rect2(0, 0, 48, 48)
|
||||
@ -113,6 +171,41 @@ region = Rect2(336, 0, 48, 48)
|
||||
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": &"death",
|
||||
"speed": 12.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_i4ail")
|
||||
}],
|
||||
"loop": false,
|
||||
@ -121,6 +214,23 @@ animations = [{
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_t4otl")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_j2b1d")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_cs1tg")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_2dvfe")
|
||||
}],
|
||||
"loop": false,
|
||||
"name": &"hurt",
|
||||
"speed": 12.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_qhqgy")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
@ -251,8 +361,8 @@ one_shot = true
|
||||
texture_filter = 1
|
||||
position = Vector2(1, -1)
|
||||
sprite_frames = SubResource("SpriteFrames_jej6c")
|
||||
animation = &"melee"
|
||||
autoplay = "idle"
|
||||
animation = &"death"
|
||||
autoplay = "death"
|
||||
|
||||
[node name="Camera2D" type="Camera2D" parent="."]
|
||||
offset = Vector2(0, -20)
|
||||
|
@ -1,8 +1,24 @@
|
||||
[gd_scene load_steps=9 format=3 uid="uid://b2lq6rp0aht6d"]
|
||||
[gd_scene load_steps=13 format=3 uid="uid://b2lq6rp0aht6d"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://cn1jvyyvb3g3c" path="res://assets/graphics/enemies/slime_green.png" id="1_371uh"]
|
||||
[ext_resource type="Script" uid="uid://bsmcx4pr1imsq" path="res://scripts/slime.gd" id="1_p2gj0"]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_fd6lc"]
|
||||
atlas = ExtResource("1_371uh")
|
||||
region = Rect2(0, 48, 24, 24)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_gstla"]
|
||||
atlas = ExtResource("1_371uh")
|
||||
region = Rect2(24, 48, 24, 24)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_v5wyi"]
|
||||
atlas = ExtResource("1_371uh")
|
||||
region = Rect2(48, 48, 24, 24)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_0l8pv"]
|
||||
atlas = ExtResource("1_371uh")
|
||||
region = Rect2(72, 48, 24, 24)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_p2gj0"]
|
||||
atlas = ExtResource("1_371uh")
|
||||
region = Rect2(0, 24, 24, 24)
|
||||
@ -23,6 +39,23 @@ region = Rect2(72, 24, 24, 24)
|
||||
animations = [{
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_fd6lc")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_gstla")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_v5wyi")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_0l8pv")
|
||||
}],
|
||||
"loop": false,
|
||||
"name": &"hurt",
|
||||
"speed": 12.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_p2gj0")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
@ -48,9 +81,8 @@ script = ExtResource("1_p2gj0")
|
||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
||||
texture_filter = 1
|
||||
sprite_frames = SubResource("SpriteFrames_fd6lc")
|
||||
animation = &"run"
|
||||
animation = &"hurt"
|
||||
autoplay = "run"
|
||||
frame_progress = 0.256611
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
position = Vector2(0, 4)
|
||||
|
46
scenes/ui.tscn
Normal file
46
scenes/ui.tscn
Normal file
@ -0,0 +1,46 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://b41kay5ja3tlt"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://cv1at33pu2ae2" path="res://scripts/ui.gd" id="1_nt7q6"]
|
||||
|
||||
[node name="Control" type="Control"]
|
||||
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="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 10
|
||||
anchor_right = 1.0
|
||||
grow_horizontal = 2
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="VBoxContainer/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="Health" type="Label" parent="VBoxContainer/HBoxContainer/MarginContainer"]
|
||||
layout_mode = 2
|
||||
text = "Health"
|
||||
|
||||
[node name="MarginContainer2" type="MarginContainer" parent="VBoxContainer/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="Timer" type="Label" parent="VBoxContainer/HBoxContainer/MarginContainer2"]
|
||||
layout_mode = 2
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="MarginContainer3" type="MarginContainer" parent="VBoxContainer/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="Coins" type="Label" parent="VBoxContainer/HBoxContainer/MarginContainer3"]
|
||||
layout_mode = 2
|
||||
text = "Coins"
|
||||
horizontal_alignment = 2
|
@ -1,4 +1,4 @@
|
||||
class_name GameController extends Node2D
|
||||
extends Node2D
|
||||
|
||||
var totalCrates = 3
|
||||
var timeLimit = 10
|
||||
@ -12,13 +12,25 @@ var currentLevel = 0
|
||||
|
||||
var playerHealth = 100
|
||||
|
||||
var player:CharacterStats
|
||||
var slime:CharacterStats
|
||||
|
||||
var enemiesDict = {}
|
||||
|
||||
signal levelCompleteSignal(level)
|
||||
signal destroySignal(body)
|
||||
signal playerDamage
|
||||
signal playerDamage(health, maxHealth)
|
||||
signal playerDeath
|
||||
signal countDown(timeRemaining)
|
||||
signal coinUpdate(totalCoins)
|
||||
signal enemyHurt(enemy)
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
func _ready() -> void:
|
||||
#load custom resources for player and slime
|
||||
player = load("res://scripts/res/playerstats.tres")
|
||||
slime = load("res://scripts/res/slimestats.tres")
|
||||
|
||||
add_child(timer)
|
||||
timer.wait_time = 1
|
||||
timer.one_shot = false
|
||||
@ -28,6 +40,7 @@ func _ready() -> void:
|
||||
func secondCounter():
|
||||
print("tick "+str(timeLimit))
|
||||
timeLimit -= 1
|
||||
countDown.emit(timeLimit)
|
||||
if timeLimit <= 0:
|
||||
print("YOU LOSE...")
|
||||
levelCompleteSignal.emit(levels[currentLevel])
|
||||
@ -50,32 +63,51 @@ func _on_trigger_fired(effect: Variant, body: Variant) -> void:
|
||||
|
||||
func _on_coin_collected(body, coin):
|
||||
coinsCollectedTotal += 1
|
||||
coinUpdate.emit(coinsCollectedTotal)
|
||||
destroySignal.emit(coin)
|
||||
print("GC knows coin collected")
|
||||
|
||||
func _on_player_damage(body, enemy):
|
||||
if enemy is Slime:
|
||||
print("slime attack!")
|
||||
playerHealth -= 10
|
||||
if playerHealth > 0:
|
||||
print("Player damaged")
|
||||
playerDamage.emit()
|
||||
else:
|
||||
print("Player dead")
|
||||
playerDeath.emit()
|
||||
#playerHealth -= slime.meleeDamage
|
||||
playerHealth -= enemiesDict[enemy]["damage"]
|
||||
|
||||
if playerHealth > 0:
|
||||
print("Player damaged")
|
||||
playerDamage.emit(playerHealth, player.max_health)
|
||||
else:
|
||||
print("Player dead")
|
||||
playerDeath.emit()
|
||||
|
||||
func addEnemyToLevel(enemy):
|
||||
var randHealth = randi() % 20
|
||||
var randDamage = randi() % 10
|
||||
var enemyStat = {
|
||||
"health":slime.health + randHealth,
|
||||
"damage":slime.meleeDamage + randDamage
|
||||
}
|
||||
enemiesDict[enemy] = enemyStat
|
||||
|
||||
func numberOfCrates(value:int)->void:
|
||||
totalCrates = value
|
||||
|
||||
func bulletDamage(body, bullet):
|
||||
if body is Crate:
|
||||
print("Crates remaining: " + str(totalCrates))
|
||||
destroySignal.emit(body)
|
||||
#if body is Crate:
|
||||
# print("Crates remaining: " + str(totalCrates))
|
||||
# destroySignal.emit(body)
|
||||
if body is Slime:
|
||||
enemiesDict[body]["health"] -= player.rangeDamage
|
||||
print("Enemy Health "+str(enemiesDict[body]["health"]))
|
||||
enemyHurt.emit(body)
|
||||
if enemiesDict[body]["health"] <= 0:
|
||||
destroySignal.emit(body)
|
||||
enemiesDict.erase(body)
|
||||
|
||||
func reset():
|
||||
timeLimit = timers[currentLevel]
|
||||
playerHealth = 100
|
||||
playerHealth = player.starting_health
|
||||
|
||||
func death():
|
||||
print("player death animation complete")
|
||||
|
||||
levelCompleteSignal.emit(levels[currentLevel])
|
||||
|
@ -19,7 +19,7 @@ const JUMP_VELOCITY = -400.0
|
||||
@export var acceleration = 50
|
||||
@export var hard_gravity = 5
|
||||
|
||||
enum State {IDLE, RUN, JUMP, FALLING, MELEE}
|
||||
enum State {IDLE, RUN, JUMP, FALLING, MELEE, HURT, DEATH}
|
||||
var current_state = State.IDLE
|
||||
|
||||
enum FaceDirection {LEFT, RIGHT}
|
||||
@ -32,11 +32,13 @@ var upJump: bool = false
|
||||
|
||||
signal deathComplete
|
||||
|
||||
func _player_damage():
|
||||
func _player_damage(_currentHealth, _maxHealth):
|
||||
print("Player taking damage!")
|
||||
current_state = State.HURT
|
||||
|
||||
func _player_death():
|
||||
print("Player dead!!!")
|
||||
current_state = State.DEATH
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
# Add the gravity.
|
||||
@ -46,7 +48,8 @@ func _physics_process(delta: float) -> void:
|
||||
velocity += get_gravity() * hard_gravity * delta
|
||||
|
||||
# Handle input
|
||||
handle_input()
|
||||
if current_state != State.HURT and current_state != State.DEATH:
|
||||
handle_input()
|
||||
update_movement()
|
||||
|
||||
# Handle states and animation
|
||||
@ -140,6 +143,10 @@ func update_animation()->void:
|
||||
player_graphic.play("fall")
|
||||
State.MELEE:
|
||||
player_graphic.play("melee")
|
||||
State.HURT:
|
||||
player_graphic.play("hurt")
|
||||
State.DEATH:
|
||||
player_graphic.play("death")
|
||||
|
||||
func handle_collisions() -> void:
|
||||
for i in get_slide_collision_count():
|
||||
@ -173,3 +180,8 @@ func _on_animation_finished() -> void:
|
||||
upJump = false
|
||||
State.MELEE:
|
||||
current_state = State.IDLE
|
||||
State.HURT:
|
||||
current_state = State.IDLE
|
||||
State.DEATH:
|
||||
print("Death animation finished")
|
||||
deathComplete.emit()
|
||||
|
8
scripts/res/characterstats.gd
Normal file
8
scripts/res/characterstats.gd
Normal file
@ -0,0 +1,8 @@
|
||||
class_name CharacterStats extends Resource
|
||||
|
||||
@export var max_health:int = 100
|
||||
@export var starting_health:int = 100
|
||||
@export var health:int = 100
|
||||
|
||||
@export var meleeDamage:int = 10
|
||||
@export var rangeDamage:int = 0
|
1
scripts/res/characterstats.gd.uid
Normal file
1
scripts/res/characterstats.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://cb4odxbsudi2y
|
12
scripts/res/playerstats.tres
Normal file
12
scripts/res/playerstats.tres
Normal file
@ -0,0 +1,12 @@
|
||||
[gd_resource type="Resource" script_class="CharacterStats" load_steps=2 format=3 uid="uid://d2w3olbk7mqqq"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://cb4odxbsudi2y" path="res://scripts/res/characterstats.gd" id="1_4nldt"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_4nldt")
|
||||
max_health = 100
|
||||
starting_health = 100
|
||||
health = 100
|
||||
meleeDamage = 10
|
||||
rangeDamage = 30
|
||||
metadata/_custom_type_script = "uid://cb4odxbsudi2y"
|
12
scripts/res/slimestats.tres
Normal file
12
scripts/res/slimestats.tres
Normal file
@ -0,0 +1,12 @@
|
||||
[gd_resource type="Resource" script_class="CharacterStats" load_steps=2 format=3 uid="uid://b4ilwsa0a21fi"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://cb4odxbsudi2y" path="res://scripts/res/characterstats.gd" id="1_fftob"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_fftob")
|
||||
max_health = 50
|
||||
starting_health = 50
|
||||
health = 50
|
||||
meleeDamage = 40
|
||||
rangeDamage = 0
|
||||
metadata/_custom_type_script = "uid://cb4odxbsudi2y"
|
@ -5,6 +5,7 @@ extends Node
|
||||
@onready var coins: Node2D = $"../Coins"
|
||||
@onready var enemies: Node2D = $"../Enemies"
|
||||
@onready var player: Player = $"../CharacterBody2D"
|
||||
@onready var control: Control = $"../CanvasLayer/Control"
|
||||
|
||||
var bullet = preload("res://scenes/bullet.tscn")
|
||||
var bulletArray = []
|
||||
@ -29,9 +30,13 @@ func buildLevel() -> void:
|
||||
Gamecontroller.levelCompleteSignal.connect(loadLevel)
|
||||
Gamecontroller.destroySignal.connect(destroy)
|
||||
Gamecontroller.playerDamage.connect(player._player_damage)
|
||||
Gamecontroller.playerDamage.connect(control.healthUpdate)
|
||||
Gamecontroller.coinUpdate.connect(control.coinsUpdate)
|
||||
Gamecontroller.playerDeath.connect(player._player_death)
|
||||
# player connection
|
||||
player.deathComplete.connect(Gamecontroller.death)
|
||||
# UI signals
|
||||
Gamecontroller.countDown.connect(control.timerUpdate)
|
||||
|
||||
# Connect trigger signals
|
||||
if triggers:
|
||||
@ -48,6 +53,8 @@ func buildLevel() -> void:
|
||||
for obj in enemies.get_children():
|
||||
if obj is Slime:
|
||||
obj.playerDamageSignal.connect(Gamecontroller._on_player_damage)
|
||||
Gamecontroller.enemyHurt.connect(obj.damage)
|
||||
Gamecontroller.addEnemyToLevel(obj)
|
||||
|
||||
func countCrates()->int:
|
||||
# count crates
|
||||
|
@ -11,14 +11,29 @@ var speed = 100
|
||||
var direction = 1
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if not right_down_cast.is_colliding() or right_side_cast.is_colliding():
|
||||
if not right_down_cast.is_colliding():
|
||||
direction = -1
|
||||
sprite.flip_h = true
|
||||
if not left_down_cast.is_colliding() or left_side_cast.is_colliding():
|
||||
if right_side_cast.is_colliding():
|
||||
if not right_side_cast.get_collider() is Player:
|
||||
direction = -1
|
||||
sprite.flip_h = true
|
||||
|
||||
if not left_down_cast.is_colliding():
|
||||
direction = 1
|
||||
sprite.flip_h = false
|
||||
if left_side_cast.is_colliding():
|
||||
if not left_side_cast.get_collider() is Player:
|
||||
direction = 1
|
||||
sprite.flip_h = false
|
||||
|
||||
position.x += direction * speed * delta
|
||||
|
||||
func _on_body_entered(body: Node2D) -> void:
|
||||
print("Slime Contact")
|
||||
playerDamageSignal.emit(body, self)
|
||||
func _on_body_entered(body: Node2D) -> void:
|
||||
if body is Player:
|
||||
print("Slime Contact")
|
||||
playerDamageSignal.emit(body, self)
|
||||
|
||||
func damage(body)->void:
|
||||
if body == self:
|
||||
sprite.play("hurt")
|
||||
|
17
scripts/ui.gd
Normal file
17
scripts/ui.gd
Normal file
@ -0,0 +1,17 @@
|
||||
extends Control
|
||||
|
||||
@onready var health: Label = $VBoxContainer/HBoxContainer/MarginContainer/Health
|
||||
@onready var timer: Label = $VBoxContainer/HBoxContainer/MarginContainer2/Timer
|
||||
@onready var coins: Label = $VBoxContainer/HBoxContainer/MarginContainer3/Coins
|
||||
|
||||
func _ready() -> void:
|
||||
pass
|
||||
|
||||
func healthUpdate(currentHealth, maxHealth) -> void:
|
||||
health.text = "Health: "+str(currentHealth)+"/"+str(maxHealth)
|
||||
|
||||
func coinsUpdate(currentCoins) -> void:
|
||||
coins.text = "Coins: "+str(currentCoins)
|
||||
|
||||
func timerUpdate(currentTimer) -> void:
|
||||
timer.text = "Timer: "+str(currentTimer)
|
1
scripts/ui.gd.uid
Normal file
1
scripts/ui.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://cv1at33pu2ae2
|
Loading…
Reference in New Issue
Block a user