69 lines
1.8 KiB
GDScript
69 lines
1.8 KiB
GDScript
class_name ChimneyGame extends Node3D
|
|
|
|
static var instance: ChimneyGame
|
|
|
|
@onready var santa: Santa = $SantaModel
|
|
@onready var spotScene: PackedScene = preload("res://Scenes/StuckSpot.tscn")
|
|
|
|
@export var cam: Camera3D
|
|
@export var maxStucks: int = 20
|
|
@export var minStucks: int = 10
|
|
@export var spawnChance: float = 1
|
|
@export var maxSpawnlessTime: float = 0.4
|
|
|
|
var spots: int
|
|
var spawned: int
|
|
var cleared: int
|
|
var tween: Tween
|
|
var targetHeight: float
|
|
|
|
func _enter_tree():
|
|
if (is_instance_valid(instance) && instance != null):
|
|
queue_free()
|
|
return
|
|
instance = self
|
|
|
|
func startGame() -> void:
|
|
spots = 0
|
|
spawned = 0
|
|
cleared = 0
|
|
targetHeight = 0
|
|
santa.animator.play("Idle")
|
|
spots = randi_range(minStucks, maxStucks)
|
|
spawnSpot()
|
|
|
|
func spawnSpot() -> void:
|
|
if (spawned == spots): return
|
|
var spot: StuckSpot = spotScene.instantiate()
|
|
var pos: Vector2 = Vector2(santa.position.x + randf_range(-1, 1), santa.position.z + randf_range(-1, 1)).normalized()
|
|
if (pos.x < -0.7):
|
|
pos.x += 0.3
|
|
if (pos.y >= 0): pos.y += 2
|
|
else: pos.y -= 2
|
|
if (pos.x > 0.7):
|
|
pos.x -= 0.3
|
|
if (pos.y >= 0): pos.y += 2
|
|
else: pos.y -= 2
|
|
pos = pos.normalized()
|
|
spot.clicked.connect(unstickSpot)
|
|
spot.position = Vector3(pos.x / 2.5, santa.position.y + 0.5, pos.y / 2.5)
|
|
add_child(spot)
|
|
spawned += 1
|
|
|
|
func unstickSpot() -> void:
|
|
targetHeight -= 2.0 / spots
|
|
if (tween): tween.kill()
|
|
tween = get_tree().create_tween()
|
|
tween.finished.connect(spawnSpot)
|
|
tween.tween_property(santa, "position:y", targetHeight, 0.15)
|
|
cleared += 1
|
|
if (cleared == spots):
|
|
santa.animator.play("roll")
|
|
City.instance.animator.play("fadeOut")
|
|
await City.instance.animator.animation_finished
|
|
cam.clear_current()
|
|
City.instance.animator.play_backwards("fadeOut")
|
|
City.moving = true
|
|
santa.animator.play("roll", -1, -10, true)
|
|
santa.position = Vector3(0, 0, 0)
|