From 1cf1e309eadc35d212faaf9d81d247df91bbbc62 Mon Sep 17 00:00:00 2001 From: Maikel de Vries Date: Mon, 6 Apr 2015 18:49:58 +0200 Subject: [PATCH] clean up moon and star objects --- .../Time.ocd/Moon.ocd/DefCore.txt | 4 -- .../Time.ocd/Moon.ocd/Script.c | 71 +++++++++++-------- .../Time.ocd/Stars.ocd/Script.c | 32 +++++---- 3 files changed, 62 insertions(+), 45 deletions(-) diff --git a/planet/Objects.ocd/Environment.ocd/Time.ocd/Moon.ocd/DefCore.txt b/planet/Objects.ocd/Environment.ocd/Time.ocd/Moon.ocd/DefCore.txt index 8c58d13aa..f305fe47c 100644 --- a/planet/Objects.ocd/Environment.ocd/Time.ocd/Moon.ocd/DefCore.txt +++ b/planet/Objects.ocd/Environment.ocd/Time.ocd/Moon.ocd/DefCore.txt @@ -5,7 +5,3 @@ Category=C4D_StaticBack|C4D_Background|C4D_Parallax Width=128 Height=128 Offset=-64,-64 -Vertices=1 -VertexY=0 -Mass=1 -StretchGrowth=1 diff --git a/planet/Objects.ocd/Environment.ocd/Time.ocd/Moon.ocd/Script.c b/planet/Objects.ocd/Environment.ocd/Time.ocd/Moon.ocd/Script.c index 0c146e5f9..d8d1e69bf 100644 --- a/planet/Objects.ocd/Environment.ocd/Time.ocd/Moon.ocd/Script.c +++ b/planet/Objects.ocd/Environment.ocd/Time.ocd/Moon.ocd/Script.c @@ -1,23 +1,31 @@ -/*-- Moon --*/ +/** + Moon + Moon which are shown in the night sky. +*/ local phase; + protected func Initialize() { - var alpha=0; - if(GetTime() < 300 || GetTime() > 1140) alpha=255; - SetClrModulation(RGBa(255,255,255,alpha)); + var alpha = 0; + var time = FindObject(Find_ID(Environment_Time)); + if (time && time->IsNight()) + alpha = 255; + SetClrModulation(RGBa(255, 255, 255, alpha)); + SetAction("Be"); Update(); - this["Parallaxity"] = [30,30]; + this.Parallaxity = [30, 30]; + return; } public func NextMoonPhase() { - SetMoonPhase(phase+1); + SetMoonPhase(phase + 1); } -/** @return values from 0..100, depending on the full-ness of the moon */ +// Return values from 0 to 100, depending on the full-ness of the moon public func GetMoonLightness() { return 100 - Abs(100 * phase / this.ActMap.Be.Length - 50); @@ -27,43 +35,48 @@ public func GetMoonPhase() { return phase; } -public func SetMoonPhase(int iphase) + +public func SetMoonPhase(int to_phase) { - phase = iphase % this.ActMap.Be.Length; + phase = to_phase % this.ActMap.Be.Length; Update(); + return; } -private func Update() { +private func Update() +{ SetPhase(phase); var phases = this.ActMap.Be.Length; - var x = phase - phases/2; - var height = LandscapeHeight() / (6 - (x*x)/phases); - var width = 100 + phase * (LandscapeWidth()-200) / phases; + var x = phase - phases / 2; + var height = LandscapeHeight() / (6 - (x * x) / phases); + var width = 100 + phase * (LandscapeWidth() - 200) / phases; - SetPosition(width,height); + SetPosition(width, height); + return; } -// only appears during the night +// Only appears during the night. public func IsCelestial() { return true; } // Not stored by itself because it's created by the time environment -func SaveScenarioObject() { return false; } +public func SaveScenarioObject() { return false; } +/*-- Properties --*/ + local ActMap = { - -Be = { - Prototype = Action, - Name = "Be", - Procedure = DFA_FLOAT, - Length = 8, - Delay = 0, - X = 0, - Y = 0, - Wdt = 128, - Hgt = 128, - NextAction = "Hold" -} + Be = { + Prototype = Action, + Name = "Be", + Procedure = DFA_FLOAT, + Length = 8, + Delay = 0, + X = 0, + Y = 0, + Wdt = 128, + Hgt = 128, + NextAction = "Hold" + } }; diff --git a/planet/Objects.ocd/Environment.ocd/Time.ocd/Stars.ocd/Script.c b/planet/Objects.ocd/Environment.ocd/Time.ocd/Stars.ocd/Script.c index a09bec840..e28a4bc07 100644 --- a/planet/Objects.ocd/Environment.ocd/Time.ocd/Stars.ocd/Script.c +++ b/planet/Objects.ocd/Environment.ocd/Time.ocd/Stars.ocd/Script.c @@ -1,21 +1,29 @@ -/*-- Stars --*/ +/** + Stars + Stars which are shown in the night sky. +*/ + protected func Initialize() { - var alpha=0; - if(GetTime()<300 || GetTime()>1140) alpha=255; - var g = RandomX(1,9); - if(g > 1) SetGraphics(Format("%d",g)); - SetClrModulation(RGBa(255,255,255,alpha)); + var g = RandomX(1, 9); + if (g > 1) + SetGraphics(Format("%d", g)); + + var alpha = 0; + var time = FindObject(Find_ID(Environment_Time)); + if (time && time->IsNight()) + alpha = 255; + SetClrModulation(RGBa(255, 255, 255, alpha)); SetObjectBlitMode(GFX_BLIT_Additive); + var parallax = RandomX(8,12); - this["Parallaxity"] = [parallax,parallax]; + this.Parallaxity = [parallax, parallax]; + return; } +// Only appears during the night. public func IsCelestial() { return true; } -// Not stored by itself because it's created by the time environment -// (Also, a million stars in Objects.c would suck) -func SaveScenarioObject() { return false; } - -local Name = "Stars"; +// Not stored by itself because it's created by the time environment. +public func SaveScenarioObject() { return false; }