-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameObject.pde
276 lines (236 loc) · 7.05 KB
/
GameObject.pde
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
private abstract class GameObject implements Cloneable {
private boolean isActive;
protected boolean isFreeRef;
protected float posX, posY, posX2, posY2, sizeX, sizeY, posRX, posRY, rotation;
protected float number;
protected float scale = 1.0f;
protected float alpha = 1.0f;
private int blend = BLEND;
protected color colors;
protected float colorH, colorS, colorB;
protected Map<String, State> states = new HashMap<String, State>();
//protected ArrayList<State> subStates = new ArrayList<State>();
@Override
public GameObject clone(){
GameObject object = new GameObject() {
@Override protected void concreteDraw() {};
@Override protected void adjustParameter() {};
};
try {
object = (GameObject)super.clone();
object.states = new HashMap<String, State>(this.states);
for(Entry<String, State> entry : object.states.entrySet()) {
object.addState(entry.getKey(), entry.getValue());
}
// object.subStates = new ArrayList<State>(this.subStates);
} catch (Exception e){
e.printStackTrace();
}
return object;
}
protected final boolean isActive() {
return isActive;
}
/*
protected final void setFreeRef(boolean isFreeRef) {
this.isFreeRef = isFreeRef;
adjustParameter();
}*/
protected final void setPosition(float posX, float posY) {
this.posX = posX;
this.posY = posY;
adjustParameter();
}
protected final void addPosition(float posX, float posY) {
this.posX += posX;
this.posY += posY;
adjustParameter();
}
protected final float[] getPosition() {
float[] position = {posX, posY};
return position;
}
protected final void setPosition2(float posX2, float posY2) {
this.posX2 = posX2;
this.posY2 = posY2;
adjustParameter();
}
protected final void addPosition2(float posX2, float posY2) {
this.posX2 += posX2;
this.posY2 += posY2;
adjustParameter();
}
protected final float[] getPosition2() {
float[] position2 = {posX2, posY2};
return position2;
}
protected final void setSize(float sizeX, float sizeY) {
this.sizeX = sizeX;
this.sizeY = sizeY;
adjustParameter();
}
protected final void addSize(float sizeX, float sizeY) {
this.sizeX += sizeX;
this.sizeY += sizeY;
adjustParameter();
}
protected final float[] getSize() {
float[] size = {sizeX, sizeY};
return size;
}
protected final void setScale(float scale) {
if(scale < 0.0f) {
println("Error:scale can't support under 0.0f");
this.scale = 0.0f;
}
this.scale = scale;
}
protected final void addScale(float scale) {
this.scale += scale;
if(scale < 0.0f) {
this.scale = 0.0f;
}
}
protected final float getScale() {
return scale;
}
/*
protected final void setRefPosition(float posRX, float posRY) {
this.posRX = posRX;
this.posRY = posRY;
adjustParameter();
}*/
protected final float[] getRefPosition() {
float[] refPosition = {posRX, posRY};
return refPosition;
}
protected final void setBlend(int blend) {
this.blend = blend;
}
protected final void setColor(color colors) {
this.colors = colors;
}
protected final void setColor(float colorB) {
setColor(0.0f, 0.0f , colorB);
}
protected final void setColor(float colorH, float colorS, float colorB) {
float[] colorHSB = {colorH, colorS, colorB};
for(float c : colorHSB) {
if(c > 100.0f) {
c = 100.0f;
} else if(c < 0.0f) {
c = 100.0f;
}
}
this.colorH = colorHSB[0];
this.colorS = colorHSB[1];
this.colorB = colorHSB[2];
setColor(color(colorHSB[0], colorHSB[1], colorHSB[2]));
}
protected final color getColor() {
return colors;
}
protected final float getColorB() {
return colorB;
}
protected final float[] getColorHSB() {
float[] colorHSB = {colorH, colorS, colorB};
return colorHSB;
}
protected final void setAlpha(float alpha) {
this.alpha = alpha;
alpha = constrain(alpha, 0.0f, 1.0f);
}
protected final void addAlpha(float alpha) {
this.alpha += alpha;
alpha = constrain(alpha, 0.0f, 1.0f);
}
protected final float getAlpha() {
return alpha;
}
protected final void setNumber(float number) {
this.number = number;
}
protected final void addNumber(float number) {
this.number += number;
}
protected final float getNumber() {
return number;
}
protected final void setRotation(float rotation) {
this.rotation = rotation;
rotation %= 360;
}
protected final void addRotation(float rotation) {
this.rotation += rotation;
rotation %= 360;
}
protected final float getRotation() {
return rotation;
}
protected final void addState(String name, State state) {
State cloneState = state.clone();
states.put(name, cloneState.setObject(this));
}
protected final void enableObject() {
isActive = true;
}
protected final void startState(String ... names) {
isActive = true;
for(String name : names) {
if(states.get(name) == null) {
println("Error:No such state");
return;
}
states.get(name).enter();
}
}
protected final void stopState(String ... names) {
for(String name : names) {
if(states.get(name) == null) {
println("Error:No such state");
return;
}
states.get(name).exitState();
}
}
protected final void updateState() {
if(!isActive) {
return;
}
/*if(nowState != null) {
nowState.update();
}*/
for(Entry<String, State> entry : states.entrySet()) {
entry.getValue().update();
}
/*for(State subState : subStates) {
subState.update();
}*/
}
/*
protected final void transitionState(String name) {
if(states.get(name) == null) {
println("No such state");
return;
}
nowState.dispose();
nowState = states.get(name);
nowState.start();
}*/
protected final void disableObject() {
isActive = false;
}
// 実装メソッド
protected final void drawObject() {
if(!isActive) {
return;
}
blendMode(blend);
concreteDraw();
// 座標軸とブレンドモードを戻す
blendMode(BLEND);
}
protected abstract void concreteDraw();
protected abstract void adjustParameter();
}