Skip to content

Commit

Permalink
add win state detection
Browse files Browse the repository at this point in the history
  • Loading branch information
Psypher9 committed May 1, 2023
1 parent a2bd575 commit c99ad36
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Sick_Day_Delivery/Scenes/global_state.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@

[node name="Global State" type="Node"]
script = ExtResource("1_beo4s")
enemies_destroyed = 100
colonies_destroyed = 100
enemies_max = 100
12 changes: 12 additions & 0 deletions Sick_Day_Delivery/Scripts/global_state.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ signal on_colony_count_updated (total)
signal on_enemies_destroyed (total)
signal on_colonies_destroyed (total)
signal on_game_over
signal on_game_won

@export var enemies_destroyed := 0
@export var colonies_destroyed := 0
Expand All @@ -18,6 +19,7 @@ func report_enemy_destroyed():
total_enemies -= 1
emit_signal("on_enemies_count_updated", total_enemies)
emit_signal("on_enemies_destroyed", enemies_destroyed)
try_win_game()

func report_enemy_created():
total_enemies += 1
Expand All @@ -35,6 +37,16 @@ func report_colony_destroyed():
total_colonies -= 1
emit_signal("on_colonies_destroyed", colonies_destroyed)
emit_signal("on_colony_count_updated", total_colonies)
try_win_game()

func try_win_game():
if(total_enemies == 0 &&
total_colonies == 0 &&
enemies_destroyed > 0 &&
colonies_destroyed > 0):
print("🫡🏆🎆 YOU WON! YOU WINNINGING WINNER YOU! 🫡🏆🎆")
emit_signal("on_game_won")


func reset_state():
enemies_destroyed = 0
Expand Down
4 changes: 2 additions & 2 deletions Sick_Day_Delivery/Scripts/infection_spawner.gd
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ func createColony():
spawns.shuffle()
print_debug(spawns[0].name + ": " + str(spawns[0].position))
colony.process_priority = 1
colony.position = spawns[0].position
$Colonies.add_child(colony)
colony.position = spawns[0].position
$Colonies.add_child(colony)
2 changes: 1 addition & 1 deletion Sick_Day_Delivery/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ config/features=PackedStringArray("4.0", "GL Compatibility")
boot_splash/bg_color=Color(0.0156863, 0.164706, 0.172549, 1)
boot_splash/image="res://Sprites/Pill_PlaceholderOpen.png"
boot_splash/fullsize=false
config/icon="res://icon.svg"
config/icon="res://Sprites/Pill_PlaceholderOpen.png"

[audio]

Expand Down

0 comments on commit c99ad36

Please sign in to comment.