import chess.Chess;
import chess.Screen;
import chess.Sprite;
import java.awt.Color;

public class PhysicsSpriteTest {
        
    public static void main(String[] args) {
        /* here you go */
        Screen greg= Chess.newScreen( 600,600 );
        
        Sprite coin= greg.newSprite("sprites/coin2.jpg");
        
        double x=50;
        double y=550;
        
        coin.setPosition( (int)x, (int)y );
        
        double vx= 2;
        double vy= -10.0;
        double angleSpeed= 1;
        
        double angle= 0;
        
        long dt= System.currentTimeMillis();
        
        while ( true ) {
            Chess.waitForNextFrame( 37. ) ;
            
            long now= System.currentTimeMillis();
            double frameRate= 1000. / ( now - dt );
            dt= now;
            
            coin.setPosition( (int)x, (int)y );
            coin.setOrientation( angle);            
                        
            x= x+vx;
            y= y+vy;
            
            greg.setColor( Color.lightGray );
            greg.drawLine( (int)(x-vx), (int)(y-vy), (int)x, (int)y );
            
            vy= vy+0.1;
            
            if ( y>550 ) {
                vy= -1.0 * vy;
                angleSpeed= vx/50. * 180 / Math.PI;
            }
            
            if ( x<50 || x>550 ) {
                vx= -1.0 * vx;
                if ( x<50 ) {
                    angleSpeed= vy/50. * 180 / Math.PI;
                } else {
                    angleSpeed= -1 * vy/50. * 180 / Math.PI;
                }
            }
            
            int mousex;
            if ( (mousex=greg.getMouseX())!=-999 ) {
                int mousey= greg.getMouseY();
                x= mousex;
                y=mousey;
            }
            
            angle= angle+angleSpeed;
            
        }
        
        /* two braces below */
    }
    
}
