87 lines
2.5 KiB
GDScript
87 lines
2.5 KiB
GDScript
extends Node3D
|
|
|
|
@onready var player: CharacterBody3D = get_tree().get_first_node_in_group("player")
|
|
@onready var player_ray: RayCast3D = get_tree().get_first_node_in_group("player_ray")
|
|
@onready var construct: Node3D = get_tree().get_first_node_in_group("Constructs")
|
|
@onready var wind_dir = self.get_parent().find_child("Snow_Particles").wind_direction
|
|
|
|
## Positive X is North
|
|
## Negative X is South
|
|
## Positive Z is East
|
|
## Negative Z is West
|
|
## North = 0, East = 1, South = 2, West = 3
|
|
|
|
var snowball_scene = preload("res://scenes/props/drifting/snowball.tscn")
|
|
var snowball_scene_2 = preload("res://scenes/props/drifting/snowball_2.tscn")
|
|
var snowball_scene_3 = preload("res://scenes/props/drifting/snowball_3.tscn")
|
|
var snowball
|
|
var wind_ray: String = "NorthRay"
|
|
|
|
var last_snow_amount: int
|
|
|
|
@export var snow_amount: int = 0
|
|
|
|
func _ready() -> void:
|
|
update_snow()
|
|
|
|
func _physics_process(_delta: float) -> void:
|
|
|
|
##TODO Fix it so snow does not accumulate when player is in the way of spot
|
|
if snow_amount < last_snow_amount or (snow_amount > last_snow_amount and self.find_child("Spot_Area").overlaps_body(player) == false):
|
|
update_snow()
|
|
|
|
func blow_snow():
|
|
|
|
## If snow spot has snow get the wind direction name
|
|
if self.snow_amount != 0:
|
|
match wind_dir:
|
|
0:
|
|
wind_ray = "North_Ray"
|
|
1:
|
|
wind_ray = "East_Ray"
|
|
2:
|
|
wind_ray = "South_Ray"
|
|
3:
|
|
wind_ray = "West_Ray"
|
|
|
|
##If north of snow pile there is something
|
|
if self.find_child(wind_ray).is_colliding():
|
|
|
|
##If thing north of snow pile is snow pile
|
|
if self.find_child(wind_ray).get_collider().is_in_group("snow_spot"):
|
|
|
|
##If snow pile to north is not full
|
|
if self.find_child(wind_ray).get_collider().get_parent().snow_amount < 3:
|
|
|
|
##Add snow to adjacent pile and subtract snow from current pile
|
|
self.find_child(wind_ray).get_collider().get_parent().snow_amount += 1
|
|
self.snow_amount -= 1
|
|
#update_snow()
|
|
|
|
func update_snow():
|
|
#print(snowball)
|
|
##Remove old snowball if one exists
|
|
if is_instance_valid(snowball):
|
|
snowball.queue_free()
|
|
snowball = null
|
|
|
|
##instance new snowball
|
|
match snow_amount:
|
|
0:
|
|
pass
|
|
1:
|
|
snowball = snowball_scene.instantiate()
|
|
2:
|
|
snowball = snowball_scene_2.instantiate()
|
|
3:
|
|
snowball = snowball_scene_3.instantiate()
|
|
|
|
##Add snowball
|
|
##TODO Fix bug where when pile is emptied throws
|
|
##ERROR: Can't add child 'Snowball' to 'Snow_Spot#', already has parent 'Snow_Spot#'
|
|
if is_instance_valid(snowball):
|
|
add_child(snowball)
|
|
|
|
##update last snow amount
|
|
last_snow_amount = snow_amount
|