Created
August 22, 2012 11:44
-
-
Save jake7864/3424751 to your computer and use it in GitHub Desktop.
a class similar to the Rectangle class but with a few modifications so that it can be the base class for an entity in a game
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Cords | |
{ | |
public static enum Dir {UP, DOWN, LEFT, RIGHT, STOP} | |
public static Dir dir; | |
protected double x, y, size; | |
public double getX(){return x;} | |
public double getY(){return y;} | |
public double getCenterX(){return x+size/2;} | |
public double getCenterY(){return y+size/2;} | |
public void increaseX(double num){x+=num;} | |
public void decreaseX(double num){x-=num;} | |
public void increaseY(double num){y+=num;} | |
public void decreaseY(double num){y-=num;} | |
public boolean collide(Rectangle r) | |
{ | |
if(r.intersects(new Rectangle((int)x, (int)y, (int)size, (int)size)))return true; | |
return false; | |
} | |
public boolean inRange(double x0, double y0, double range) | |
{ | |
double distance = Math.sqrt((getCenterX()-x0)*(getCenterX()-x0) + (getCenterY()-y0)*(getCenterY()-y0)); | |
if(distance<range) return true; | |
return false; | |
} | |
public Rectangle getBounds() | |
{ | |
return new Rectangle((int)x, (int)y, (int)size, (int)size); | |
} | |
public void setBounds(int x, int y, int size) | |
{ | |
this.x = x; | |
this.y = y; | |
this.size = size; | |
} | |
public void setCord(int x, int y) | |
{ | |
this.x = x; | |
this.y = y; | |
} | |
public double getSize(){return size;} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment