Skip to content

Commit

Permalink
fixed signals and timer
Browse files Browse the repository at this point in the history
  • Loading branch information
Micael006 committed Jul 9, 2023
1 parent a9829f6 commit 9ed39da
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Components/health_component.gd
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ signal health_changed_r(health : float)
cur_health = 0.0
emit_signal("death")
emit_signal("health_changed_a",cur_health)
emit_signal("health_changed_a",cur_health/max_health)
emit_signal("health_changed_r",cur_health/max_health)

func damage(ammount : float):
cur_health -= ammount
Expand Down
9 changes: 7 additions & 2 deletions Levels/level1.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ texture = ExtResource("1_ttw4w")

[node name="ControlableLog" parent="." instance=ExtResource("2_s23q5")]

[node name="HealthComponent" parent="ControlableLog" index="2"]
max_health = 50.0
cur_health = 50.0

[node name="Axe" parent="ControlableLog" instance=ExtResource("4_7amhu")]
position = Vector2(3, -113)
rotation = 1.74533
Expand All @@ -37,7 +41,8 @@ monitoring = false

[node name="KnifeSpawner" parent="." instance=ExtResource("3_7qehu")]
knives = Array[PackedScene]([ExtResource("6_wmavp"), ExtResource("4_pkscq"), ExtResource("6_emabd"), ExtResource("6_07jcx"), ExtResource("6_iiakj"), ExtResource("6_4i1hi"), ExtResource("6_c2d6i"), ExtResource("6_bpaxc"), ExtResource("6_y8onp"), ExtResource("6_qri2c"), ExtResource("6_o0n02")])
positions = Array[Vector2]([Vector2(0, 1)])
types = Array[int]([0])
positions = Array[Vector2]([Vector2(0, 1), Vector2(0, 2)])
types = Array[int]([0, 3])

[editable path="ControlableLog"]
[editable path="ControlableLog/Axe"]
2 changes: 2 additions & 0 deletions Prefabs/controlable_log.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ health = NodePath("../HealthComponent")
[node name="CollisionShape2D" type="CollisionShape2D" parent="HitboxComponent"]
z_index = 1
shape = SubResource("CircleShape2D_revv6")

[connection signal="area_entered" from="HitboxComponent" to="HitboxComponent" method="_on_area_entered"]
9 changes: 8 additions & 1 deletion Scripts/KnifeSpawner.gd
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ extends Node2D
#@export var knife_scene: PackedScene = preload("res://Prefabs/knife.tscn")
@export var warning_scene: PackedScene = preload("res://Prefabs/warning.tscn")
@export var distance: float = 600.0
@export var spawn_time: float = 3.0

signal victory
signal score_changed(score : int)
Expand All @@ -17,11 +18,18 @@ var cur_index : int = 0
var score : int = 0

func new_game():
$MobTimer.wait_time = spawn_time
$MobTimer.start()

func _ready():
new_game()

func _physics_process(_delta):
if(cur_index <= positions.size() - 1):
return
if(get_child_count() == 1):
emit_signal("victory")
set_physics_process(false)

func _on_mob_timer_timeout():
spawn_on_circle()
Expand All @@ -43,6 +51,5 @@ func spawn_on_circle():
attack.add_child(warning)
if(cur_index == positions.size() - 1):
$MobTimer.stop()
emit_signal("victory")
cur_index += 1

5 changes: 5 additions & 0 deletions Scripts/level.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ signal health_changed(health : float)
# Called when the node enters the scene tree for the first time.
@onready var ui_scene : PackedScene = preload("res://UI/in_game_ui.tscn")

var canWin : bool = true

func _ready():
$ControlableLog/HealthComponent.connect("health_changed_r", on_health_changed)
$ControlableLog/HealthComponent.connect("death", on_game_over)
Expand All @@ -23,9 +25,12 @@ func on_score_changed(score : int):
emit_signal("score_changed", score)

func on_victory():
if(!canWin):
return
emit_signal("victory")

func on_game_over():
canWin = false
emit_signal("game_over")

func connect_ui():
Expand Down
4 changes: 1 addition & 3 deletions UI/levels.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[ext_resource type="Theme" uid="uid://b5sam0xashck5" path="res://UI/ui_default.tres" id="1_jqpsc"]
[ext_resource type="Script" path="res://UI/levels.gd" id="1_mutc8"]
[ext_resource type="PackedScene" uid="uid://dkri62q20y46i" path="res://UI/main_menu.tscn" id="2_g3jyf"]
[ext_resource type="PackedScene" uid="uid://bmbo0fggcsr5e" path="res://UI/level1.tscn" id="4_mrjmj"]
[ext_resource type="PackedScene" uid="uid://bmbo0fggcsr5e" path="res://Levels/level1.tscn" id="4_mrjmj"]
[ext_resource type="Texture2D" uid="uid://c311p8qlyy43p" path="res://Assets/background.png" id="5_2lo4r"]

[node name="Levels" type="Control"]
Expand All @@ -16,10 +16,8 @@ grow_vertical = 2
theme = ExtResource("1_jqpsc")
script = ExtResource("1_mutc8")
go_back = ExtResource("2_g3jyf")

levels = Array[PackedScene]([ExtResource("4_mrjmj")])


[node name="TextureRect" type="TextureRect" parent="."]
layout_mode = 1
anchors_preset = 15
Expand Down

0 comments on commit 9ed39da

Please sign in to comment.