-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEntity.java
65 lines (52 loc) · 1.44 KB
/
Entity.java
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package uet.oop.bomberman.entities;
import uet.oop.bomberman.graphics.IRender;
import uet.oop.bomberman.graphics.Screen;
import uet.oop.bomberman.graphics.Sprite;
import uet.oop.bomberman.level.Coordinates;
/**
* Lớp đại diện cho tất cả thực thể trong game (Bomber, Enemy, Wall, Brick,...)
*/
public abstract class Entity implements IRender {
protected double _x, _y;
protected boolean _removed = false;
protected Sprite _sprite;
/**
* Phương thức này được gọi liên tục trong vòng lặp game,
* mục đích để xử lý sự kiện và cập nhật trạng thái Entity
*/
@Override
public abstract void update();
/**
* Phương thức này được gọi liên tục trong vòng lặp game,
* mục đích để cập nhật hình ảnh của entity theo trạng thái
*/
@Override
public abstract void render(Screen screen);
public void remove() {
_removed = true;
}
public boolean isRemoved() {
return _removed;
}
public Sprite getSprite() {
return _sprite;
}
/**
* Phương thức này được gọi để xử lý khi hai entity va chạm vào nhau
* @param e
* @return
*/
public abstract boolean collide(Entity e);
public double getX() {
return _x;
}
public double getY() {
return _y;
}
public int getXTile() {
return Coordinates.pixelToTile(_x + _sprite.SIZE / 2);
}
public int getYTile() {
return Coordinates.pixelToTile(_y - _sprite.SIZE / 2);
}
}