/* $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:`Pod.java'
//
//
// DESCRIPTION
//	Pod World Object
// 
// Author
//
//	Peter Pilgrim
//	Tue May 18 23:09:23 BST 1999
// 
// RCS HEADER ``Pod.java''
// 
//	$Author$
//	$Date$
//	$Source$
//	$Revision$    $State$    $Locker$
//

package xenon.humanoid;

import java.util.Vector;
import java.awt.*;
import java.awt.image.*;

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

public class Pod extends EnemyObject
{
    public final static int	NUMBER_POD_IMAGES=1;
    public final static Color	POD_RADAR_COLOR = new Color( 255, 160, 128 );
    
    // Images of these type of world
    // Object are stored in an array
    protected static Image[]		podImages=null;



    /** magnitude velocity of pod movement */
    protected int			magnitude;
    /** the responsiveness 1=fastest and 5=slowest */ 
    protected int			response;
    
    protected int			state_counter=0;
    
    /** probability to fire a bomblet */
    protected double			bombletProbability = 0.0512;

    /** Simple Constructor take a single game object 
     * 
     * @param gameEngine the game engine
     */
    public Pod( GameEngine gameEngine ) 
    {
	super( gameEngine );
    }
    
    
    /** Constructor take a single game object 
     * 
     * @param gameEngine the game engine
     * @param wx the world x coodinate
     * @param wy the world x coodinate
     * @param magnitude the magnitude (overall speed)
     * @param response the responsive factor the lower the number 
     * the quicker the pod reacts.
     */
    public Pod( GameEngine gameEngine, 
		int wx, int wy, int magnitude, int response ) 
    {
	super( gameEngine );

	this.wx = wx;
	this.wy = wy;
	this.image_index = 0;
	this.magnitude = Math.abs(magnitude);
	this.response = response;
	setResponse( response );
	dx_vel = ( Math.random() < 0.5 ) ? this.magnitude : -this.magnitude;
	dy_vel = ( Math.random() < 0.5 ) ? 1 : -1;
	
	// Get the bounds
	width = podImages[0].getWidth(component);
	height = podImages[0].getHeight(component);
    }

    /** Gets type description type */
    public String getDescriptionType()
    {
	return ("Pod");
    }
    
    /** retrieves a default image used for placating an image of
     * the world object on the screen. For example displaying image
     * on the left of the display and the number of points scored
     * destroying this world object on the right.
     * <b>Subclassers</b> should override this methods.
     */
    public Image getDefaultImage() 
    {
	return (podImages[0]);
    }
    
    public boolean loadImages()
    {
	if (podImages == null) {

	    // Load pod images
	    podImages = new Image[NUMBER_POD_IMAGES];

	    for ( int j=0; j<NUMBER_POD_IMAGES; ++j) {
		podImages[j] = 
		    GraphicsUtils.getImageAsClassResource( 
			this, "images/pod"+j+".gif" );
	    }
	    
	    GraphicsUtils.loadImageListCompletely( component, podImages );
	}
	
	return (true);
    }

    /** Sets the response */
    public void setResponse( int newResponse )
    {
	response = newResponse;
	if (response < 0) response = 0;
	if (response > GameUtilities.RESPROW ) response = GameUtilities.RESPROW;
    }
    
    /** Gets the response */
    public int getResponse()
    {
	return (response);
    }
    
    /** Sets the magnitude */
    public void setMagnitude( int newMagnitude )
    {
	magnitude = newMagnitude;
    }
    
    /** Gets the magnitude */
    public int getMagnitude()
    {
	return (magnitude);
    }
    
    /** Sets the bomblet probability */
    public void setBombletProbability( double newValue )
    {
	bombletProbability = newValue;
    }
    
    /** Gets the bomblet probability */
    public double getBombletProbability()
    {
	return (bombletProbability);
    }
    
    /** update world object */
    public WorldObject	update()
    {
	if ( !GameUtilities.isResponsive( response, gameEngine ) )
	    return (this);
	
	wx = ( wx + dx_vel + gameEngine.world_width ) % gameEngine.world_width;
	wy += dy_vel;
	int ymin = 2;
	int ymax = gameEngine.world_height+16;
	if ( wy < ymin) {
	    wy = ymax;
	}
	else if ( wy > ymax ) {
	    wy = ymin;
	}
	
	return (this);
    }
    
    /** draw object if displayed */
    public WorldObject	drawObject( Graphics g ) 
    {
	if ( isVisible() ) {
	    
	    translateWorldToScreen();
	    
	    if ( isViewable() )
		g.drawImage( podImages[image_index], scrx, scry, component );


	    if ( GameUtilities.isResponsive( response, gameEngine ) )
		image_index = (image_index+1) % NUMBER_POD_IMAGES;
	}

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

    /** Gets the points score for this world object */
    public int getPointsScored()
    {
	return (1000);
    }
    
    /** Get the radar color for this world object */
    public Color  getRadarColor()
    {
	return POD_RADAR_COLOR;
    }

}

// fini
