-
Notifications
You must be signed in to change notification settings - Fork 1
/
GameObject.java
136 lines (117 loc) · 2.72 KB
/
GameObject.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
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
* Name: GameObjects
* Beschreibung: Explaination
*
*
*/
import java.awt.Color;
import java.util.ArrayList;
import java.util.List;
public class GameObject {
private double x;
private double y;
private double width;
private double height;
private List<Double> startSize;
private Color color;
private Color startcolor;
private boolean visible;
/**
* the GameObject constructor which is storing basic information about each GameObject.
* this information can later be used by other methods to draw these objects or do
* basic calculations with the parameters (like collision checks).
* Also it creates an ArrayList which contains the starting size for each Object (later
* used to reset it to whatever we invoked it with)
* @param x
* the x coordinate
* @param y
* the y coordinate
* @param w
* the width in pixels
* @param h
* the height in pixels
* @param color
* the color of the object
* */
public GameObject(double x, double y, double w, double h, Color color) {
this.setX(x);
this.setY(y);
this.setWidth(w);
this.setHeight(h);
this.startSize = new ArrayList<Double>() {{
add(x);
add(y);
add(w);
add(h);
}};
this.setVisible(true);
this.setColor(color);
this.startcolor = color;
}
/**
* variation of the constructor using a default color of black
* */
public GameObject(double x, double y, double w, double h) {
this(x, y, w, h, Color.BLACK);
}
/**
* the GameObjects update method
* this can be empty because we are overriding it anyways accordingly to
* what we need at the moment / in every method this is called
* */
public void update() {
}
/**
* the reset of the GameObject to its starting positions
* */
public void reset() {
this.setX(startSize.get(0));
this.setY(startSize.get(1));
this.setWidth(startSize.get(2));
this.setHeight(startSize.get(3));
this.setColor(startcolor);
this.setVisible(true);
}
/**
* getter and setter for the GameObject.
* they are returning the coordinates, width, height,
* color and a boolean to check whether the object should
* be visible or not
* */
public double getX() {
return x;
}
public void setX(double x) {
this.x = x;
}
public double getY() {
return y;
}
public void setY(double y) {
this.y = y;
}
public double getWidth() {
return width;
}
public void setWidth(double width) {
this.width = width;
}
public double getHeight() {
return height;
}
public void setHeight(double height) {
this.height = height;
}
public Color getColor() {
return color;
}
public void setColor(Color color) {
this.color = color;
}
public boolean isVisible() {
return visible;
}
public void setVisible(boolean visibile) {
this.visible = visibile;
}
}