-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameObject.java
More file actions
37 lines (37 loc) · 1.05 KB
/
Copy pathGameObject.java
File metadata and controls
37 lines (37 loc) · 1.05 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
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.Polygon;
import java.awt.Rectangle;
abstract class GameObject {
int x;
int y;
Shape shape;
Size size;
Vector trajectory;
Rectangle hitbox;
GameObject(int x, int y, Size size) {
this.x = x;
this.y = y;
this.size = size;
hitbox = new Rectangle(x,y,size.getWidth(),size.getLength());
}
public void update() {
updateHitbox();
}
public void paint(Graphics2D g2D) {
shape = constructShape();
g2D.draw(shape);
}
void updateTrajectory() {
double xTrajectory = trajectory.getXTrajectory();
double yTrajectory = trajectory.getYTrajectory();
double speed = size.getSpeed();
//It's the int rounding that's the problem
xTrajectory = (int)(speed*xTrajectory + (xTrajectory*0.5));
yTrajectory = (int)(speed*yTrajectory + (yTrajectory*0.5));
x += xTrajectory;
y += yTrajectory;
}
abstract Shape constructShape();
abstract void updateHitbox();
}