A game created for the Godot Wild Jam #21
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.5KB

  1. extends Node2D
  2. var _timer = 0.0
  3. var _level_running = true
  4. var _level_node = null
  5. func get_hours():
  6. return floor(_timer / 3600.0)
  7. func get_minutes():
  8. return floor(fmod((_timer / 60), 60.0))
  9. func get_seconds():
  10. return floor(fmod(_timer, 60.0))
  11. func load_and_play_music(src):
  12. var fn = "res://Data/Sound/Music/" + src
  13. if File.new().file_exists(fn):
  14. $Music.stream = load(fn)
  15. $Music.play()
  16. func load_level(src):
  17. _level_running = false
  18. get_node("Player").hide()
  19. var lvl = get_node("lvl")
  20. if _level_node != null:
  21. lvl.remove_child(_level_node)
  22. _level_node.call_deferred("free")
  23. _level_node = null
  24. var lvlres = load("res://Data/Scenes/Levels/" + src)
  25. if lvlres:
  26. _level_node = lvlres.instance()
  27. lvl.add_child(_level_node)
  28. load_and_play_music(_level_node.get_level_music())
  29. reset()
  30. func reset():
  31. if _level_node:
  32. get_tree().paused = true
  33. var p = get_node("Player")
  34. if _level_node.has_method("get_starting_position"):
  35. p.position = _level_node.get_starting_position()
  36. else:
  37. p.position = Vector2.ZERO
  38. p.reset()
  39. p.show()
  40. _timer = 0.0
  41. get_tree().paused = false
  42. func pause(enable = true):
  43. if get_tree().paused != enable:
  44. _level_running = !enable
  45. get_tree().paused = enable
  46. func _ready():
  47. set_physics_process(true)
  48. load_level("Level_001.tscn")
  49. #var ps = get_node("Level_00/Player_Start")
  50. #get_node("Player").position = get_node("Level_TestSite").get_starting_position()
  51. #get_node("Player").show()
  52. func _physics_process(delta):
  53. if _level_running:
  54. _timer += delta
  55. func _on_PM_Quit_pressed():
  56. get_tree().quit()