diff --git a/Main.tscn b/Main.tscn index bcacac2..314ba34 100644 --- a/Main.tscn +++ b/Main.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=26 format=2] +[gd_scene load_steps=27 format=2] [ext_resource path="res://assets/Backgrounds/bgmuck.png" type="Texture" id=1] [ext_resource path="res://src/playerC/Player.tscn" type="PackedScene" id=2] @@ -12,6 +12,7 @@ [ext_resource path="res://assets/UI/Healthbar.png" type="Texture" id=10] [ext_resource path="res://assets/UI/Healthbar-Indicator.png" type="Texture" id=11] [ext_resource path="res://src/UI/HealthBar.gd" type="Script" id=12] +[ext_resource path="res://icon.png" type="Texture" id=13] [sub_resource type="ConvexPolygonShape2D" id=2] points = PoolVector2Array( 16, 16, 0, 16, 0, 0, 16, 0 ) @@ -223,21 +224,44 @@ position = Vector2( 262, 44 ) actor_type = "NPC" [node name="UI_Dialog" parent="." instance=ExtResource( 9 )] - -[node name="Label" type="Label" parent="."] visible = false -margin_left = 75.0 -margin_top = 14.0 -margin_right = 301.0 -margin_bottom = 53.0 + +[node name="UI_Layer" type="CanvasLayer" parent="."] +layer = 2 + +[node name="PanelContainer" type="PanelContainer" parent="UI_Layer"] +visible = false +margin_left = 2.0 +margin_top = 2.0 +margin_right = 318.0 +margin_bottom = 80.0 + +[node name="HSplitContainer" type="HSplitContainer" parent="UI_Layer/PanelContainer"] +margin_left = 7.0 +margin_top = 7.0 +margin_right = 309.0 +margin_bottom = 71.0 +size_flags_vertical = 0 +split_offset = 1 + +[node name="TextureRect" type="TextureRect" parent="UI_Layer/PanelContainer/HSplitContainer"] +margin_right = 65.0 +margin_bottom = 64.0 +grow_vertical = 2 +size_flags_vertical = 5 +texture = ExtResource( 13 ) + +[node name="Label" type="Label" parent="UI_Layer/PanelContainer/HSplitContainer"] +margin_left = 77.0 +margin_right = 302.0 +margin_bottom = 64.0 +size_flags_vertical = 1 +size_flags_stretch_ratio = 5.0 custom_fonts/font = ExtResource( 8 ) text = "In a world where danger lurks in your plumbing. One thing decides to do another thing and we all determine it wasn't worth it. Hello World" autowrap = true -[node name="CanvasLayer" type="CanvasLayer" parent="."] -layer = 2 - -[node name="HealthBar" type="TextureProgress" parent="CanvasLayer"] +[node name="HealthBar" type="TextureProgress" parent="UI_Layer"] margin_left = 2.0 margin_top = 2.0 margin_right = 104.0 diff --git a/src/Projectile.tscn b/src/Projectile.tscn index 85c2783..72f562e 100644 --- a/src/Projectile.tscn +++ b/src/Projectile.tscn @@ -1,7 +1,11 @@ -[gd_scene load_steps=5 format=2] +[gd_scene load_steps=6 format=2] [ext_resource path="res://src/Projectile.gd" type="Script" id=1] [ext_resource path="res://assets/bullet.png" type="Texture" id=2] +[ext_resource path="res://src/components/Hitbox_Component.tscn" type="PackedScene" id=3] + +[sub_resource type="CircleShape2D" id=2] +radius = 4.0 [sub_resource type="SpriteFrames" id=1] animations = [ { @@ -11,9 +15,6 @@ animations = [ { "speed": 5.0 } ] -[sub_resource type="CircleShape2D" id=2] -radius = 4.0 - [node name="Projectile" type="RigidBody2D"] collision_layer = 64 collision_mask = 33 @@ -22,15 +23,23 @@ contacts_reported = 2 contact_monitor = true script = ExtResource( 1 ) -[node name="AnimatedSprite" type="AnimatedSprite" parent="."] -frames = SubResource( 1 ) - [node name="CollisionShape2D" type="CollisionShape2D" parent="."] shape = SubResource( 2 ) +[node name="AnimatedSprite" type="AnimatedSprite" parent="."] +frames = SubResource( 1 ) + [node name="Timer" type="Timer" parent="."] wait_time = 3.0 one_shot = true autostart = true +[node name="Hitbox_Component" parent="." instance=ExtResource( 3 )] +collision_layer = 1 +collision_mask = 32 +damage_amount = 10 + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Hitbox_Component"] +shape = SubResource( 2 ) + [connection signal="body_entered" from="." to="." method="_on_Projectile_body_entered"] diff --git a/src/UI_Dialog.tscn b/src/UI_Dialog.tscn index 9c73b74..354706e 100644 --- a/src/UI_Dialog.tscn +++ b/src/UI_Dialog.tscn @@ -22,7 +22,7 @@ size_flags_vertical = 0 split_offset = 1 [node name="TextureRect" type="TextureRect" parent="PanelContainer/HSplitContainer"] -margin_right = 64.0 +margin_right = 65.0 margin_bottom = 64.0 grow_vertical = 2 size_flags_vertical = 5 diff --git a/src/components/Health_Component.gd b/src/components/Health_Component.gd index fc1e548..4090114 100644 --- a/src/components/Health_Component.gd +++ b/src/components/Health_Component.gd @@ -2,7 +2,7 @@ class_name HealthComponent extends Node export var max_health: int = 0 -var health :int = 100 +onready var health :int = max_health signal health_depleted() diff --git a/src/components/Hurtbox_Component.gd b/src/components/Hurtbox_Component.gd index a797f15..7c2a198 100644 --- a/src/components/Hurtbox_Component.gd +++ b/src/components/Hurtbox_Component.gd @@ -23,7 +23,7 @@ func set_hurtbox(enabled: bool): # Switching to a new model that starts with Hitbox func on_hit(sender): - print("Received hit from: " + sender.name) + print("Received hit from: " + sender.owner.name) if hurtbox_entered_function: call_function.call_func(sender.damage_amount) diff --git a/src/enemyC/EnemyC.gd b/src/enemyC/EnemyC.gd index 2fdf35d..b0df11b 100644 --- a/src/enemyC/EnemyC.gd +++ b/src/enemyC/EnemyC.gd @@ -13,3 +13,19 @@ func _on_attack_frame_reached(state_name, animation_name, frame_number): if frame_number == 0 and animation_name == 'attack': print("I attack now!") $Hitbox_Component.set_hitbox(false) + +func enemyHit(damage): + print("oh! You got me for ", damage) + #$Hurtbox_Component.set_hurtbox(false) + $Health_Component.take_damage(damage) + if $Health_Component.health > 0: + movement_state_machine.change_state($movement_state_machine/hurt) + #yield( get_tree().create_timer(2 + $movement_state_machine/hurt.timeout_seconds), "timeout") + #$Hurtbox_Component.set_hurtbox(true) + + + +func _on_Health_Component_health_depleted(): + movement_state_machine.change_state($movement_state_machine/die) + yield( get_tree().create_timer(movement_state_machine.current_state.timeout_seconds), "timeout") + queue_free() diff --git a/src/enemyC/EnemyC.tscn b/src/enemyC/EnemyC.tscn index f847d4e..0cd1f42 100644 --- a/src/enemyC/EnemyC.tscn +++ b/src/enemyC/EnemyC.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=30 format=2] +[gd_scene load_steps=33 format=2] [ext_resource path="res://src/templates/Actor/ActorTemplate.tscn" type="PackedScene" id=1] [ext_resource path="res://src/enemyC/enemyC_movement_component.gd" type="Script" id=2] @@ -6,6 +6,9 @@ [ext_resource path="res://src/components/Hitbox_Component.tscn" type="PackedScene" id=4] [ext_resource path="res://src/components/GenericSender.tscn" type="PackedScene" id=5] [ext_resource path="res://src/enemyC/EnemyC.gd" type="Script" id=6] +[ext_resource path="res://src/components/Health_Component.tscn" type="PackedScene" id=7] +[ext_resource path="res://src/enemyC/states/hurt.gd" type="Script" id=8] +[ext_resource path="res://src/state_animated_actor.gd" type="Script" id=9] [sub_resource type="StreamTexture" id=1] load_path = "res://.import/botEnemy.png-46efd539a38730ff15fb4ddb087329c6.stex" @@ -90,7 +93,7 @@ animations = [ { "speed": 10.0 }, { "frames": [ SubResource( 7 ), SubResource( 8 ), SubResource( 9 ) ], -"loop": true, +"loop": false, "name": "death", "speed": 10.0 }, { @@ -173,6 +176,22 @@ idle_node = NodePath("../idle") [node name="move" parent="movement_state_machine" index="3"] animation_sequence = [ "walk" ] +[node name="hurt" type="Node" parent="movement_state_machine" index="4"] +script = ExtResource( 8 ) +timeout_seconds = 1.0 +move_speed = -5.0 +animation_sequence = [ "hurt" ] +idle_node = NodePath("../idle") + +[node name="die" type="Node" parent="movement_state_machine" index="5"] +script = ExtResource( 9 ) +timeout_seconds = 0.5 +move_speed = -5.0 +animation_sequence = [ "death" ] + +[node name="Hurtbox_Component" parent="." index="4"] +hurtbox_entered_function = "enemyHit" + [node name="CollisionShape2D" parent="Hurtbox_Component" index="0"] position = Vector2( -1, -2 ) shape = SubResource( 22 ) @@ -206,5 +225,9 @@ receiver_node_name = "GenericReceiver" position = Vector2( 48, 0 ) shape = SubResource( 24 ) +[node name="Health_Component" parent="." index="10" instance=ExtResource( 7 )] +max_health = 20 + [connection signal="frame_reached" from="movement_state_machine/attack" to="." method="_on_attack_frame_reached"] [connection signal="state_exited" from="movement_state_machine/attack" to="." method="_on_attack_state_exited"] +[connection signal="health_depleted" from="Health_Component" to="." method="_on_Health_Component_health_depleted"] diff --git a/src/enemyC/states/hurt.gd b/src/enemyC/states/hurt.gd new file mode 100644 index 0000000..6d8a14c --- /dev/null +++ b/src/enemyC/states/hurt.gd @@ -0,0 +1,31 @@ +extends StateAnimatedActor + +export (NodePath) var idle_node + +onready var idle_state: State = get_node(idle_node) + +func enter() -> void: + .enter() + move_component.velocity.x = 0 + #parent.set_hurtbox(false) + #TODO: Error check if timer was actually instanced + state_timeout.start() + + +func process_frame(delta: float) -> State: + if state_timeout.time_left == 0: + return idle_state + return null + + +func process_physics(delta: float) -> State: + move_component.velocity.y += gravity * delta + #parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1)) + move_component.velocity = parent.transform.x * move_speed +# if (parent.direction.x > 0): +# parent.velocity.x = 1 * move_speed +# else: +# parent.velocity.x = -1 * move_speed + move_component.velocity = parent.move_and_slide(move_component.velocity, Vector2(0, -1)) + + return null diff --git a/src/playerC/Player.tscn b/src/playerC/Player.tscn index 3ae76d7..c9fcfbf 100644 --- a/src/playerC/Player.tscn +++ b/src/playerC/Player.tscn @@ -541,6 +541,7 @@ default_color = Color( 1, 0.607843, 0, 1 ) body_entered_function = "heylookatme" [node name="Health_Component" parent="." instance=ExtResource( 16 )] +max_health = 100 [connection signal="state_exited" from="movement_state_machine/hurt" to="." method="_on_hurt_state_exited"] [connection signal="health_depleted" from="Health_Component" to="." method="_on_Health_Component_health_depleted"]