Skip to content

Commit 0139336

Browse files
committed
Day night cycle and energy demand
1 parent d86b853 commit 0139336

File tree

7 files changed

+84
-16
lines changed

7 files changed

+84
-16
lines changed

CanvasModulate.gd

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
extends CanvasModulate
2+
3+
const daynightdata = [[76,162,230,255,230,162],[91,100,230,255,230,100],[133,108,230,255,230,108]]
4+
5+
func _process(_delta):
6+
color = Color8(find_color(0),find_color(1),find_color(2))
7+
8+
func find_color(channel):
9+
var ltime = fmod(GlobalVars.tod, 4.0)/4
10+
var a = (int(floor(GlobalVars.tod/4)))%6
11+
var b = (int(floor((GlobalVars.tod+4)/4)))%6
12+
return int((daynightdata[channel][a] * (1 - ltime) + daynightdata[channel][b] * ltime))

TileMap.gd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const pi = 3.14159
88
const tempNoiseScale = 5
99
const altNoiseScale = 2
1010

11+
1112
func _ready():
1213
temperature.seed = randi()
1314
altitude.seed = randi()

energy.gd

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
extends Node
2+
3+
var noise = FastNoiseLite.new()
4+
5+
const data = [[70,60,75,75,75,75],[70,60,82,85,90,90],[80,80,95,90,85,95],[100,85,100,110,115,115]]
6+
var time = 0.0 #time measured in hours
7+
#var season = 0
8+
#var tod = 0.0
9+
var stod = ""
10+
var sseason = ""
11+
var sday = ""
12+
#var stime = ""
13+
#var spower = ""
14+
#var power = ""
15+
16+
const speed = 0.2 # in game hours per real second
17+
const daysInSeason = 6
18+
19+
func _process(delta):
20+
time += delta*speed
21+
#time of day
22+
GlobalVars.tod = fmod(time,24)
23+
GlobalVars.season = floor(fmod((time/24)/daysInSeason, 4)) # season should go 0 -> 1 -> 2 -> 3 -> 0 ...
24+
25+
if floor(GlobalVars.tod) == 0:
26+
stod = "12:" + str(floor((fmod(GlobalVars.tod,1) * 60)/15)*15).lpad(2,"0") + " AM"
27+
elif floor(GlobalVars.tod) < 13:
28+
stod = str(floor(GlobalVars.tod)) + ":" + str(floor((fmod(GlobalVars.tod,1) * 60)/15)*15).lpad(2,"0") + " AM"
29+
else:
30+
stod = str(floor(GlobalVars.tod)-12) + ":" + str(floor((fmod(GlobalVars.tod,1) * 60)/15)*15).lpad(2,"0") + " PM"
31+
32+
sseason = ["Spring","Summer","Fall","Winter"][GlobalVars.season]
33+
34+
sday = str(floor(time/24))
35+
36+
GlobalVars.stime = "Day " + sday + ", " + sseason + " " + stod
37+
GlobalVars.spower = str(round(get_energy(GlobalVars.season, time)*100)/100).pad_decimals(2)
38+
39+
print(GlobalVars.stime + " " + GlobalVars.spower + " kilowatts")
40+
41+
42+
func get_energy(s, t):
43+
var ltime = fmod(t, 4.0)/4
44+
var a = (int(floor(t/4)))%6
45+
var b = (int(floor((t+4)/4)))%6
46+
return data[s][a] * (1 - ltime) + data[s][b] * ltime + noise.get_noise_1d(100 * t)

global.gd

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
extends Node
2+
3+
var tod = 0
4+
var stime = ""
5+
var power = 0
6+
var spower = ""
7+
var season = 0

main scene.tscn

Lines changed: 14 additions & 3 deletions
Large diffs are not rendered by default.

place on tilemap.gd

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
extends TileMap
22
var placingvalue = 0
33

4-
5-
64

75
func _on_powerplantbutton_pressed():
86
var placingvalue = 1
@@ -21,14 +19,3 @@ func _input(event):
2119
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and event.is_pressed() == true:
2220
set_cell(0, Vector2i(floor(get_local_mouse_position()/32)), (placingvalue), Vector2i(0,0))
2321
print(ceil(get_local_mouse_position()/32))
24-
25-
26-
27-
28-
29-
30-
31-
32-
33-
34-

project.godot

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ run/main_scene="res://main scene.tscn"
1515
config/features=PackedStringArray("4.2", "Mobile")
1616
config/icon="res://icon.svg"
1717

18+
[autoload]
19+
20+
GlobalVars="*res://global.gd"
21+
1822
[display]
1923

2024
window/size/viewport_width=1920

0 commit comments

Comments
 (0)