diff --git a/Assets/Graphics/Player/Death/Player Death 64x64.png b/Assets/Graphics/Player/Death/Player Death 64x64.png new file mode 100644 index 0000000..2e6a1ae Binary files /dev/null and b/Assets/Graphics/Player/Death/Player Death 64x64.png differ diff --git a/Assets/Graphics/Player/Death/Player Death 64x64.png.import b/Assets/Graphics/Player/Death/Player Death 64x64.png.import new file mode 100644 index 0000000..0afc872 --- /dev/null +++ b/Assets/Graphics/Player/Death/Player Death 64x64.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://35h3pfqene6g" +path="res://.godot/imported/Player Death 64x64.png-585c61faad3b9e1142f9ebaa962a0235.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-585c61faad3b9e1142f9ebaa962a0235.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 diff --git a/Assets/Graphics/Player/Hurt/Player Hurt 48x48.png b/Assets/Graphics/Player/Hurt/Player Hurt 48x48.png new file mode 100644 index 0000000..57d8783 Binary files /dev/null and b/Assets/Graphics/Player/Hurt/Player Hurt 48x48.png differ diff --git a/Assets/Graphics/Player/Hurt/Player Hurt 48x48.png.import b/Assets/Graphics/Player/Hurt/Player Hurt 48x48.png.import new file mode 100644 index 0000000..838f22e --- /dev/null +++ b/Assets/Graphics/Player/Hurt/Player Hurt 48x48.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://npog4kgvtnlo" +path="res://.godot/imported/Player Hurt 48x48.png-4208d9781d587849c96afac76e871808.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-4208d9781d587849c96afac76e871808.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 diff --git a/Scenes/Player.tscn b/Scenes/Player.tscn index cebe537..59a90b6 100644 --- a/Scenes/Player.tscn +++ b/Scenes/Player.tscn @@ -1,16 +1,74 @@ -[gd_scene load_steps=28 format=3 uid="uid://bu8e4iyw8pc03"] +[gd_scene load_steps=44 format=3 uid="uid://bu8e4iyw8pc03"] [ext_resource type="Script" uid="uid://dsryf6gxqcm1k" path="res://Scripts/character_body_2d.gd" id="1_0y7nr"] [ext_resource type="Texture2D" uid="uid://dpv7hte6i8kui" path="res://Assets/Graphics/Player/Jump/player jump 48x48.png" id="2_dewec"] [ext_resource type="Texture2D" uid="uid://dl452cit6hmxl" path="res://Assets/Graphics/Player/Idle/Player Idle 48x48.png" id="2_kyqiw"] +[ext_resource type="Texture2D" uid="uid://35h3pfqene6g" path="res://Assets/Graphics/Player/Death/Player Death 64x64.png" id="2_nn08x"] [ext_resource type="Texture2D" uid="uid://bmrxpbm2roq7s" path="res://Assets/Graphics/Player/Run/player run 48x48.png" id="3_gntrk"] +[ext_resource type="Texture2D" uid="uid://npog4kgvtnlo" path="res://Assets/Graphics/Player/Hurt/Player Hurt 48x48.png" id="4_52ee3"] [sub_resource type="CircleShape2D" id="CircleShape2D_2poj3"] +[sub_resource type="AtlasTexture" id="AtlasTexture_qidb7"] +atlas = ExtResource("2_nn08x") +region = Rect2(0, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_70hv0"] +atlas = ExtResource("2_nn08x") +region = Rect2(48, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_8flut"] +atlas = ExtResource("2_nn08x") +region = Rect2(96, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_u7x0b"] +atlas = ExtResource("2_nn08x") +region = Rect2(144, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_utwlt"] +atlas = ExtResource("2_nn08x") +region = Rect2(192, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_kih0c"] +atlas = ExtResource("2_nn08x") +region = Rect2(240, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_lyrkg"] +atlas = ExtResource("2_nn08x") +region = Rect2(288, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_c43xd"] +atlas = ExtResource("2_nn08x") +region = Rect2(336, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_avx33"] +atlas = ExtResource("2_nn08x") +region = Rect2(384, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_rxg2u"] +atlas = ExtResource("2_nn08x") +region = Rect2(432, 0, 48, 48) + [sub_resource type="AtlasTexture" id="AtlasTexture_5v66d"] atlas = ExtResource("2_dewec") region = Rect2(96, 0, 48, 48) +[sub_resource type="AtlasTexture" id="AtlasTexture_xixlo"] +atlas = ExtResource("4_52ee3") +region = Rect2(0, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_bfbt0"] +atlas = ExtResource("4_52ee3") +region = Rect2(48, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_wosd6"] +atlas = ExtResource("4_52ee3") +region = Rect2(96, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_hkrn1"] +atlas = ExtResource("4_52ee3") +region = Rect2(144, 0, 48, 48) + [sub_resource type="AtlasTexture" id="AtlasTexture_gntrk"] atlas = ExtResource("2_kyqiw") region = Rect2(0, 0, 48, 48) @@ -95,6 +153,41 @@ region = Rect2(336, 0, 48, 48) animations = [{ "frames": [{ "duration": 1.0, +"texture": SubResource("AtlasTexture_qidb7") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_70hv0") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_8flut") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_u7x0b") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_utwlt") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_kih0c") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_lyrkg") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_c43xd") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_avx33") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_rxg2u") +}], +"loop": false, +"name": &"death", +"speed": 12.0 +}, { +"frames": [{ +"duration": 1.0, "texture": SubResource("AtlasTexture_5v66d") }], "loop": true, @@ -103,6 +196,23 @@ animations = [{ }, { "frames": [{ "duration": 1.0, +"texture": SubResource("AtlasTexture_xixlo") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_bfbt0") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_wosd6") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_hkrn1") +}], +"loop": false, +"name": &"hurt", +"speed": 12.0 +}, { +"frames": [{ +"duration": 1.0, "texture": SubResource("AtlasTexture_gntrk") }, { "duration": 1.0, @@ -178,6 +288,7 @@ animations = [{ }] [node name="CharacterBody2D" type="CharacterBody2D"] +position = Vector2(2, -1) script = ExtResource("1_0y7nr") metadata/_edit_group_ = true @@ -192,16 +303,16 @@ target_position = Vector2(16, 0) target_position = Vector2(-16, 0) [node name="RightSpawn" type="Node2D" parent="."] -position = Vector2(17, -8) +position = Vector2(17, -3) [node name="LeftSpawn" type="Node2D" parent="."] -position = Vector2(-14, -9) +position = Vector2(-14, -3) [node name="PlayerGraphic" type="AnimatedSprite2D" parent="."] texture_filter = 1 position = Vector2(0, -6) sprite_frames = SubResource("SpriteFrames_miouo") -animation = &"falling" +animation = &"hurt" autoplay = "idle" [node name="Camera2D" type="Camera2D" parent="."] diff --git a/Scenes/bullet.tscn b/Scenes/bullet.tscn index d42aa57..c91c08a 100644 --- a/Scenes/bullet.tscn +++ b/Scenes/bullet.tscn @@ -21,3 +21,5 @@ texture_filter = 1 position = Vector2(0.5, 0) shape = SubResource("RectangleShape2D_oduel") debug_color = Color(0.995859, 0, 0.197667, 0.42) + +[connection signal="area_entered" from="." to="." method="_on_area_entered"] diff --git a/Scenes/crate.tscn b/Scenes/crate.tscn index cbf7f9e..2abee9b 100644 --- a/Scenes/crate.tscn +++ b/Scenes/crate.tscn @@ -1,10 +1,12 @@ -[gd_scene load_steps=3 format=3 uid="uid://cd7fv3pwgr880"] +[gd_scene load_steps=4 format=3 uid="uid://cd7fv3pwgr880"] +[ext_resource type="Script" uid="uid://b546t5rmhjwiu" path="res://Scripts/crate.gd" id="1_i4r3v"] [ext_resource type="Texture2D" uid="uid://m685ffchmchr" path="res://Assets/Graphics/Objects/crate.png" id="1_wp72f"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_ebmjs"] [node name="RigidBody2D3" type="RigidBody2D"] +script = ExtResource("1_i4r3v") metadata/_edit_group_ = true [node name="Sprite2D" type="Sprite2D" parent="."] diff --git a/Scenes/game.tscn b/Scenes/game.tscn index 63443bc..b5b87eb 100644 --- a/Scenes/game.tscn +++ b/Scenes/game.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=18 format=4 uid="uid://c6mxse0hqjro7"] +[gd_scene load_steps=19 format=4 uid="uid://c6mxse0hqjro7"] [ext_resource type="Texture2D" uid="uid://mfcyrgamj3cc" path="res://Assets/Graphics/Terrains/Terrain (32x32).png" id="2_1l0tm"] [ext_resource type="Script" uid="uid://bs4frobn6kxne" path="res://Scripts/scene_manager.gd" id="2_i6g32"] @@ -12,6 +12,7 @@ [ext_resource type="PackedScene" uid="uid://b5d8himq5sttt" path="res://Scenes/trigger.tscn" id="4_wowpa"] [ext_resource type="PackedScene" uid="uid://cat3n1unb05u6" path="res://Scenes/slime.tscn" id="12_rfjv2"] [ext_resource type="PackedScene" uid="uid://dr1mp5x0cmbhw" path="res://Scenes/coin.tscn" id="12_rku1e"] +[ext_resource type="PackedScene" uid="uid://k42k25w6fsbo" path="res://Scenes/ui.tscn" id="13_rfjv2"] [sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_v158k"] texture = ExtResource("2_1l0tm") @@ -488,8 +489,15 @@ position = Vector2(483, 365) [node name="Enemies" type="Node2D" parent="."] +[node name="Slime2" parent="Enemies" instance=ExtResource("12_rfjv2")] +position = Vector2(275, 370) + [node name="Slime" parent="Enemies" instance=ExtResource("12_rfjv2")] position = Vector2(641, 340) +[node name="CanvasLayer" type="CanvasLayer" parent="."] + +[node name="UI" parent="CanvasLayer" instance=ExtResource("13_rfjv2")] + [connection signal="areatrigger" from="Triggers/Area2D2" to="." method="_on_areatrigger"] [connection signal="areatrigger" from="Triggers/Area2D3" to="." method="_on_areatrigger"] diff --git a/Scenes/level2.tscn b/Scenes/level2.tscn index 815467f..f72ba2f 100644 --- a/Scenes/level2.tscn +++ b/Scenes/level2.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=17 format=4 uid="uid://bcray1583u4e6"] +[gd_scene load_steps=18 format=4 uid="uid://bcray1583u4e6"] [ext_resource type="Texture2D" uid="uid://c0aoaemjratj1" path="res://Assets/Graphics/Terrains/forestsky.png" id="1_mtqcm"] [ext_resource type="Texture2D" uid="uid://cugs4plceapu2" path="res://Assets/Graphics/Terrains/forestbackground.png" id="2_mmf1u"] @@ -11,6 +11,7 @@ [ext_resource type="PackedScene" uid="uid://cd7fv3pwgr880" path="res://Scenes/crate.tscn" id="9_051s1"] [ext_resource type="PackedScene" uid="uid://b5d8himq5sttt" path="res://Scenes/trigger.tscn" id="10_in4v8"] [ext_resource type="PackedScene" uid="uid://dr1mp5x0cmbhw" path="res://Scenes/coin.tscn" id="11_mu7lp"] +[ext_resource type="PackedScene" uid="uid://k42k25w6fsbo" path="res://Scenes/ui.tscn" id="12_mmf1u"] [sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_v158k"] texture = ExtResource("4_r8hce") @@ -486,5 +487,9 @@ position = Vector2(952, 174) [node name="Enemies" type="Node2D" parent="."] +[node name="CanvasLayer" type="CanvasLayer" parent="."] + +[node name="UI" parent="CanvasLayer" instance=ExtResource("12_mmf1u")] + [connection signal="areatrigger" from="Triggers/Area2D2" to="." method="_on_areatrigger"] [connection signal="areatrigger" from="Triggers/Area2D3" to="." method="_on_areatrigger"] diff --git a/Scenes/level3.tscn b/Scenes/level3.tscn index 0a70183..2fa27ff 100644 --- a/Scenes/level3.tscn +++ b/Scenes/level3.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=17 format=4 uid="uid://kqvn8jpvyrej"] +[gd_scene load_steps=18 format=4 uid="uid://kqvn8jpvyrej"] [ext_resource type="Texture2D" uid="uid://c0aoaemjratj1" path="res://Assets/Graphics/Terrains/forestsky.png" id="1_h6p24"] [ext_resource type="Texture2D" uid="uid://cugs4plceapu2" path="res://Assets/Graphics/Terrains/forestbackground.png" id="2_vn7r1"] @@ -11,6 +11,7 @@ [ext_resource type="PackedScene" uid="uid://cd7fv3pwgr880" path="res://Scenes/crate.tscn" id="9_p2sx0"] [ext_resource type="PackedScene" uid="uid://b5d8himq5sttt" path="res://Scenes/trigger.tscn" id="10_tc3ri"] [ext_resource type="PackedScene" uid="uid://dr1mp5x0cmbhw" path="res://Scenes/coin.tscn" id="11_3nkac"] +[ext_resource type="PackedScene" uid="uid://k42k25w6fsbo" path="res://Scenes/ui.tscn" id="12_vn7r1"] [sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_v158k"] texture = ExtResource("4_fpsp3") @@ -486,5 +487,9 @@ position = Vector2(896, 372) [node name="Enemies" type="Node2D" parent="."] +[node name="CanvasLayer" type="CanvasLayer" parent="."] + +[node name="UI" parent="CanvasLayer" instance=ExtResource("12_vn7r1")] + [connection signal="areatrigger" from="Triggers/Area2D2" to="." method="_on_areatrigger"] [connection signal="areatrigger" from="Triggers/Area2D3" to="." method="_on_areatrigger"] diff --git a/Scenes/slime.tscn b/Scenes/slime.tscn index de2d84d..5a06f17 100644 --- a/Scenes/slime.tscn +++ b/Scenes/slime.tscn @@ -1,8 +1,24 @@ -[gd_scene load_steps=9 format=3 uid="uid://cat3n1unb05u6"] +[gd_scene load_steps=13 format=3 uid="uid://cat3n1unb05u6"] [ext_resource type="Texture2D" uid="uid://1qmvigexa3to" path="res://Assets/Graphics/Enemies/slime_purple.png" id="1_jokqx"] [ext_resource type="Script" uid="uid://vjdcp0a4i0j8" path="res://Scripts/slime.gd" id="1_swwnm"] +[sub_resource type="AtlasTexture" id="AtlasTexture_5gljc"] +atlas = ExtResource("1_jokqx") +region = Rect2(0, 48, 24, 24) + +[sub_resource type="AtlasTexture" id="AtlasTexture_vblni"] +atlas = ExtResource("1_jokqx") +region = Rect2(24, 48, 24, 24) + +[sub_resource type="AtlasTexture" id="AtlasTexture_e388w"] +atlas = ExtResource("1_jokqx") +region = Rect2(48, 48, 24, 24) + +[sub_resource type="AtlasTexture" id="AtlasTexture_r4o34"] +atlas = ExtResource("1_jokqx") +region = Rect2(72, 48, 24, 24) + [sub_resource type="AtlasTexture" id="AtlasTexture_swwnm"] atlas = ExtResource("1_jokqx") region = Rect2(0, 24, 24, 24) @@ -23,6 +39,23 @@ region = Rect2(72, 24, 24, 24) animations = [{ "frames": [{ "duration": 1.0, +"texture": SubResource("AtlasTexture_5gljc") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_vblni") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_e388w") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_r4o34") +}], +"loop": false, +"name": &"hurt", +"speed": 12.0 +}, { +"frames": [{ +"duration": 1.0, "texture": SubResource("AtlasTexture_swwnm") }, { "duration": 1.0, @@ -49,10 +82,10 @@ metadata/_edit_group_ = true [node name="slimeGraphic" type="AnimatedSprite2D" parent="."] texture_filter = 1 sprite_frames = SubResource("SpriteFrames_5gljc") -animation = &"idle" +animation = &"hurt" autoplay = "idle" -frame = 1 -frame_progress = 0.885206 +frame = 3 +frame_progress = 1.0 [node name="CollisionShape2D" type="CollisionShape2D" parent="."] position = Vector2(0, 4) diff --git a/Scenes/ui.tscn b/Scenes/ui.tscn new file mode 100644 index 0000000..b661887 --- /dev/null +++ b/Scenes/ui.tscn @@ -0,0 +1,47 @@ +[gd_scene load_steps=2 format=3 uid="uid://k42k25w6fsbo"] + +[ext_resource type="Script" uid="uid://cw51scv08wj72" path="res://ui.gd" id="1_m1v6r"] + +[node name="UI" 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_m1v6r") + +[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="MarginContainer3" type="MarginContainer" parent="VBoxContainer/HBoxContainer"] +layout_mode = 2 +size_flags_horizontal = 3 + +[node name="Timer" type="Label" parent="VBoxContainer/HBoxContainer/MarginContainer3"] +layout_mode = 2 +text = "Timer" +horizontal_alignment = 1 + +[node name="MarginContainer2" type="MarginContainer" parent="VBoxContainer/HBoxContainer"] +layout_mode = 2 +size_flags_horizontal = 3 + +[node name="Coins" type="Label" parent="VBoxContainer/HBoxContainer/MarginContainer2"] +layout_mode = 2 +text = "Coins" +horizontal_alignment = 2 diff --git a/Scripts/bullet.gd b/Scripts/bullet.gd index 5a91ee5..16f1b71 100644 --- a/Scripts/bullet.gd +++ b/Scripts/bullet.gd @@ -1,6 +1,8 @@ class_name Bullet extends Area2D var speed = 700 +signal bulletDamageSignal(body, bullet) + # Called when the node enters the scene tree for the first time. func _ready() -> void: pass # Replace with function body.func setSpeed(value): @@ -11,3 +13,9 @@ func setSpeed(value): # Called every frame. 'delta' is the elapsed time since the previous frame. func _physics_process(delta: float) -> void: position += transform.x * speed * delta + +func _on_area_entered(area: Area2D) -> void: + print("bullet is hitting area") + if area is Slime: + bulletDamageSignal.emit(area, self) + diff --git a/Scripts/character_body_2d.gd b/Scripts/character_body_2d.gd index d670486..a5a05c4 100644 --- a/Scripts/character_body_2d.gd +++ b/Scripts/character_body_2d.gd @@ -14,7 +14,7 @@ const JUMP_VELOCITY = -400.0 enum FaceDirection{LEFT, RIGHT} var facing:FaceDirection = FaceDirection.RIGHT -enum State{IDLE, RUN, JUMP, FALLING} +enum State{IDLE, RUN, JUMP, FALLING, HURT, DEATH} var current_state:State = State.IDLE var pushTarget @@ -22,6 +22,8 @@ var pushEnabled = false var direction var upJump = false +signal deathAnimationCompleteSignal + func _physics_process(delta: float) -> void: #game loop handle_input() @@ -65,6 +67,10 @@ func update_animation(): player_graphic.play("jump") State.FALLING: player_graphic.play("falling") + State.HURT: + player_graphic.play("hurt") + State.DEATH: + player_graphic.play("death") func handle_movement(delta): # Add the gravity. if not is_on_floor(): @@ -134,10 +140,16 @@ func _on_animation_finished() -> void: match current_state: State.JUMP: upJump = false + State.HURT: + current_state = State.IDLE + State.DEATH: + deathAnimationCompleteSignal.emit() func playerTakesDamage(health): print("Player sees remaining health "+str(health)) + current_state = State.HURT func playerDies(): print("Player sees they died.") + current_state = State.DEATH diff --git a/Scripts/coin.gd b/Scripts/coin.gd index d4549e7..d028a35 100644 --- a/Scripts/coin.gd +++ b/Scripts/coin.gd @@ -13,5 +13,4 @@ func _process(delta: float) -> void: func _on_body_entered(body: Node2D) -> void: - print("coin sees collision") coinCollectedSignal.emit(body, self) diff --git a/Scripts/crate.gd b/Scripts/crate.gd new file mode 100644 index 0000000..7f42195 --- /dev/null +++ b/Scripts/crate.gd @@ -0,0 +1 @@ +class_name Crate extends RigidBody2D diff --git a/Scripts/crate.gd.uid b/Scripts/crate.gd.uid new file mode 100644 index 0000000..621a365 --- /dev/null +++ b/Scripts/crate.gd.uid @@ -0,0 +1 @@ +uid://b546t5rmhjwiu diff --git a/Scripts/gamecontroller.gd b/Scripts/gamecontroller.gd index 9d197be..fdc8c6e 100644 --- a/Scripts/gamecontroller.gd +++ b/Scripts/gamecontroller.gd @@ -3,24 +3,30 @@ extends Node2D var totalCoinsAvailable var timer = Timer.new() -var timeAvailable = 5 +var timeAvailable var level="res://Scenes/game.tscn" var levelTwo = "res://Scenes/level2.tscn" +var startingCoins = 0 var levels = ["res://Scenes/game.tscn", "res://Scenes/level2.tscn", "res://Scenes/level3.tscn"] -var timers = [10,15,9] +var timers = [30,15,9] var currentLevel = 0 signal destroySignal(body) signal levelChangeSignal(level) signal playerTakesDamageSignal(health) signal playerDiesSignal +signal bulletDamageEnemySignal(body) +signal countDownSignal(timeRemaining) +signal coinCountSignal(coinsRemaining, startingCoins) var player:CharacterStats var enemy:CharacterStats var playerHealth:int +var enemiesDict = {} + # Called when the node enters the scene tree for the first time. func _ready() -> void: player = load("res://Scripts/rscs/playerStats.tres") @@ -36,12 +42,15 @@ func _ready() -> void: func secondCounter() -> void: timeAvailable -=1 + countDownSignal.emit(timeAvailable) if timeAvailable <= 0: print("LOSE") #reload the current scene levelChangeSignal.emit(levels[currentLevel]) func reset() -> void: + startingCoins = 0 timeAvailable = timers[currentLevel] + playerHealth = player.starting_health # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta: float) -> void: @@ -60,22 +69,45 @@ func _on_areatrigger(effect, body) -> void: func totalCoinCount(totalCoins): - print("GC knows the total coins is "+str(totalCoins) ) + if startingCoins == 0: + startingCoins = totalCoins totalCoinsAvailable = totalCoins func coinCollected(body, coin): - destroySignal.emit(coin) - totalCoinsAvailable -=1 - if totalCoinsAvailable <= 0: - currentLevel +=1 - if currentLevel >= levels.size(): - currentLevel = 0 - levelChangeSignal.emit(levels[currentLevel]) + if not body is Crate: + destroySignal.emit(coin) + totalCoinsAvailable -=1 + coinCountSignal.emit(totalCoinsAvailable, startingCoins) + if totalCoinsAvailable <= 0: + currentLevel +=1 + if currentLevel >= levels.size(): + currentLevel = 0 + levelChangeSignal.emit(levels[currentLevel]) func playerAttacked(body, slime): print("GC knows player attacked") - playerHealth -= enemy.meleeDamage + playerHealth -= enemiesDict[slime].damage if playerHealth <=0: playerDiesSignal.emit() else: print("Received damage...") playerTakesDamageSignal.emit(playerHealth) + +func playerDead(): + levelChangeSignal.emit(levels[currentLevel]) + +func bulletDamage(area, bullet): + enemiesDict[area].health -= player.rangeDamage + if enemiesDict[area].health <=0: + destroySignal.emit(area) + enemiesDict.erase(area) + else: + bulletDamageEnemySignal.emit(area) + +func addEnemyToLevel(slime): + var randHealth:int = randi() % 20 + var randDamage:int = randi() % 10 + var enemyStat = { + "health":enemy.starting_health + randHealth, + "damage":enemy.meleeDamage + randDamage + } + enemiesDict[slime]=enemyStat diff --git a/Scripts/scene_manager.gd b/Scripts/scene_manager.gd index 3ab3cb5..289bfae 100644 --- a/Scripts/scene_manager.gd +++ b/Scripts/scene_manager.gd @@ -7,6 +7,7 @@ var totalAllowedBullets = 7 @onready var coins: Node2D = $"../Coins" @onready var enemies: Node2D = $"../Enemies" @onready var player: Player = $"../Player" +@onready var ui: Control = $"../CanvasLayer/UI" func _ready() -> void: @@ -19,13 +20,20 @@ func _ready() -> void: for obj in enemies.get_children(): if obj is Slime: obj.playerDamageSignal.connect(Gamecontroller.playerAttacked) + Gamecontroller.addEnemyToLevel(obj) + Gamecontroller.bulletDamageEnemySignal.connect(obj.takeDamage) updateCoins() Gamecontroller.destroySignal.connect(destroyItem) Gamecontroller.levelChangeSignal.connect(changeScene) Gamecontroller.playerTakesDamageSignal.connect(player.playerTakesDamage) + if ui: + Gamecontroller.playerTakesDamageSignal.connect(ui.healthUpdate) + Gamecontroller.countDownSignal.connect(ui.timerUpdate) + Gamecontroller.coinCountSignal.connect(ui.coinsUpdate) Gamecontroller.playerDiesSignal.connect(player.playerDies) + player.deathAnimationCompleteSignal.connect(Gamecontroller.playerDead) #call this any time the coins change func updateCoins() -> void: @@ -47,6 +55,7 @@ func bulletFactory(): if bulletArray.size() < totalAllowedBullets: #make a new bullet mybullet = bullet.instantiate() + mybullet.bulletDamageSignal.connect(Gamecontroller.bulletDamage) owner.add_child(mybullet) else: #recycle bullet diff --git a/Scripts/slime.gd b/Scripts/slime.gd index fbcc338..9f8deb6 100644 --- a/Scripts/slime.gd +++ b/Scripts/slime.gd @@ -26,12 +26,14 @@ func _process(delta: float) -> void: slime_graphic.flip_h = false if right_side_cast.is_colliding(): - direction = -1 - slime_graphic.flip_h = true + if not right_side_cast.get_collider() is Player && not right_side_cast.get_collider() is Slime: + direction = -1 + slime_graphic.flip_h = true if left_side_cast.is_colliding(): - direction = 1 - slime_graphic.flip_h =false + if not left_side_cast.get_collider() is Player && not left_side_cast.get_collider() is Slime: + direction = 1 + slime_graphic.flip_h =false position.x += direction * speed * delta @@ -40,3 +42,7 @@ func _on_body_entered(body: Node2D) -> void: if body is Player: print("Slime attack") playerDamageSignal.emit(body,self) + +func takeDamage(body): + if body == self: + slime_graphic.play("hurt") diff --git a/ui.gd b/ui.gd new file mode 100644 index 0000000..8ac0d0a --- /dev/null +++ b/ui.gd @@ -0,0 +1,18 @@ +extends Control +@onready var health: Label = $VBoxContainer/HBoxContainer/MarginContainer/Health +@onready var timer: Label = $VBoxContainer/HBoxContainer/MarginContainer3/Timer +@onready var coins: Label = $VBoxContainer/HBoxContainer/MarginContainer2/Coins + + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + pass + +func healthUpdate(healthRemaining): + health.text = "Health: "+str(healthRemaining) + +func timerUpdate(timeRemaining): + timer.text = str(timeRemaining) + +func coinsUpdate(coinsRemaining, startingCoins): + coins.text = "Coins: "+str(coinsRemaining)+"/"+str(startingCoins) diff --git a/ui.gd.uid b/ui.gd.uid new file mode 100644 index 0000000..fb851d4 --- /dev/null +++ b/ui.gd.uid @@ -0,0 +1 @@ +uid://cw51scv08wj72