Gamasutra.com - Mars Sucks - Can Games Fly on Google Earth?
It's free to join Gamasutra!|Have a question? Want to know who runs this site? Here you go.|Targeting the game development market with your product or service? Get info on advertising here.||For altering your contact information or changing email subscription preferences.
Registered members can log in here.Back to the home page.

Search articles, jobs, buyers guide, and more.

By Omar Rodrigues
[Author's Bio]
Mike MacPherson
[Author's Bio]
and Scott Crabtree
[Author's Bio]
Gamasutra
December 21, 2006

Mars Sucks - Can Games Fly on Google Earth?

arrowrightPage One
arrowrightPage Two
arrowrightPage Three
arrowrightPage Four




Latest Letters to the Editor:
Perpetual Layoffs by Alexander Brandon [09.21.2007]

Casual friendliness in MMO's by Colby Poulson [09.20.2007]

Scrum deals and 'What is Scrum?' by Tom Plunket [08.29.2007]


[Submit Letter]

[View All...]
  


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.




join | contact us | advertise | write | my profile
news | features | companies | jobs | resumes | education | product guide | projects | store



Copyright © 2006 CMP Media LLC

privacy policy
| terms of service