import java.awt.Color; public class Ship { private Color color; private double x; private double y; private double radius; private double xVelocity; private double yVelocity; private boolean alive; public Ship( double x, double y, double radius, double xVelocity, double yVelocity ) { //TODO: Initialize all the private members //Set the color to StdDraw.BLUE //Set alive to true } public boolean isAlive() { //TODO: Complete accessor for alive } public void update( Asteroid[] asteroids, double time, double mouseX, double mouseY ) { if( mouseX > 0 && mouseX < 1 && mouseY > 0 && mouseY < 1 ) { if( mouseX > x ) xVelocity += 0.015; else xVelocity -= 0.015; if( mouseY > y ) yVelocity += 0.015; else yVelocity -= 0.015; xVelocity = Math.max( xVelocity, -0.3 ); xVelocity = Math.min( xVelocity, 0.3 ); yVelocity = Math.max( yVelocity, -0.3 ); yVelocity = Math.min( yVelocity, 0.3 ); } x = x + xVelocity*time; y = y + yVelocity*time; if( y < 0 ) y = 1; else if( y > 1 ) y = 0; if( x < 0 ) x = 1; else if( x > 1 ) x = 0; if( collides( asteroids ) ) { alive = false; color = StdDraw.BLACK; } } public boolean collides( Asteroid[] asteroids ) { //TODO: Determine if any of the asteroids collide with the ship //Loop through all the asteroids in the array //Compute the distance from each asteroid to the ship //If the distance is less than the radius of the ship + the radius of the asteroid, return true //After looking through all the asteroids (and finding none that collide), return false } public void draw() { StdDraw.setPenColor( color ); StdDraw.filledCircle( x, y, radius ); } }