REM/scripts/drifting/weather.gd
2026-03-26 20:37:29 -06:00

114 lines
4.2 KiB
GDScript

extends Node3D
@onready var wind_dir = self.find_child("Snow_Particles").wind_direction
@export var storm_intensity: int = 1
var prev_storm_intensity: int
var random_accumulation
var random_blow
var numb_spots: int = 183
var numb_paths: int = 18
var final_score: float = 0.0
var snow_on_path: float = 0
var spots_on_paths: float = 0
var end_message: String = "Thank you for playing my game!"
var time_left: float
func _ready() -> void:
time_left = self.find_child("Game_Over").get_time_left() / self.find_child("Game_Over").wait_time
random_accumulation = [randi_range(1,numb_spots), randi_range(1,numb_spots), randi_range(1,numb_spots), randi_range(1,numb_spots)]
random_blow = [randi_range(1,numb_spots), randi_range(1,numb_spots), randi_range(1,numb_spots), randi_range(1,numb_spots)]
##Set previous storm intensity to match starting storm intensity
prev_storm_intensity = storm_intensity
func _process(_delta: float) -> void:
## Ratio of time left in game
time_left = self.find_child("Game_Over").get_time_left() / self.find_child("Game_Over").wait_time
##Intensify the storm as game time goes on
if time_left <= 0.66 and time_left > 0.33:
storm_intensity = 2
elif time_left <= 0.33:
storm_intensity = 3
print(self.find_child("Snow_Accumulation_Timer").wait_time)
##Make the sky darker over time
#print(self.find_child("Game_Over").get_time_left())
#print(self.find_child("WorldEnvironment").environment.background_energy_multiplier)
self.find_child("WorldEnvironment").environment.background_energy_multiplier = self.find_child("Game_Over").get_time_left() / self.find_child("Game_Over").wait_time
##Update timer to add snow more frequently as storm intensifies
if storm_intensity != prev_storm_intensity:
match storm_intensity:
1:
self.find_child("Snow_Accumulation_Timer").wait_time = 7
self.find_child("Snow_Particles").amount = 66666
2:
self.find_child("Snow_Accumulation_Timer").wait_time = 5
self.find_child("Snow_Particles").amount = 133333
3:
self.find_child("Snow_Accumulation_Timer").wait_time = 3
self.find_child("Snow_Particles").amount = 200000
prev_storm_intensity = storm_intensity
func _on_snow_accumulation_timer_timeout():
##Accumulate snow at random spot
for n in range(0,4):
if self.find_child("Snow_Spot" + str(random_accumulation[n])).snow_amount < 3:
self.find_child("Snow_Spot" + str(random_accumulation[n])).snow_amount += 1
##Rerandomize snow spots to accumulate
random_accumulation = [randi_range(1,numb_spots), randi_range(1,numb_spots), randi_range(1,numb_spots), randi_range(1,numb_spots)]
##Blow around random snow from spots based on wind direction
for n in range(0,4):
self.find_child("Snow_Spot" + str(random_blow[n])).blow_snow()
##Rerandomize snow spots to blow snow off of
random_blow = [randi_range(1,numb_spots), randi_range(1,numb_spots), randi_range(1,numb_spots), randi_range(1,numb_spots)]
##Change wind direction
self.find_child("Snow_Particles").wind_direction = randi_range(0,3)
func _on_game_over_timeout() -> void:
print("Game Over Man")
##Get the final total amount of snow on the paths
for n in range(1, numb_paths + 1):
snow_on_path += self.find_child("Path" + str(n)).find_child("Path_Area").snowtal
spots_on_paths += self.find_child("Path" + str(n)).find_child("Path_Area").spots
final_score = snapped(100 - (snow_on_path / (3 * spots_on_paths)) * 100, 0.01)
##Print final score
print("snow on path: " + str(snow_on_path))
print("spots on paths: " + str(spots_on_paths))
print("Final Score: " + str(final_score) + "% Clear")
if final_score > 70:
end_message = "Friend: Great job clearing the paths! Getting to the cabin was easy!"
elif final_score > 40:
end_message = "Friend: That storm out there is crazy! It took me a little bit to get to the cabin. Thank you for clearing the paths!"
else:
end_message = "Friend: I had a hard time getting here. But I know you did your best clearing the paths!"
print(end_message)
Global.message = end_message
Global.final_score = "Path Cleared: " + str(final_score) + "%"
##Reset the score metrics
snow_on_path = 0
spots_on_paths = 0
final_score = 0.0
##End the Game
get_tree().change_scene_to_file.call_deferred("res://scenes/levels/drifting/drifting_game_over.tscn")