31 lines
638 B
Java
31 lines
638 B
Java
import java.awt.Graphics;
|
|
import java.awt.Rectangle;
|
|
import javax.swing.ImageIcon;
|
|
|
|
public class Collidable extends Sprite {
|
|
int x, y, width, height;
|
|
Rectangle rect;
|
|
|
|
public Collidable(int x1, int y1, int w, int h, ImageIcon icon) {
|
|
super(icon);
|
|
x = x1;
|
|
y = y1;
|
|
width = w;
|
|
height = h;
|
|
rect = new Rectangle(x1, y1, w, h);
|
|
}
|
|
|
|
public void draw(Graphics g) {
|
|
sprite = icon.getImage();
|
|
g.drawImage(sprite, x, y, width, height, null);
|
|
}
|
|
|
|
public boolean collidesWith(Collidable other) {
|
|
return this.rect.intersects(other.rect);
|
|
}
|
|
|
|
public void onCollide(Collidable other) {
|
|
return;
|
|
}
|
|
}
|