/*
Travell Perkins
6.837 Project 1
*/

import java.awt.*;
import java.awt.image.*;
import java.util.Random;

public class Sprite extends Raster { 
  int velx, vely;
  public Point location; 

  public Sprite(Image img) {
    super(img);
    int x,y;
    Random rand = new Random();
    x = (int)(Math.abs(rand.nextInt()) % 400);
    y = (int)(Math.abs(rand.nextInt()) % 400);
    location = new Point(x,y);
			
    System.out.println("Location at "+x+","+y);
    System.out.println("Size is "+width+","+height);
    do {
      velx = (int) (rand.nextFloat() * 6 - 3);
      vely = (int) (rand.nextFloat() * 6 - 3);
    } while (velx == 0 || vely == 0);
  }

  public void updatePosition() {
       location = new Point(location.x +velx, location.y + vely);
       
  }
  public void flip(int maxx, int maxy) {
    // Perform the checks
    if(location.x < 0)
      velx = Math.abs(velx);
    if(location.x + width > maxx)
      velx = - Math.abs(velx);
    if(location.y < 0)
      vely = Math.abs(vely);
    if(location.y + height > maxy)
      vely = - Math.abs(vely);
  }

  
  public boolean GotPixel(int x, int y) {
    int xrel = x-location.x,
      yrel = y-location.y;
    if ((xrel > 0) &&
	(yrel > 0) &&
	(xrel < width) &&
	(yrel < height) &&
	(pixel[yrel*width+xrel] < 8388607)) {  //alpha channel is zero
      return(true);
    }
    return(false);
  }
}
      
      

 
  
	
  
  
