Game Development Reference
In-Depth Information
The mini-map class
Mini-map shows where the ship is along the racetrack. In the implementation, we
represent our own ship in red and all others in blue. The mini-map implementation
is quite simple.
The mini-map appears at the top of the screen during the race. The complete listing
is shown below:
package race.game
{
import flash.display.Sprite;
import pulseui.util.Map;
import race.game.SpaceShip;
public class MiniMap extends Sprite
{
// The width of the mini-map
private const MAP_LEN:int = 300;
// A hash map to store all the ship sprites
private var m_map:Map = new Map();
public function MiniMap()
{
super();
// Center the display
x = (RaceTrack.SCREEN_W/2) - (MAP_LEN/2);
// Give it a gray background
graphics.beginFill(0xAAAAAA, 0.5);
graphics.drawRoundRect(0, 0, MAP_LEN, 10, 1, 1);
graphics.endFill();
}
public function update(ship:SpaceShip, remote:Boolean):void {
var s:Sprite;
s = m_map.getValue(ship.getMask());
if ( s == null ) {
// Create a sprite for each ship
s = new Sprite();
m_map.put(ship.getMask(), s);
if ( remote )
s.graphics.beginFill(0x0000FF, 0.8); //blue
else
s.graphics.beginFill(0xFF0000, 0.8); //red
s.graphics.drawEllipse(0, 0, 7, 4);
s.graphics.endFill();
 
Search WWH ::




Custom Search