-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGameEntity.java
More file actions
77 lines (69 loc) · 1.65 KB
/
GameEntity.java
File metadata and controls
77 lines (69 loc) · 1.65 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
import java.awt.*;
import javax.swing.*;
public abstract class GameEntity{
double x;
double y;
Image img;
double x_vel = 0;
double y_vel = 0;
int speed = 0;
double accel = 2;
double fric = 0.9;
Rectangle bounds;
public int health;
String image;
public GameEntity(int x,int y) {
this.x = x;
this.y = y;
}
public abstract void update(Space stage);
public abstract void draw(Graphics2D g);
public abstract String getImg();
public void setImage() {
// No need to init the same image over and over..
// I know speed isn't a serious issue - for the moment at least (Android?)
// but Ideally we should generate code to do this once and wrap it all
// in a static class so we don't keep initializing with every single GameEntity
img = new ImageIcon(this.getClass().getResource(getImg())).getImage();
bounds = new Rectangle(getX(),getY(),getWidth(),getHeight());
}
public double getX_vel(){
return x_vel;
}
public double getY_vel(){
return y_vel;
}
public double getx(){
return x;
}
public int getX(){
return (int)x;
}
public double gety(){
return y;
}
public int getY(){
return (int)y;
}
public Image getImage() {
return img;
}
public int getWidth() {
return img.getWidth(null);
}
public int getHeight() {
return img.getHeight(null);
}
public int getHealth() {
return health;
}
public void setX(int x) {
this.x = x;
}
public void setY(int y) {
this.y = y;
}
public void setHealth(int health) {
this.health = health;
}
}