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..4693a85 --- /dev/null +++ b/assets/graphics/player/death/Player Death 64x64.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://ee76odplcxaw" +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 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..21ff7b3 --- /dev/null +++ b/assets/graphics/player/hurt/Player Hurt 48x48.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://deuibts3u2osv" +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 diff --git a/scenes/bullet.tscn b/scenes/bullet.tscn index ffa4b0d..9093e6c 100644 --- a/scenes/bullet.tscn +++ b/scenes/bullet.tscn @@ -20,3 +20,5 @@ position = Vector2(-3, -2) rotation = 3.14159 scale = Vector2(0.071529, 0.071529) texture = ExtResource("2_y25gk") + +[connection signal="area_entered" from="." to="." method="_on_area_entered"] diff --git a/scenes/crate.tscn b/scenes/crate.tscn index bb77fa7..fcd53e9 100644 --- a/scenes/crate.tscn +++ b/scenes/crate.tscn @@ -1,10 +1,12 @@ -[gd_scene load_steps=3 format=3 uid="uid://dm0s1wei11x43"] +[gd_scene load_steps=4 format=3 uid="uid://dm0s1wei11x43"] [ext_resource type="Texture2D" uid="uid://bupa7vw3dnbia" path="res://assets/graphics/objects/crate.png" id="1_b66cd"] +[ext_resource type="Script" uid="uid://cb5w1tpwn7cn0" path="res://scripts/crate.gd" id="1_dwt0d"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_uwrxv"] [node name="RigidBody2D3" type="RigidBody2D"] +script = ExtResource("1_dwt0d") metadata/_edit_group_ = true [node name="Sprite2D" type="Sprite2D" parent="."] diff --git a/scenes/game.tscn b/scenes/game.tscn index eaf6c20..3c04f70 100644 --- a/scenes/game.tscn +++ b/scenes/game.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=19 format=4 uid="uid://dc4obqdsdq81h"] +[gd_scene load_steps=20 format=4 uid="uid://dc4obqdsdq81h"] [ext_resource type="PackedScene" uid="uid://drodkouhgldnf" path="res://scenes/player.tscn" id="2_lbhrr"] [ext_resource type="Script" uid="uid://cf8f01b63m2hq" path="res://scripts/scene_manager.gd" id="2_p57ef"] @@ -12,6 +12,7 @@ [ext_resource type="Texture2D" uid="uid://c3ubltiqufnyr" path="res://assets/graphics/terrains/mushroom_32x64.png" id="4_vtaks"] [ext_resource type="PackedScene" uid="uid://qk8sby4wmfnn" path="res://scenes/slime.tscn" id="12_dinhu"] [ext_resource type="PackedScene" uid="uid://1kjfjblxns38" path="res://scenes/coin.tscn" id="13_kvuet"] +[ext_resource type="PackedScene" uid="uid://cifuwno7jvsaf" path="res://scenes/ui.tscn" id="13_trtic"] [sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_gee14"] texture = ExtResource("2_u5sy4") @@ -452,7 +453,7 @@ position = Vector2(399, 297) position = Vector2(333, 284) [node name="RigidBody2D5" parent="Crates" instance=ExtResource("3_lbhrr")] -position = Vector2(590, 342) +position = Vector2(511, 340) [node name="triggers" type="Node2D" parent="."] @@ -498,5 +499,9 @@ position = Vector2(618, 308) [node name="Slime2" parent="Enemies" instance=ExtResource("12_dinhu")] position = Vector2(618, 372) +[node name="CanvasLayer" type="CanvasLayer" parent="."] + +[node name="Ui" parent="CanvasLayer" instance=ExtResource("13_trtic")] + [connection signal="areatrigger" from="triggers/Area2D" to="." method="_on_areatrigger"] [connection signal="areatrigger" from="triggers/Area2D2" to="." method="_on_areatrigger"] diff --git a/scenes/level2.tscn b/scenes/level2.tscn index f434d09..841721a 100644 --- a/scenes/level2.tscn +++ b/scenes/level2.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=18 format=4 uid="uid://ct1x1utv2pfpu"] +[gd_scene load_steps=19 format=4 uid="uid://ct1x1utv2pfpu"] [ext_resource type="Texture2D" uid="uid://v7huiinvs1pw" path="res://assets/graphics/terrains/forestsky.png" id="1_76toy"] [ext_resource type="Texture2D" uid="uid://drprk4q04ohta" path="res://assets/graphics/terrains/forestbackground.png" id="2_8g4ke"] @@ -11,6 +11,7 @@ [ext_resource type="PackedScene" uid="uid://dm0s1wei11x43" path="res://scenes/crate.tscn" id="9_o3sye"] [ext_resource type="PackedScene" uid="uid://bu03yhhfncspe" path="res://scenes/trigger.tscn" id="10_24ks5"] [ext_resource type="PackedScene" uid="uid://1kjfjblxns38" path="res://scenes/coin.tscn" id="11_s4es8"] +[ext_resource type="PackedScene" uid="uid://cifuwno7jvsaf" path="res://scenes/ui.tscn" id="12_8g4ke"] [sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_gee14"] texture = ExtResource("4_ve5ok") @@ -491,5 +492,9 @@ position = Vector2(301, 373) [node name="Enemies" type="Node2D" parent="."] +[node name="CanvasLayer" type="CanvasLayer" parent="."] + +[node name="Ui" parent="CanvasLayer" instance=ExtResource("12_8g4ke")] + [connection signal="areatrigger" from="triggers/Area2D" to="." method="_on_areatrigger"] [connection signal="areatrigger" from="triggers/Area2D2" to="." method="_on_areatrigger"] diff --git a/scenes/level3.tscn b/scenes/level3.tscn index 38490c8..e376300 100644 --- a/scenes/level3.tscn +++ b/scenes/level3.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=18 format=4 uid="uid://ck8wgd4sr3vpl"] +[gd_scene load_steps=19 format=4 uid="uid://ck8wgd4sr3vpl"] [ext_resource type="Texture2D" uid="uid://v7huiinvs1pw" path="res://assets/graphics/terrains/forestsky.png" id="1_fh4ka"] +[ext_resource type="PackedScene" uid="uid://cifuwno7jvsaf" path="res://scenes/ui.tscn" id="1_qewby"] [ext_resource type="Texture2D" uid="uid://drprk4q04ohta" path="res://assets/graphics/terrains/forestbackground.png" id="2_qewby"] [ext_resource type="Texture2D" uid="uid://bbqbgivyotdyq" path="res://assets/graphics/terrains/spookytrees.png" id="3_bradm"] [ext_resource type="Texture2D" uid="uid://c4ltj66f0bstb" path="res://assets/graphics/terrains/Terrain (32x32).png" id="4_got4s"] @@ -405,6 +406,10 @@ distance = 144.0 [node name="Game" type="Node2D"] +[node name="CanvasLayer" type="CanvasLayer" parent="."] + +[node name="Ui" parent="CanvasLayer" instance=ExtResource("1_qewby")] + [node name="Parallax2D" type="Parallax2D" parent="."] repeat_size = Vector2(320, 180) diff --git a/scenes/player.tscn b/scenes/player.tscn index bcbb627..c07d515 100644 --- a/scenes/player.tscn +++ b/scenes/player.tscn @@ -1,16 +1,74 @@ -[gd_scene load_steps=28 format=3 uid="uid://drodkouhgldnf"] +[gd_scene load_steps=44 format=3 uid="uid://drodkouhgldnf"] [ext_resource type="Script" uid="uid://dmyw2bn6gnbbv" path="res://scripts/character_body_2d.gd" id="1_3vyb7"] [ext_resource type="Texture2D" uid="uid://44l8sisj1m28" path="res://assets/graphics/player/jump/player jump 48x48.png" id="2_dqkch"] [ext_resource type="Texture2D" uid="uid://bu65v0qav121i" path="res://assets/graphics/player/idle/Player Idle 48x48.png" id="2_g2els"] +[ext_resource type="Texture2D" uid="uid://ee76odplcxaw" path="res://assets/graphics/player/death/Player Death 64x64.png" id="2_tuyoq"] [ext_resource type="Texture2D" uid="uid://cul2mnim1qiyl" path="res://assets/graphics/player/run/player run 48x48.png" id="3_qhqgy"] +[ext_resource type="Texture2D" uid="uid://deuibts3u2osv" path="res://assets/graphics/player/hurt/Player Hurt 48x48.png" id="3_qlg0r"] [sub_resource type="CircleShape2D" id="CircleShape2D_8cj0n"] +[sub_resource type="AtlasTexture" id="AtlasTexture_pf23h"] +atlas = ExtResource("2_tuyoq") +region = Rect2(0, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_dt7fs"] +atlas = ExtResource("2_tuyoq") +region = Rect2(48, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_wqfne"] +atlas = ExtResource("2_tuyoq") +region = Rect2(96, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_wnwbv"] +atlas = ExtResource("2_tuyoq") +region = Rect2(144, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_gl8cc"] +atlas = ExtResource("2_tuyoq") +region = Rect2(192, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_487ah"] +atlas = ExtResource("2_tuyoq") +region = Rect2(240, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_md1ol"] +atlas = ExtResource("2_tuyoq") +region = Rect2(288, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_bj30b"] +atlas = ExtResource("2_tuyoq") +region = Rect2(336, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_jc3p3"] +atlas = ExtResource("2_tuyoq") +region = Rect2(384, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_hax0n"] +atlas = ExtResource("2_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) @@ -95,6 +153,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, @@ -103,6 +196,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, @@ -201,7 +311,7 @@ position = Vector2(-14, -5) texture_filter = 1 position = Vector2(0, -5) sprite_frames = SubResource("SpriteFrames_jej6c") -animation = &"falling" +animation = &"death" autoplay = "idle" [node name="Camera2D" type="Camera2D" parent="."] diff --git a/scenes/slime.tscn b/scenes/slime.tscn index 4d80636..50ac851 100644 --- a/scenes/slime.tscn +++ b/scenes/slime.tscn @@ -1,8 +1,24 @@ -[gd_scene load_steps=9 format=3 uid="uid://qk8sby4wmfnn"] +[gd_scene load_steps=13 format=3 uid="uid://qk8sby4wmfnn"] [ext_resource type="Script" uid="uid://b0naxk1huoh1b" path="res://scripts/slime.gd" id="1_p2gj0"] [ext_resource type="Texture2D" uid="uid://dqyyvekkdnc4" path="res://assets/graphics/enemies/slime_green (1).png" id="2_n6pvg"] +[sub_resource type="AtlasTexture" id="AtlasTexture_p2gj0"] +atlas = ExtResource("2_n6pvg") +region = Rect2(0, 48, 24, 24) + +[sub_resource type="AtlasTexture" id="AtlasTexture_n6pvg"] +atlas = ExtResource("2_n6pvg") +region = Rect2(24, 48, 24, 24) + +[sub_resource type="AtlasTexture" id="AtlasTexture_v5wyi"] +atlas = ExtResource("2_n6pvg") +region = Rect2(48, 48, 24, 24) + +[sub_resource type="AtlasTexture" id="AtlasTexture_0l8pv"] +atlas = ExtResource("2_n6pvg") +region = Rect2(72, 48, 24, 24) + [sub_resource type="AtlasTexture" id="AtlasTexture_pjw23"] atlas = ExtResource("2_n6pvg") region = Rect2(0, 24, 24, 24) @@ -23,6 +39,23 @@ region = Rect2(72, 24, 24, 24) animations = [{ "frames": [{ "duration": 1.0, +"texture": SubResource("AtlasTexture_p2gj0") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_n6pvg") +}, { +"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_pjw23") }, { "duration": 1.0, @@ -50,7 +83,6 @@ texture_filter = 1 sprite_frames = SubResource("SpriteFrames_v5wyi") animation = &"idle" autoplay = "idle" -frame_progress = 0.916706 [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..575a283 --- /dev/null +++ b/scenes/ui.tscn @@ -0,0 +1,47 @@ +[gd_scene load_steps=2 format=3 uid="uid://cifuwno7jvsaf"] + +[ext_resource type="Script" uid="uid://cguclh40lh0w1" path="res://scripts/ui.gd" id="1_nt7q6"] + +[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_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 +text = "Timer" +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 diff --git a/scripts/bullet.gd b/scripts/bullet.gd index 82cffa6..fa6bbdb 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. @@ -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 be5492e..1941e1f 100644 --- a/scripts/character_body_2d.gd +++ b/scripts/character_body_2d.gd @@ -12,7 +12,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 @@ -20,6 +20,8 @@ var pushEnabled = false var direction var upJump = false +signal deathAnimationCompleteSignal + func _physics_process(delta: float) -> void: #game loop handle_input() @@ -60,6 +62,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. @@ -131,9 +137,15 @@ 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 he ded.") + current_state = State.DEATH diff --git a/scripts/coin.gd b/scripts/coin.gd index 010e67a..2b975fb 100644 --- a/scripts/coin.gd +++ b/scripts/coin.gd @@ -12,5 +12,5 @@ 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..06d8724 --- /dev/null +++ b/scripts/crate.gd.uid @@ -0,0 +1 @@ +uid://cb5w1tpwn7cn0 diff --git a/scripts/gamecontroller.gd b/scripts/gamecontroller.gd index 8eac5c8..7024431 100644 --- a/scripts/gamecontroller.gd +++ b/scripts/gamecontroller.gd @@ -3,23 +3,30 @@ extends Node2D var totalCoinsAvailable =0 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 playerTakeDamageSignal(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,13 +43,15 @@ func _ready() -> void: func secondCounter() -> void: timeAvailable -=1 + countDownSignal.emit(timeAvailable) if timeAvailable <= 0: print("YOU 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: pass @@ -60,24 +69,46 @@ func _on_areatrigger(effect, body) -> void: print("Player health is now "+str(playerHealth)) func totalCoinCount(totalCoins): - + if startingCoins == 0: + startingCoins = totalCoins totalCoinsAvailable = totalCoins -func coinCollected(body, coin): - destroySignal.emit(coin) - totalCoinsAvailable -=1 - if totalCoinsAvailable <= 0: - print("YOU WIN") - currentLevel +=1 - if currentLevel >= levels.size(): - currentLevel = 0 - - levelChangeSignal.emit(levels[currentLevel]) +func coinCollected(body, coin): + if not body is Crate: + destroySignal.emit(coin) + totalCoinsAvailable -=1 + coinCountSignal.emit(totalCoinsAvailable, startingCoins) + if totalCoinsAvailable <= 0: + print("YOU WIN") + 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: playerTakeDamageSignal.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 bd0cf2f..9befafe 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: Gamecontroller.reset() @@ -18,14 +19,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.playerTakeDamageSignal.connect(player.playerTakesDamage) + if ui: + Gamecontroller.playerTakeDamageSignal.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: var coinCount = 0 @@ -46,6 +53,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 a08b8d8..9079f51 100644 --- a/scripts/slime.gd +++ b/scripts/slime.gd @@ -5,6 +5,7 @@ class_name Slime extends Area2D @onready var left_down_cast: RayCast2D = $LeftDownCast @onready var right_down_cast: RayCast2D = $RightDownCast + var speed:int = 100 var direction = 1 @@ -16,6 +17,7 @@ func _ready() -> void: # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta: float) -> void: + if not right_down_cast.is_colliding(): direction = -1 slime_graphic.flip_h = true @@ -25,12 +27,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 @@ -39,3 +43,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/scripts/ui.gd b/scripts/ui.gd new file mode 100644 index 0000000..7718c7d --- /dev/null +++ b/scripts/ui.gd @@ -0,0 +1,18 @@ +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 + + +# 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/scripts/ui.gd.uid b/scripts/ui.gd.uid new file mode 100644 index 0000000..45b2cb5 --- /dev/null +++ b/scripts/ui.gd.uid @@ -0,0 +1 @@ +uid://cguclh40lh0w1