001         package com.croftsoft.apps.road;
002         
003         import java.applet.*;
004         import java.awt.*;
005         import java.awt.event.*;
006         import java.awt.geom.*;
007         import java.io.*;
008         import java.net.URL;
009         import java.util.*;
010         import javax.swing.*;
011         import javax.swing.event.*;
012    
013         import com.croftsoft.core.animation.clock.Timekeeper;
014         import com.croftsoft.core.animation.sprite.IconSprite;
015    
016         import com.croftsoft.apps.road.model.Car;
017    
018         /*********************************************************************
019         * Roadrunner Sprite.
020         *
021         * @version
022         *   2003-11-09
023         * @since
024         *   2003-08-05
025         * @author
026         *   <a href="https://www.croftsoft.com/">David Wallace Croft</a>
027         *********************************************************************/
028    
029         public final class  RunnerSprite
030           extends IconSprite
031           implements Constants
032         //////////////////////////////////////////////////////////////////////
033         //////////////////////////////////////////////////////////////////////
034         {
035    
036         private final Car         car;
037    
038         private final Timekeeper  timekeeper;
039    
040         //
041    
042         private Point  mousePoint;
043    
044         //////////////////////////////////////////////////////////////////////
045         //////////////////////////////////////////////////////////////////////
046    
047         public  RunnerSprite (
048           Car         car,
049           Icon        runnerIcon,
050           Timekeeper  timekeeper,
051           Component   component )
052         //////////////////////////////////////////////////////////////////////
053         {
054           super ( runnerIcon );
055    
056           this.car = car;
057    
058           this.timekeeper = timekeeper;
059    
060           // initialize mouse input
061    
062           component.addMouseMotionListener (
063             new MouseMotionAdapter ( )
064             {
065               public void  mouseMoved ( MouseEvent  mouseEvent )
066               {
067                 mousePoint = mouseEvent.getPoint ( );
068               }
069             } );
070    
071           component.addMouseListener (
072             new MouseAdapter ( )
073             {
074               public void  mouseExited ( MouseEvent  mouseEvent )
075               {
076                 mousePoint = null;
077               }
078             } );
079         }
080    
081         //////////////////////////////////////////////////////////////////////
082         //////////////////////////////////////////////////////////////////////
083    
084         public void  update ( JComponent  component )
085         //////////////////////////////////////////////////////////////////////
086         {
087           if ( mousePoint != null )
088           {
089             car.setDestinationPoint ( mousePoint );
090    
091             mousePoint = null;
092           }
093    
094           double  timeDelta = timekeeper.getTimeDelta ( );
095    
096           car.update ( timeDelta );
097    
098           x = car.getCenterX ( );
099    
100           y = car.getCenterY ( );
101         }
102    
103         //////////////////////////////////////////////////////////////////////
104         //////////////////////////////////////////////////////////////////////
105         }