forked from JanPauldeVoor/gauntlet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameObjectFactory.java
More file actions
111 lines (87 loc) · 3.83 KB
/
Copy pathGameObjectFactory.java
File metadata and controls
111 lines (87 loc) · 3.83 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
110
111
package com.example.gauntlet;
import android.content.Context;
import android.graphics.PointF;
class GameObjectFactory {
private Context mContext;
private PointF mScreenSize;
private GameEngine mGameEngineReference;
GameObjectFactory(Context c, PointF screenSize,
GameEngine gameEngine) {
this.mContext = c;
this.mScreenSize = screenSize;
mGameEngineReference = gameEngine;
}
GameObject create(ObjectSpec spec) {
GameObject object = new GameObject();
int numComponents = spec.getComponents().length;
final float HIDDEN = -2000f;
object.setmTag(spec.getTag());
// Configure the speed relative to the screen size
float speed = spec.getSpeed();
// Configure the object size relative to screen size
PointF objectSize =
new PointF(mScreenSize.x / spec.getScale().x,
mScreenSize.y / spec.getScale().y);
// Set the location to somewhere off-screen
PointF location = new PointF(HIDDEN, HIDDEN);
object.setTransform(new Transform(speed, objectSize.x,
objectSize.y, location, mScreenSize));
// More code here next...
// Loop through and add/initialize all the components
for (int i = 0; i < numComponents; i++) {
switch (spec.getComponents()[i]) {
case "PlayerInputComponent":
object.setInput(new PlayerInputComponent
(mGameEngineReference));
break;
case "StdGraphicsComponent":
object.setGraphics(new StdGraphicsComponent(),
mContext, spec, objectSize);
break;
case "PlayerMovementComponent":
object.setMovement(new PlayerMovementComponent());
break;
case "ArrowMovementComponent":
object.setMovement(new ArrowMovementComponent());
break;
case "PlayerSpawnComponent":
object.setSpawner(new PlayerSpawnComponent());
break;
case "ArrowSpawnComponent":
object.setSpawner(new ArrowSpawnComponent());
break;
case "BackgroundGraphicsComponent":
object.setGraphics(new BackgroundGraphicsComponent(),
mContext, spec, objectSize);
break;
case "BackgroundMovementComponent":
object.setMovement(new BackgroundMovementComponent());
break;
case "BackgroundSpawnComponent":
object.setSpawner(new BackgroundSpawnComponent());
break;
case "SimpleMovementComponent":
object.setMovement(new SimpleMovementComponent());
break;
case "GhostChaseMovementComponent":
object.setMovement(
new GhostChaseMovementComponent(
mGameEngineReference));
break;
case "GhostSpawnComponent":
object.setSpawner(
new GhostSpawnComponent());
break;
default:
// Error unidentified component
break;
case "DoorSpawnComponent":
object.setSpawner(
new DoorSpawnComponent());
break;
}
}
// Return the completed GameObject to the Level class
return object;
}
}