This entry is part 5 of 9 in the series Artificial Galaxies

So this latest incarnation incorporates some cool stuff. In the Galaxy object, I’ve built functionality so you can query the Galaxy to return only stars that are owned by a particular civilization. The usage:

That will return a table with all the star objects that belong to civilization 1 to the table ‘starModel’. Name it whatever you want, but in trying to keep my former promise of using the MVC paradigm, I’ll call it starModel. Remember the term OBJECTS. So we have the data for them, but we still need a display.

Here’s where I’ll break into my CoronaSDK background. We’ll create a bunch of display objects to represent the stars and the ship. I just have one ship for testing purposes below. The ship is the white hexagon flying from it’s starting point (the green star) to the destination (the red star).

I built some convenience code and attributes into the code for the Ship object. For the Ship object (which I think I included in the code from before, but we never used…) I added a ChangeHeading function, and a MoveForward function. These both use the mathlib library to do some heavy lifting in calculating radians to degrees and then implementing a function to move at an incremental speed to their destinations.

Check it:

We call the function every 250ms, so we tell the ship to get the heading of the starModel[3] object. Then, we tell the object to move forward along that heading. So, our screen shows the ship grooving along the path from the source star to the destination star…then it just kinda diddles around the destination star. We can build some functionality to have the ship ‘Dock” at the destination star if it gets within a certain distance, and perhaps have the star reference which ship are docked at it? We already have the Ship object with a builtin ‘DockedAt’ variable we can point to the destination star too.

See? Groovy things are a-happening! Download it here.

PS Aliens:

Series Navigation<< The Star and Planet objectsTerritory Borders >>