diff --git a/febfabgame/Assets/fonts/PixelOperator8-Bold.ttf b/febfabgame/Assets/fonts/PixelOperator8-Bold.ttf new file mode 100644 index 0000000..10225eb Binary files /dev/null and b/febfabgame/Assets/fonts/PixelOperator8-Bold.ttf differ diff --git a/febfabgame/Assets/fonts/PixelOperator8-Bold.ttf.import b/febfabgame/Assets/fonts/PixelOperator8-Bold.ttf.import new file mode 100644 index 0000000..f8f47c3 --- /dev/null +++ b/febfabgame/Assets/fonts/PixelOperator8-Bold.ttf.import @@ -0,0 +1,34 @@ +[remap] + +importer="font_data_dynamic" +type="FontFile" +uid="uid://bw3apeamf3ad1" +path="res://.godot/imported/PixelOperator8-Bold.ttf-18d3f5771d654272ea5e81396761520b.fontdata" + +[deps] + +source_file="res://Assets/fonts/PixelOperator8-Bold.ttf" +dest_files=["res://.godot/imported/PixelOperator8-Bold.ttf-18d3f5771d654272ea5e81396761520b.fontdata"] + +[params] + +Rendering=null +antialiasing=1 +generate_mipmaps=false +disable_embedded_bitmaps=true +multichannel_signed_distance_field=false +msdf_pixel_range=8 +msdf_size=48 +allow_system_fallback=true +force_autohinter=false +hinting=1 +subpixel_positioning=1 +oversampling=0.0 +Fallbacks=null +fallbacks=[] +Compress=null +compress=true +preload=[] +language_support={} +script_support={} +opentype_features={} diff --git a/febfabgame/Assets/fonts/PixelOperator8.ttf b/febfabgame/Assets/fonts/PixelOperator8.ttf new file mode 100644 index 0000000..f9146ac Binary files /dev/null and b/febfabgame/Assets/fonts/PixelOperator8.ttf differ diff --git a/febfabgame/Assets/fonts/PixelOperator8.ttf.import b/febfabgame/Assets/fonts/PixelOperator8.ttf.import new file mode 100644 index 0000000..397fc5e --- /dev/null +++ b/febfabgame/Assets/fonts/PixelOperator8.ttf.import @@ -0,0 +1,34 @@ +[remap] + +importer="font_data_dynamic" +type="FontFile" +uid="uid://c8245dvygofsq" +path="res://.godot/imported/PixelOperator8.ttf-23bb57fce2fe6dbb570e8add02d65ecc.fontdata" + +[deps] + +source_file="res://Assets/fonts/PixelOperator8.ttf" +dest_files=["res://.godot/imported/PixelOperator8.ttf-23bb57fce2fe6dbb570e8add02d65ecc.fontdata"] + +[params] + +Rendering=null +antialiasing=1 +generate_mipmaps=false +disable_embedded_bitmaps=true +multichannel_signed_distance_field=false +msdf_pixel_range=8 +msdf_size=48 +allow_system_fallback=true +force_autohinter=false +hinting=1 +subpixel_positioning=1 +oversampling=0.0 +Fallbacks=null +fallbacks=[] +Compress=null +compress=true +preload=[] +language_support={} +script_support={} +opentype_features={} diff --git a/febfabgame/Assets/graphics/player/death/Player Death 64x64.png b/febfabgame/Assets/graphics/player/death/Player Death 64x64.png new file mode 100644 index 0000000..2e6a1ae Binary files /dev/null and b/febfabgame/Assets/graphics/player/death/Player Death 64x64.png differ diff --git a/febfabgame/Assets/graphics/player/death/Player Death 64x64.png.import b/febfabgame/Assets/graphics/player/death/Player Death 64x64.png.import new file mode 100644 index 0000000..7f1b5c0 --- /dev/null +++ b/febfabgame/Assets/graphics/player/death/Player Death 64x64.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://b1udsh0kjwm6p" +path="res://.godot/imported/Player Death 64x64.png-8cffae3676cd831a7eeab76d499d241a.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-8cffae3676cd831a7eeab76d499d241a.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/febfabgame/Scenes/UI.tscn b/febfabgame/Scenes/UI.tscn new file mode 100644 index 0000000..ac86b35 --- /dev/null +++ b/febfabgame/Scenes/UI.tscn @@ -0,0 +1,65 @@ +[gd_scene load_steps=4 format=3 uid="uid://by75e75hc6mru"] + +[ext_resource type="FontFile" uid="uid://c8245dvygofsq" path="res://Assets/fonts/PixelOperator8.ttf" id="1_14vep"] +[ext_resource type="Script" path="res://Scripts/ui.gd" id="1_e51tv"] + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_bn8em"] +bg_color = Color(0.195707, 0.483861, 0.218543, 1) + +[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_e51tv") + +[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="VBoxContainer" type="VBoxContainer" parent="VBoxContainer/HBoxContainer/MarginContainer"] +layout_mode = 2 + +[node name="health" type="Label" parent="VBoxContainer/HBoxContainer/MarginContainer/VBoxContainer"] +layout_mode = 2 +theme_override_fonts/font = ExtResource("1_14vep") +theme_override_font_sizes/font_size = 8 +text = "Health" + +[node name="healthProgress" type="ProgressBar" parent="VBoxContainer/HBoxContainer/MarginContainer/VBoxContainer"] +layout_mode = 2 +theme_override_styles/fill = SubResource("StyleBoxFlat_bn8em") +show_percentage = false + +[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 +theme_override_fonts/font = ExtResource("1_14vep") +theme_override_font_sizes/font_size = 8 +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 +theme_override_fonts/font = ExtResource("1_14vep") +theme_override_font_sizes/font_size = 8 +text = "Coins" +horizontal_alignment = 2 diff --git a/febfabgame/Scenes/feb_fab_game lv2.tscn b/febfabgame/Scenes/feb_fab_game lv2.tscn index 7a3389a..20cd8fe 100644 --- a/febfabgame/Scenes/feb_fab_game lv2.tscn +++ b/febfabgame/Scenes/feb_fab_game lv2.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=22 format=4 uid="uid://dj7i8q4okyc4t"] +[gd_scene load_steps=23 format=4 uid="uid://dj7i8q4okyc4t"] [ext_resource type="Script" path="res://Scripts/gamecontroller.gd" id="1_8umew"] [ext_resource type="Texture2D" uid="uid://b0qpo3wfi6qju" path="res://Assets/graphics/backgrounds/block.png" id="2_bhclh"] @@ -13,6 +13,7 @@ [ext_resource type="PackedScene" uid="uid://b0snboj7mbad5" path="res://Scenes/player.tscn" id="11_q3vru"] [ext_resource type="Script" path="res://Scripts/scene_manager.gd" id="12_cqomf"] [ext_resource type="PackedScene" uid="uid://d0ve3ds64sk3p" path="res://Scenes/trigger.tscn" id="13_buf7s"] +[ext_resource type="PackedScene" uid="uid://by75e75hc6mru" path="res://Scenes/UI.tscn" id="14_yul7q"] [sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_ky1en"] texture = ExtResource("6_aca0c") @@ -495,3 +496,8 @@ effect = "powerup" position = Vector2(4, -1) shape = SubResource("RectangleShape2D_ilkes") debug_color = Color(0.304464, 0.623664, 0.204875, 0.42) + +[node name="CanvasLayer" type="CanvasLayer" parent="."] + +[node name="UI" parent="CanvasLayer" instance=ExtResource("14_yul7q")] +metadata/_edit_use_anchors_ = true diff --git a/febfabgame/Scenes/feb_fab_game lv3.tscn b/febfabgame/Scenes/feb_fab_game lv3.tscn index e369568..e1d6cb3 100644 --- a/febfabgame/Scenes/feb_fab_game lv3.tscn +++ b/febfabgame/Scenes/feb_fab_game lv3.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=21 format=4 uid="uid://663q2oo8cvte"] +[gd_scene load_steps=22 format=4 uid="uid://663q2oo8cvte"] [ext_resource type="Texture2D" uid="uid://b0qpo3wfi6qju" path="res://Assets/graphics/backgrounds/block.png" id="1_ci28m"] [ext_resource type="Texture2D" uid="uid://cq4t2eebwx5mj" path="res://Assets/graphics/backgrounds/forestbackground.png" id="2_yaphm"] @@ -12,6 +12,7 @@ [ext_resource type="PackedScene" uid="uid://b0snboj7mbad5" path="res://Scenes/player.tscn" id="10_qs1yn"] [ext_resource type="Script" path="res://Scripts/scene_manager.gd" id="11_7dhkr"] [ext_resource type="PackedScene" uid="uid://d0ve3ds64sk3p" path="res://Scenes/trigger.tscn" id="12_nm3ll"] +[ext_resource type="PackedScene" uid="uid://by75e75hc6mru" path="res://Scenes/UI.tscn" id="13_nwu02"] [sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_ky1en"] texture = ExtResource("5_txjyq") @@ -493,3 +494,8 @@ effect = "powerup" position = Vector2(4, -1) shape = SubResource("RectangleShape2D_ilkes") debug_color = Color(0.304464, 0.623664, 0.204875, 0.42) + +[node name="CanvasLayer" type="CanvasLayer" parent="."] + +[node name="UI" parent="CanvasLayer" instance=ExtResource("13_nwu02")] +metadata/_edit_use_anchors_ = true diff --git a/febfabgame/Scenes/feb_fab_game.tscn b/febfabgame/Scenes/feb_fab_game.tscn index fd38f77..e08d13c 100644 --- a/febfabgame/Scenes/feb_fab_game.tscn +++ b/febfabgame/Scenes/feb_fab_game.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=23 format=4 uid="uid://cpuc12n61qg6b"] +[gd_scene load_steps=24 format=4 uid="uid://cpuc12n61qg6b"] [ext_resource type="Texture2D" uid="uid://fwqc3qyc3jss" path="res://Assets/graphics/terrains/Terrain (32x32).png" id="2_2rxht"] [ext_resource type="Texture2D" uid="uid://b0qpo3wfi6qju" path="res://Assets/graphics/backgrounds/block.png" id="2_d6us3"] @@ -14,6 +14,7 @@ [ext_resource type="Texture2D" uid="uid://c1k7osqmbur1d" path="res://Assets/graphics/backgrounds/rocks.png" id="5_umo5t"] [ext_resource type="PackedScene" uid="uid://buyuw4dj3uovh" path="res://Scenes/coin.tscn" id="13_o1lsv"] [ext_resource type="PackedScene" uid="uid://col8ryohnxcnw" path="res://Scenes/slime.tscn" id="14_dmc5d"] +[ext_resource type="PackedScene" uid="uid://by75e75hc6mru" path="res://Scenes/UI.tscn" id="15_clvfp"] [sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_ky1en"] texture = ExtResource("2_2rxht") @@ -514,3 +515,8 @@ position = Vector2(561, 372) [node name="Area2D2" parent="badguys" instance=ExtResource("14_dmc5d")] position = Vector2(293, 566) + +[node name="CanvasLayer" type="CanvasLayer" parent="."] + +[node name="UI" parent="CanvasLayer" instance=ExtResource("15_clvfp")] +metadata/_edit_use_anchors_ = true diff --git a/febfabgame/Scenes/player.tscn b/febfabgame/Scenes/player.tscn index 94d450c..e1e0698 100644 --- a/febfabgame/Scenes/player.tscn +++ b/febfabgame/Scenes/player.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=33 format=3 uid="uid://b0snboj7mbad5"] +[gd_scene load_steps=44 format=3 uid="uid://b0snboj7mbad5"] [ext_resource type="Script" path="res://Scripts/Player.gd" id="1_mjl5w"] +[ext_resource type="Texture2D" uid="uid://b1udsh0kjwm6p" path="res://Assets/graphics/player/death/Player Death 64x64.png" id="2_3mg5s"] [ext_resource type="Texture2D" uid="uid://jnn6hcmfgyfo" path="res://Assets/graphics/player/idle/Player Idle 48x48.png" id="2_20p21"] [ext_resource type="Texture2D" uid="uid://b21la5hkk8w5l" path="res://Assets/graphics/player/hurt/Player Hurt 48x48.png" id="2_xgiy8"] [ext_resource type="Texture2D" uid="uid://ciaht230dnmu3" path="res://Assets/graphics/player/run/player run 48x48.png" id="3_ergv2"] @@ -8,6 +9,46 @@ [sub_resource type="CircleShape2D" id="CircleShape2D_xiumq"] +[sub_resource type="AtlasTexture" id="AtlasTexture_tj7s0"] +atlas = ExtResource("2_3mg5s") +region = Rect2(0, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_2s788"] +atlas = ExtResource("2_3mg5s") +region = Rect2(48, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_y3jwc"] +atlas = ExtResource("2_3mg5s") +region = Rect2(96, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_8l2gc"] +atlas = ExtResource("2_3mg5s") +region = Rect2(144, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_bxljl"] +atlas = ExtResource("2_3mg5s") +region = Rect2(192, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_uroio"] +atlas = ExtResource("2_3mg5s") +region = Rect2(240, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_ou44u"] +atlas = ExtResource("2_3mg5s") +region = Rect2(288, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_s01m7"] +atlas = ExtResource("2_3mg5s") +region = Rect2(336, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_520ja"] +atlas = ExtResource("2_3mg5s") +region = Rect2(384, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_msh31"] +atlas = ExtResource("2_3mg5s") +region = Rect2(432, 0, 48, 48) + [sub_resource type="AtlasTexture" id="AtlasTexture_b4hot"] atlas = ExtResource("2_xgiy8") region = Rect2(0, 0, 48, 48) @@ -112,6 +153,41 @@ region = Rect2(336, 0, 48, 48) animations = [{ "frames": [{ "duration": 1.0, +"texture": SubResource("AtlasTexture_tj7s0") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_2s788") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_y3jwc") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_8l2gc") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_bxljl") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_uroio") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_ou44u") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_s01m7") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_520ja") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_msh31") +}], +"loop": false, +"name": &"death", +"speed": 12.0 +}, { +"frames": [{ +"duration": 1.0, "texture": SubResource("AtlasTexture_b4hot") }, { "duration": 1.0, @@ -231,8 +307,10 @@ texture_filter = 1 position = Vector2(2, -11) scale = Vector2(1.54734, 1.26736) sprite_frames = SubResource("SpriteFrames_tbufb") -animation = &"hurt" +animation = &"death" autoplay = "hurt" +frame = 9 +frame_progress = 1.0 [node name="Camera2D" type="Camera2D" parent="."] diff --git a/febfabgame/Scenes/slime.tscn b/febfabgame/Scenes/slime.tscn index f3b3038..51fff30 100644 --- a/febfabgame/Scenes/slime.tscn +++ b/febfabgame/Scenes/slime.tscn @@ -56,4 +56,18 @@ frame_progress = 0.192104 position = Vector2(0, 4.5) shape = SubResource("RectangleShape2D_khbh8") +[node name="rightCast" type="RayCast2D" parent="."] +target_position = Vector2(13, 0) + +[node name="leftCast" type="RayCast2D" parent="."] +target_position = Vector2(-13, 0) + +[node name="rightCastFloor" type="RayCast2D" parent="."] +position = Vector2(6, 0) +target_position = Vector2(0, 14) + +[node name="leftCastFloor" type="RayCast2D" parent="."] +position = Vector2(-6, 0) +target_position = Vector2(0, 14) + [connection signal="body_entered" from="." to="." method="_on_body_entered"] diff --git a/febfabgame/Scripts/Player.gd b/febfabgame/Scripts/Player.gd index 4b47978..a6ce91c 100644 --- a/febfabgame/Scripts/Player.gd +++ b/febfabgame/Scripts/Player.gd @@ -20,6 +20,8 @@ var isJumping = false var animPlaying = "idle" var living = true +signal deathCompleteSignal + func _physics_process(delta: float) -> void: if living and not animPlaying == "hurt": # Add the gravity. @@ -106,8 +108,16 @@ func hurtPlayer(health): print("Player takes damage, health remaining::"+str(health)) animPlaying = "hurt" playerGraphic.play(animPlaying) +func killPlayer(): + print("KILL") + living = false + animPlaying = "death" + playerGraphic.play(animPlaying) + func _on_animated_finished() -> void: if animPlaying == "hurt": - animPlaying=="idle" + animPlaying = "idle" + if animPlaying == "death": + deathCompleteSignal.emit() diff --git a/febfabgame/Scripts/gamecontroller.gd b/febfabgame/Scripts/gamecontroller.gd index b8278a9..26be2c0 100644 --- a/febfabgame/Scripts/gamecontroller.gd +++ b/febfabgame/Scripts/gamecontroller.gd @@ -9,7 +9,10 @@ var enemies = 0 signal destroySignal(body) signal LevelCompleteSignal(level) -signal playerHurtSignal(healthRemaining) +signal playerHurtSignal(healthRemaining, maxHealth) +signal playerKillSignal +signal timerUpdateSignal(timeRemaining, totalTimeForLevel) +signal coinUpdateSignal(coinsCollectedTotal, coinsAvailableTotal) #Level Info var timer:= Timer.new() @@ -21,6 +24,7 @@ var countdown=0 var player:Resource var slime:Resource +var enemiesDict={} # Called when the node enters the scene tree for the first time. func _ready() -> void: @@ -33,12 +37,17 @@ func _ready() -> void: timer.one_shot = false timer.connect("timeout", secondCounter) timer.start() + func reset(): countdown = timers[currentLevel] + player.health = player.max_health + coinsCollected = 0 + func secondCounter(): #print("tick") countdown -=1 + timerUpdateSignal.emit(countdown, timers[currentLevel]) if countdown <=0: print("LOSER") LevelCompleteSignal.emit(levels[currentLevel]) @@ -92,8 +101,10 @@ func coinCollected(body, coin): if body is Player: #increase coins collected count coinsCollected +=1 + coinUpdateSignal.emit(coinsCollected, totalCoinsAvailable) print("total coins =" + str(coinsCollected)) destroySignal.emit(coin) + func playerDamage(body, badguy): if body is Player: @@ -101,9 +112,23 @@ func playerDamage(body, badguy): print("player health "+str(player.health)+"takes damage "+str(slime.meleeDamage)) player.health -= slime.meleeDamage if player.health > 0: - playerHurtSignal.emit(player.health) + playerHurtSignal.emit(player.health, player.max_health) else: - print("dead") - + playerKillSignal.emit() + print(enemiesDict[badguy]["health"]) + +func addBadGuy(enemy): + print("adding an enemy") + #use a dictionary + var enemyStats = { + "health": slime.health, + "damage": slime.meleeDamage + } + enemiesDict[enemy] = enemyStats + func numberOfBadguys(value): enemies = value + +func deathComplete(): + print("GC knows death is complete") + LevelCompleteSignal.emit(levels[currentLevel]) diff --git a/febfabgame/Scripts/scene_manager.gd b/febfabgame/Scripts/scene_manager.gd index c1a4fe7..ee80b60 100644 --- a/febfabgame/Scripts/scene_manager.gd +++ b/febfabgame/Scripts/scene_manager.gd @@ -5,6 +5,7 @@ extends Node @onready var coins: Node2D = $"../coins" @onready var badguys: Node2D = $"../badguys" @onready var player: Player = $"../CharacterBody2D" +@onready var ui: Control = $"../CanvasLayer/UI" @@ -71,6 +72,7 @@ func buildLevel(): if obj is Slime: totalBadguys +=1 obj.playerDamagSignal.connect(Gamecontroller.playerDamage) + Gamecontroller.addBadGuy(obj) Gamecontroller.numberOfBadguys(totalBadguys) #wire up the triggers @@ -84,6 +86,13 @@ func buildLevel(): Gamecontroller.destroySignal.connect(destroy) Gamecontroller.LevelCompleteSignal.connect(loadLevel) Gamecontroller.playerHurtSignal.connect(playerHurt) + Gamecontroller.playerHurtSignal.connect(ui.healthUpdate) + Gamecontroller.playerKillSignal.connect(playerKill) + Gamecontroller.timerUpdateSignal.connect(ui.timerUpdate) + Gamecontroller.coinUpdateSignal.connect(ui.coinsUpdate) + + #listen to player + player.deathCompleteSignal.connect(Gamecontroller.deathComplete) func loadLevel(level): get_tree().change_scene_to_file(level) @@ -92,5 +101,8 @@ func _ready() -> void: buildLevel() Gamecontroller.reset() -func playerHurt(health): +func playerHurt(health, _maxHealth): player.hurtPlayer(health) + +func playerKill(): + player.killPlayer() diff --git a/febfabgame/Scripts/slime.gd b/febfabgame/Scripts/slime.gd index 12442b0..b19eebe 100644 --- a/febfabgame/Scripts/slime.gd +++ b/febfabgame/Scripts/slime.gd @@ -1,8 +1,33 @@ class_name Slime extends Area2D signal playerDamagSignal +@onready var right_cast: RayCast2D = $rightCast +@onready var left_cast: RayCast2D = $leftCast +@onready var right_cast_floor: RayCast2D = $rightCastFloor +@onready var left_cast_floor: RayCast2D = $leftCastFloor +var speed = 100 +var direction = 1 + +func _process(delta: float) -> void: + if not right_cast_floor.is_colliding(): + direction = -1 + if not left_cast_floor.is_colliding(): + direction = 1 + + + if right_cast.is_colliding(): + var body = right_cast.get_collider() + if not body is Player: + direction = -1 + if left_cast.is_colliding(): + var body = left_cast.get_collider() + if not body is Player: + direction = 1 + + position.x += direction*speed*delta + func _on_body_entered(body: Node2D) -> void: playerDamagSignal.emit(body, self) print("bad guy yum yum") diff --git a/febfabgame/Scripts/ui.gd b/febfabgame/Scripts/ui.gd new file mode 100644 index 0000000..04ebb9b --- /dev/null +++ b/febfabgame/Scripts/ui.gd @@ -0,0 +1,26 @@ +extends Control + +@onready var timer: Label = $VBoxContainer/HBoxContainer/MarginContainer2/timer +@onready var coins: Label = $VBoxContainer/HBoxContainer/MarginContainer3/coins +@onready var health: Label = $VBoxContainer/HBoxContainer/MarginContainer/VBoxContainer/health +@onready var health_progress: ProgressBar = $VBoxContainer/HBoxContainer/MarginContainer/VBoxContainer/healthProgress + + + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + health.text="HEALTH" + timer.text="TIMER" + coins.text="COINS" + +func healthUpdate(currentHealth, maxHealth): + print( float(currentHealth) / maxHealth* 100) + health.text = "Health: "+str(currentHealth)+" of "+str(maxHealth) + health_progress.value = (float(currentHealth) / maxHealth* 100) + +func timerUpdate(timeRemaining, _timeAvailable): + #print(timeRemaining, _timeAvailable) + timer.text= "Time: "+str(timeRemaining) +func coinsUpdate(coinsCollected, CoinsAvailable): + print(coinsCollected, CoinsAvailable) + coins.text ="coins: "+str(coinsCollected)+" of "+str(CoinsAvailable)