-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameObject.java
More file actions
109 lines (91 loc) · 2.26 KB
/
GameObject.java
File metadata and controls
109 lines (91 loc) · 2.26 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import java.awt.Color;
import java.awt.Image;
import java.awt.Rectangle;
public abstract class GameObject implements MovingObject {
private double speed;// 0 - 10
private double direction, // degrees or radians
// >= 0
// 10 might be a good size
health; // 0 - 100
private int x, y, size;//
private Color color;
private Image img;
private Rectangle rect = new Rectangle();
public GameObject (double speed, double direction, int size, double health, int x, int y, Color c){
this.speed = speed;
this.direction = direction;
this.size = size;
this.health = health;
this.x = x;
this.y = y;
this.color = c;
}
@Override
public void move() {
x += (int) (getSpeed()*Math.cos(direction));
y += (int) (getSpeed()*Math.sin(direction));
resetDir();
//System.out.println(direction);
gravity();
checkOffScreen();
// maybe "push" back onto the screen change direction if
// this object goes off the screen
}
public void gravity() {
// if(direction>(3*Math.PI/2)||direction<(Math.PI/2))
// direction -= Math.PI/16;
// if(direction<(3*Math.PI/2)&&direction>(Math.PI/2))
// direction += Math.PI/16;
//System.out.println("gravity");
}
public void resetDir() {
while(direction > 2*Math.PI)
direction -= 2*Math.PI;
while(direction < 0)
direction += 2*Math.PI;
}
public abstract void checkOffScreen();
public Image getImg() {
return img;
}
public void setImg(Image img) {
this.img = img;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public double getSpeed() {
return speed;
}
public void setSpeed(double speed) {
this.speed = speed;
}
public void setDirection(double direction){
this.direction = direction;
}
public int getSize(){
return size;
}
public double getDirection(){
return this.direction;
}
public void openBackgroundImage() {
// TODO Auto-generated method stub
}
@Override
public Rectangle getBoundingRect() {
return this.rect.getBounds();
}
public void setBoundingRect(int x, int y, int width, int height){
rect.setBounds(x, y, width, height);
}
}