/* $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:`BonusFlyer.java'
//
//
// Description:
//	Bonus Flyer
// 
// Author:
//	Peter Pilgrim
//	Tue Jun 01 00:00:43 BST 1999
// 
// RCS HEADER ``BonusFlyer.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 BonusFlyer extends WorldObject
{
    protected int		duration=0;
    protected String		str;
    protected Font		font;
    protected int		counter=0;

    protected int []		letterWidth;
    
    /** Constructor take a single game object */
    public BonusFlyer( GameEngine gameEngine, 
		       int wx, int wy, int dx_vel, int dy_vel, 
		       String bonusMsg )
    {
	this( gameEngine, wx, wy, dx_vel, dy_vel, bonusMsg, 48 );
    }
    
    /** Constructor take a single game object */
    public BonusFlyer( GameEngine gameEngine, 
		       int wx, int wy, int dx_vel, int dy_vel, 
		       int bonus )
    {
	this( gameEngine, wx, wy, dx_vel, dy_vel, bonus, 48 );
    }
    
    /** Constructor take a single game object */
    public BonusFlyer( GameEngine gameEngine, 
		       int wx, int wy, int dx_vel, int dy_vel, 
		       String bonusMsg, int duration ) 
    {
	super( gameEngine );

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

	str = bonusMsg;
	font = new Font( "Dialog", Font.BOLD, 14 );
	int N = str.length();
	FontMetrics fm = Toolkit.getDefaultToolkit().getFontMetrics(font);
	letterWidth = new int[N];
	for (int j=0; j<N; ++j) {
	    letterWidth[j] = fm.charWidth( (char)str.charAt(j) );
	}
    }
    
    /** Constructor take a single game object */
    public BonusFlyer( GameEngine gameEngine, 
		       int wx, int wy, int dx_vel, int dy_vel, 
		       int bonusValue,
		       int duration ) 
    {
	super( gameEngine );

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


	str = Integer.toString( bonusValue );
	font = new Font( "Dialog", Font.BOLD, 14 );

	int N = str.length();
	FontMetrics fm = Toolkit.getDefaultToolkit().getFontMetrics(font);
	letterWidth = new int[N];
	for (int j=0; j<N; ++j) {
	    letterWidth[j] = fm.charWidth( (char)str.charAt(j) );
	}
	
    }

    /** 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.setFont( font );
		FontMetrics fm = g.getFontMetrics();
		int letterx=scrx, lettery=scry;
		
		if ( gameEngine.frameClock % 5 == 0 )
		    counter = (counter+1) % 4;
		
		for (int j=0; j<str.length(); ++j) {
		    char ch = str.charAt(j);
		    switch ( counter ) {
		      case 0: g.setColor( Color.yellow ) ; break;
		      case 1: g.setColor( Color.red ) ; break;
		      case 2: g.setColor( Color.magenta )  ; break;
		      case 3: g.setColor( Color.cyan ) ; break;
		    }
		    
		    g.drawString( ""+ch, letterx, lettery );
		    letterx += letterWidth[j];
		    counter = (counter+1) % 4;
		}

	    }
	}

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

    /** return true, if this object visible on the radar */ 
    public boolean isRadarable() 
    {
	return (false);
    }
    
    /** Get the radar color for this world object */
    public Color getRadarColor()
    {
	return Color.blue;
    }

}

// fini
