11require " helper"
2+ require " models.moon"
23
34Planet = {}
45
@@ -7,6 +8,7 @@ Planet.new = function(x, y, radius, red, green, blue)
78 -- variables
89 local self = {}
910 local composition = {}
11+ local moons = {}
1012
1113 -- positioning
1214 local x = x or 0
@@ -32,6 +34,7 @@ Planet.new = function(x, y, radius, red, green, blue)
3234 self .getGreen = function () return green end
3335 self .getBlue = function () return blue end
3436 self .getComposition = function () return composition end
37+ self .getMoons = function () return moons end
3538
3639 -- setters
3740 self .setX = function (arg ) x = arg end
@@ -44,6 +47,7 @@ Planet.new = function(x, y, radius, red, green, blue)
4447 self .setGreen = function (arg ) green = arg end
4548 self .setBlue = function (arg ) blue = arg end
4649 self .setComposition = function (arg ) composition = arg end
50+ self .setMoons = function (arg ) moons = arg end
4751
4852 -- composition
4953 self .generate_composition = function ()
@@ -104,6 +108,22 @@ Planet.new = function(x, y, radius, red, green, blue)
104108
105109 -- generate composition
106110 self .setComposition (self .generate_composition ())
111+
112+ -- generate moons
113+ local num_moons = love .math .random (0 ,2 )
114+ for i = 1 ,num_moons do
115+ local moon = Moon .new ()
116+ moon .generate ()
117+ -- the position should match the planet
118+ moon .setX (x )
119+ moon .setY (y )
120+ -- the distance should be the radius of the planet + the radius of the moon + a bit
121+ -- but actually randum
122+ moon .setDistance (love .math .random (radius + moon .getRadius ()+ 10 ,radius + moon .getRadius ()+ 40 ))
123+ -- the radius should be a percentage of the planet radius
124+ moon .setRadius (0.25 * radius )
125+ table.insert (moons , moon )
126+ end
107127 end
108128
109129 -- primary star
0 commit comments