From 8a47c8f64f2a8a509053548c2ea7441948e082c4 Mon Sep 17 00:00:00 2001 From: Ententerminator Date: Mon, 27 Jan 2020 17:54:28 +0100 Subject: [PATCH] sun upper & sun downer --- Characters/Player/Player.tscn | 4 +- Characters/Player/UI/UI.gd | 6 +-- Global/Daytime.gd | 3 +- Global/Environment.gd | 73 +++++++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 6 deletions(-) create mode 100644 Global/Environment.gd diff --git a/Characters/Player/Player.tscn b/Characters/Player/Player.tscn index cb160aa..224ab07 100644 --- a/Characters/Player/Player.tscn +++ b/Characters/Player/Player.tscn @@ -175,7 +175,7 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.0461721, 1.84617, 0 ) script = ExtResource( 2 ) [node name="LookingAt" type="RayCast" parent="Body/PillCameras"] -transform = Transform( -1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 0, 0 ) +transform = Transform( -1, 0, -8.74228e-008, 0, 1, 0, 8.74228e-008, 0, -1, 0, 0, 0 ) enabled = true cast_to = Vector3( 0, 0, 2 ) @@ -273,7 +273,7 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0 ) script = ExtResource( 11 ) [node name="Pills" parent="PillTaker" instance=ExtResource( 12 )] -transform = Transform( 0.1, 0, 0, 0, -4.37114e-09, 0.1, 0, -0.1, -4.37114e-09, 0, 0.7, 0 ) +transform = Transform( 0.1, 0, 0, 0, -4.37114e-009, 0.1, 0, -0.1, -4.37114e-009, 0, 0.7, 0 ) visible = false [editable path="HUD"] diff --git a/Characters/Player/UI/UI.gd b/Characters/Player/UI/UI.gd index 842480f..de0bf77 100644 --- a/Characters/Player/UI/UI.gd +++ b/Characters/Player/UI/UI.gd @@ -42,8 +42,8 @@ func _process(_delta): _labelPillLevel.text = "curLevel: " + String(Pills.get_level()) _pillLevel.value = Pills.get_level() var val = int(Daytime.get_time()) - _labelDayTime.text = "dayTime: " + String(val) + " - %02d:%02d" % [val/60%24, val%60] - _dayTime.value = Daytime.get_time() + #_labelDayTime.text = "dayTime: " + String(val) + " - %02d:%02d" % [val/60%24, val%60] + _dayTime.value = val - _dayTimeVisual.rect_rotation = (val/_dayTime.max_value) * 360 + _dayTimeVisual.rect_rotation = ((val/_dayTime.max_value) * 180) - 90 \ No newline at end of file diff --git a/Global/Daytime.gd b/Global/Daytime.gd index 0f8789f..489181c 100644 --- a/Global/Daytime.gd +++ b/Global/Daytime.gd @@ -1,6 +1,7 @@ extends Node -const _max: int = 1440 # 24 hour + 60 mins +#const _max: int = 1440 # 24 hour + 60 mins +const _max: int = 100 const WORK_TIME = _max * 0.3 const SLEEP_TIME = _max * 0.6 diff --git a/Global/Environment.gd b/Global/Environment.gd new file mode 100644 index 0000000..5087f15 --- /dev/null +++ b/Global/Environment.gd @@ -0,0 +1,73 @@ +extends Spatial + +#const +const LONGITUDE: int = -90 # we are on equator + +const SUNRISE: Color = Color("ffdb00") +const SUNSET: Color = Color("ffdb00") +const STANDARD_SKY_TOP: Color = Color("a5d6f1") #godots standard sky top color +const SUNRISE_DEGREE: int = 15 #until this degree is sunset color +const RISE_INTERPOL: int = SUNRISE_DEGREE + 15 #until this degree, sunrise interpolates to day +const SUNSET_DEGREE: int = 170 #from this degree on is sunset color +const SET_INTERPOL: int = SUNSET_DEGREE - 15 #until this degree, day interpolates to sunset + + +#private members +var _worldEnvironment: WorldEnvironment +var _light: DirectionalLight + +var _max: float #max Daytime +var _currentTime: float + +var _degree: float #current degrees of sun & light ((currentTime/maxTime) * 180) + +#var _standardSkyHorizon: Color = Color("d6eafa") #godots standard sky horizon color +var _setSkyColor: Color #for setting current skycolor + + +# Called when the node enters the scene tree for the first time. +func _ready(): + #assign children + _worldEnvironment = get_node("WorldEnvironment") + assert(null != _worldEnvironment) + + _light = get_node("DirectionalLight") + assert(null != _light) + + #set values + _worldEnvironment.environment.background_sky.sun_longitude = LONGITUDE + + #get values (from the other side - adele) + _max = Daytime.get_max() + + +func _process(_delta): + _currentTime = Daytime.get_time() + _degree = (_currentTime/_max) * 180 + _sun_position() + _light_rotation() + _sky_light() + +#update sun position +func _sun_position(): + _worldEnvironment.environment.background_sky.sun_latitude = _degree + +#update light position to sun position +func _light_rotation(): + _light.rotation_degrees = Vector3(-(_degree), LONGITUDE, 0) + +#set light color depending on daytime +func _sky_light(): + if _degree <= SUNRISE_DEGREE: + #_worldEnvironment.environment.background_sky.sky_curve = 1 + _setSkyColor = SUNRISE + elif _degree > SUNRISE_DEGREE and _degree < RISE_INTERPOL: #interpolate colors from sunrise sky to daytime sky + _setSkyColor = SUNRISE.linear_interpolate(STANDARD_SKY_TOP, ((_degree-SUNRISE_DEGREE)/(RISE_INTERPOL-SUNRISE_DEGREE))) + elif _degree >= RISE_INTERPOL and _degree <= SET_INTERPOL: + #_worldEnvironment.environment.background_sky.sky_curve = 0.09 + _setSkyColor = STANDARD_SKY_TOP + elif _degree > SET_INTERPOL and _degree < SUNSET_DEGREE: #interpolate colors from daytime sky to sunset sky + _setSkyColor = STANDARD_SKY_TOP.linear_interpolate(SUNSET, ((_degree-SET_INTERPOL)/(SUNSET_DEGREE-SET_INTERPOL))) + elif _degree >= SUNSET_DEGREE: + _setSkyColor = SUNSET + _worldEnvironment.environment.background_sky.sky_horizon_color = _setSkyColor \ No newline at end of file