-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainScene.cs
94 lines (70 loc) · 3.15 KB
/
MainScene.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using Godot;
using System;
public class MainScene : Node2D{
public bool started = false, paused = false;
public override void _Ready(){
started = false;
paused = false;
((Button) GetNode("Controls/Start_Stop")).Text = "Start";
((Button) GetNode("Controls/PauseButton")).Text = "Pause";
Tank IncomeSplitter = (Tank)GetNode("Tank");
Tank Surplus = (Tank)GetNode("Surplus");
Tank Transaction = (Tank)GetNode("Transaction");
Surplus.currentVol = 0.9;
Transaction.currentVol = 0.1;
flowUpdate();
}
// // Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _PhysicsProcess(float delta){
flowUpdate();
}
public void _on_Start_Stop_pressed(){
if(!started){
started = true;
paused = false;
((Button) GetNode("Controls/Start_Stop")).Text = "Reset";
GetTree().CallGroup("WaterTanks","StartStop");
}
else{
GetTree().ReloadCurrentScene();
}
}
public void _on_PauseButton_pressed(){
if(!paused){
((Button) GetNode("Controls/PauseButton")).Text = "Continue";
paused=true;
}
else{
((Button) GetNode("Controls/PauseButton")).Text = "Pause";
paused=false;
}
GetTree().CallGroup("WaterTanks","PauseButton");
}
public double slider,slider2,slider3;
public void flowUpdate(){
Tank IncomeSplitter = (Tank)GetNode("IncomeSplitter");
Tank Surplus = (Tank)GetNode("Surplus");
Tank Transaction = (Tank)GetNode("Transaction");
Pipe Consumption = (Pipe)GetNode("Consumption");
Pipe Saving = (Pipe)GetNode("Saving");
Pipe Expenditure = (Pipe)GetNode("Expenditure");
Pipe Income = (Pipe)GetNode("Income");
Consumption.ConnectPipe(IncomeSplitter,Transaction);
Saving.ConnectPipe(IncomeSplitter,Surplus);
Expenditure.ConnectPipe(Surplus,Transaction);
Income.ConnectPipe(Transaction,IncomeSplitter);
Income.SetPointPosition(3,Income.GetPointPosition(1));
Income.SetPointPosition(1,Income.GetPointPosition(0)- new Vector2(Transaction.wall_width+50,0));
Income.SetPointPosition(2,Income.GetPointPosition(3)- new Vector2(Transaction.wall_width+50,0));
((RichTextLabel)GetNode("Income/PipeName")).SetPosition((Income.GetPointPosition(1)+Income.GetPointPosition(2))/2);
Consumption.physicalMaxFlow = 5;
Saving.physicalMaxFlow = 5;
Expenditure.physicalMaxFlow = 5;
Consumption.currentMaxFlow = (double)Math.Sqrt(IncomeSplitter.currentVol/IncomeSplitter.crossArea);
Saving.currentMaxFlow = (double)Math.Sqrt(IncomeSplitter.currentVol/IncomeSplitter.crossArea);
Expenditure.currentMaxFlow = (double)Math.Sqrt(Surplus.currentVol/Surplus.crossArea);
Consumption.currentFlow = Consumption.currentMaxFlow * 0.2;
Saving.currentFlow = Saving.currentMaxFlow * slider2;
Expenditure.currentFlow = Expenditure.currentMaxFlow * slider3;
}
}