fixed pausing

added code to make the drops delete themselves on exit_tree
changed spawner "remove_drop" method to just remove
master
Zac 4 years ago
parent 222fde443b
commit 55de929ded
  1. 7
      scripts/MainMenu.gd
  2. 7
      scripts/rain.gd
  3. 23
      scripts/rain_spawner.gd

@ -15,6 +15,7 @@ const _OnScreen = Vector2(0, 0)
# vars
var _autoplay_mode
var _paused = true
#-------------------------------
# signals
@ -41,15 +42,15 @@ func toggle_pause():
# pauses the game
func _pause():
get_tree().set_paused(true)
_paused = true
# unpauses the game
func _unpause():
get_tree().set_paused(false)
_paused = false
# returns the current paused state
func is_paused():
return get_tree().paused
return _paused
# callback to start the game
# TODO: make this better....

@ -1,5 +1,11 @@
extends RigidBody2D
#-------------------------------
# overloaded functions
func _exit_tree():
queue_free()
#-------------------------------
# functions
@ -9,4 +15,5 @@ func scale_down(scale):
n.set_scale(new_scale)
func _on_screen_exited():
$VisibilityNotifier.disconnect("screen_exited", self, "_on_screen_exited")
get_parent().remove_drop(self)

@ -14,20 +14,22 @@ var _time_between = 0
var _cur_time = 0
var _drop_counter = 0
var _rain = preload("res://_scenes/rain.tscn")
var _should_spawn = true
#-------------------------------
# overloaded functions
func _process(delta):
_cur_time += delta
if _cur_time >= _time_between:
randomize()
_time_between = randf() * _MaxTimeBetween
_cur_time = 0
if _should_spawn:
_cur_time += delta
if _cur_time >= _time_between:
randomize()
_time_between = randf() * _MaxTimeBetween
_cur_time = 0
if _drop_counter < GameState.MaxDrops:
_spawn_rain()
if _drop_counter < GameState.MaxDrops:
_spawn_rain()
#-------------------------------
# functions
@ -56,7 +58,8 @@ func _spawn_rain():
add_child(r)
_drop_counter += 1
# removes a drop as a child, decrements the counter
# and deletes the drop
func remove_drop(obj):
_drop_counter -= 1
remove_child(obj)
obj.queue_free()
remove_child(obj)
Loading…
Cancel
Save