1 /**
2 Moon
3 Moon which are shown in the night sky.
4 */
5
6 local phase;
7
8
Initialize()9 protected func Initialize()
10 {
11 phase = 0;
12 var alpha = 0;
13 if (Time->IsNight())
14 alpha = 255;
15 SetClrModulation(RGBa(255, 255, 255, alpha));
16
17 SetAction("Be");
18 Update();
19 this.Parallaxity = [30, 30];
20 return;
21 }
22
NextMoonPhase()23 public func NextMoonPhase()
24 {
25 SetMoonPhase(phase + 1);
26 }
27
28 // Return values from 0 to 100, depending on the full-ness of the moon
GetMoonLightness()29 public func GetMoonLightness()
30 {
31 return 100 - Abs(100 * phase / this.ActMap.Be.Length - 50);
32 }
33
GetMoonPhase()34 public func GetMoonPhase()
35 {
36 return phase;
37 }
38
SetMoonPhase(int to_phase)39 public func SetMoonPhase(int to_phase)
40 {
41 phase = to_phase % this.ActMap.Be.Length;
42 Update();
43 return;
44 }
45
Update()46 private func Update()
47 {
48 SetPhase(phase);
49
50 var phases = this.ActMap.Be.Length;
51
52 var x = phase - phases / 2;
53 var height = LandscapeHeight() / (6 - (x * x) / phases);
54 var width = 100 + phase * (LandscapeWidth() - 200) / phases;
55
56 SetPosition(width, height);
57 return;
58 }
59
60 // Only appears during the night.
IsCelestial()61 public func IsCelestial() { return true; }
62
63 // Not stored by itself because it's created by the time environment
SaveScenarioObject()64 public func SaveScenarioObject() { return false; }
65
66
67 /*-- Properties --*/
68
69 local ActMap = {
70 Be = {
71 Prototype = Action,
72 Name = "Be",
73 Procedure = DFA_FLOAT,
74 Length = 8,
75 Delay = 0,
76 X = 0,
77 Y = 0,
78 Wdt = 128,
79 Hgt = 128,
80 NextAction = "Hold"
81 }
82 };
83