|
Features

Mars Sucks - Can Games Fly on Google Earth?
Displaying Images
The foundation of any game is drawing images on screen. Fortunately this was fairly easy to do using KML. This sample code from init.php shows how we displayed the image of the cockpit on a fixed screen location:
<Folder>
<name>Dashboard</name>
<ScreenOverlay>
<name>Dashboard</name>
<drawOrder>1</drawOrder>
<visibility>1</visibility>
<Icon>
<href>images/Mars_Sucks_Dashboard.png</href>
</Icon>
<overlayXY x="0.5" y="0" xunits="fraction" yunits="fraction" />
<screenXY x="0.5" y="12" xunits="fraction" yunits="pixels" />
<size x="1" y="250" xunits="fraction" yunits="pixels" />
</ScreenOverlay>
</Folder>
We also needed to show Martian spacecraft hovering over the planet. These would be drawn relative to locations on Earth, not screen locations. This sample code shows how we added Martians above the Earth:
First of all, a Craft object is created within display_clues.php with the information of the current alien craft.
$craft = new Craft( $craft_num, new Point(trim($lon),trim($lat),500) );
Once the craft is created, a simple test is performed within destroy.php on the current craft to see if it has been hit more than the maximum number of allowed times. This determines if the clues for this craft keep showing up or if the craft has been destroyed.
if($_SESSION['craft']['hits'] < $_SESSION['CRAFT_MAX_HITS']) {
$craft_kml .= $craft->toKML();
} else {
// count current craft as destroyed
}
Within lib.php, a Craft class is defined with the following toKML() method used to display the craft:
public function toKML() {
switch($this->hits) {
case 0: $state = "default"; break;
case 1: $state = "hitOnce"; break;
case 2: $state = "hitTwice"; break;
case 3: $state = "hitThrice"; break;
default: $state = "destroyed";
}
$kml = "<Placemark>";
$kml .= "<styleUrl>styles.xml#{$state}</styleUrl>";
$kml .= "{$this->location->toKML()}";
$kml .= "</Placemark>";
return $kml;
}
Screen Text
To display the game clues we needed to get text on to the Google Earth client screen. There was no direct way to display text so we got around this limitation by using the <ScreenOverlay> tags which are used to place images on the Google Earth screen. The workaround was to use PHP5 with the existing GD library to create images on the fly. The clues' text is extracted from a file and an image is created from the text in order to place it on the screen using the <ScreenOverlay> tags. The extensive libraries that work with PHP5 made this solution easy to implement.
|