/* $Id$
 *
 * Copyright (c) 1999 Xenonsoft Limited. All Rights Reserved.
 *
 * This software is protected by copyright. You are hereby notified from
 * now by reading this message. This software is also the confidential 
 * and proprietary information of Xenonsoft Limited.  ("Confidential
 * Information"). 
 *
 * This software is distributed under the Xenonsoft Public end user 
 * License ("XPeL"), where the machine-readable source code is provided 
 * under the "Open Source" model.
 * For more information, please read the file "LICENSE-XPL.txt" 
 */

// File:`Bomblet.java'
//
//
// DESCRIPTION
//	Alien Bomblet
// 
// Author
//
//	Peter Pilgrim
//	Wed May 26 00:57:25 BST 1999
// 
// RCS HEADER ``Bomblet.java''
// 
//	$Author$
//	$Date$
//	$Source$
//	$Revision$    $State$    $Locker$
//

package xenon.humanoid;

import java.awt.*;
import java.awt.image.*;

import xenon.gamekit.*;				// for GameEngine, WorldObject, etc
import xenon.soundkit.*;			// for SoundEngine, PPMCAudioPlayer, etc

public class Bomblet extends WorldObject
{
    public final static int	OPTIMAL_NUMBER=15;
    
    protected int		duration=0;

    // Private object instance counter
    private static ObjectCounter objCounter = new ObjectCounter();

    protected static Image	bomblet_image=null;

    /** Constructor take a single game object 
     * @param gameEngine the game engine
     * @param wx the world x coordinate
     * @param wy the world x coordinate
     * @param dx_vel the world x velocity
     * @param dy_vel the world y velocity
     * @param duration the duration
     */
    public Bomblet( GameEngine gameEngine, 
		    int wx, int wy, int dx_vel, int dy_vel, 
		    int duration ) 
    {
	super( gameEngine );

	this.wx = wx;
	this.wy = wy;
	this.dx_vel = dx_vel;
	this.dy_vel = dy_vel;
	this.duration = duration;

	width  = bomblet_image.getWidth(component);
	height = bomblet_image.getHeight(component);

	objCounter.increment();			/* ! */
    }

    /** Gets type description type */
    public String getDescriptionType()
    {
	return ("Bomblet");
    }

    public static int getInstanceCount() 
    {
	return objCounter.getCount();
    }
    
    public boolean loadImages()
    {
	if (bomblet_image == null) {

	    bomblet_image = 
		GraphicsUtils.getImageAsClassResource( 
		    this, "images/bomblet.gif" );
	    GraphicsUtils.loadImageCompletely( component, bomblet_image );
	}

	return (true);
    }

    /** update world object */
    public WorldObject	update()
    {
	if ( duration > 0 ) {
	    --duration;
	    wx += dx_vel;
	    wy += dy_vel;
	}
	else
	    destroy();
	
	return (this);
    }
    
    /** draw object if displayed */
    public WorldObject	drawObject( Graphics g ) 
    {
	if ( isVisible() ) {
	    
	    translateWorldToScreen();
	    
	    if ( isViewable() )
		g.drawImage( bomblet_image, scrx, scry, component );
	}

	return (this);
    }
    
    /** undraw object if displayed */
    public WorldObject undrawObject( Graphics g )
    {
	return (this);
    }

    public void	destroy()
    {
	if ( !isDestroyed() ) {
	    objCounter.decrement();	/* ! */
	    super.destroy();
	}
    }
    
    /** Returns a boolean true if this object can be seen byte the radar */
    public boolean isRadarable()
    {
	return (false);
    }
    
    /** Get the radar color for this world object */
    public Color  getRadarColor()
    {
	return Color.red;
    }

}

// fini
