-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEntity.java
More file actions
31 lines (25 loc) · 725 Bytes
/
Copy pathEntity.java
File metadata and controls
31 lines (25 loc) · 725 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package game;
import java.awt.Graphics2D;
import java.awt.Rectangle;
public class Entity {
private int x, y, size;
public Entity(int size) {this.size = size;}
public int getX() {return x;}
public int getY() {return y;}
public void setX(int x) {this.x = x;}
public void setY(int y) {this.y = y;}
public void setPosition(int x, int y) {
this.x = x;
this.y = y;
}
public void move(int dx, int dy) {
x += dx;
y += dy;
}
public Rectangle getBound() {return new Rectangle(x, y, size, size);}
public boolean isCollision(Entity o) {
if (o == this) return false;
return getBound().intersects(o.getBound());
}
public void render(Graphics2D g2d) { g2d.fillRect(x + 1, y + 1, size - 2, size - 2); }
}