package visual.dynamic.described;

import javax.microedition.lcdui.*;

import event.*;
import geom.*;
import visual.statik.TransformableContent;


/**
 * The Cupola in the Balloon game.
 *
 * J2ME Changes:
 *    Changed PointerListener to KeyboardListener for ease of game play
 *
 * @author  Prof. David Bernstein, James Madison University
 * @version 1.0 (J2ME)
 */
public class Cupola extends RuleBasedSprite implements KeyboardListener
{
    private double     left, top;

    /**
     * Explicit Value Constructor
     *
     * @param content     The static visual content
     * @param stageWidth  The width of the Stage
     * @param stageHeight The height of the Stage
     */
    public Cupola(TransformableContent content, 
                  double stageWidth, double stageHeight)
    {
       super(content);
       Rectangle2D        bounds;       

       bounds = content.getBounds2D(false);
       top    = (stageHeight - bounds.getHeight());
       left   = (stageWidth  - bounds.getWidth())/2.0;
    
       setLocation(left, top);
    }

    /**
     * Handle a tick event (generated by the Stage)
     *
     * @param time  The current time (which is not used)
     */
    public void handleTick(int time)
    {
       setLocation(left, top);
    }


    /**
     * Handle a "key press" event 
     * (required by KeyboardListener)
     *
     * @param key  The key
     */
    public void handleKeyPress(int key)
    {
        if (key == KeyDictionary.KEY_LEFT)
            left -= 5;
        else if (key == KeyDictionary.KEY_RIGHT)
            left += 5;
    }
}

