-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
172 lines (141 loc) · 5.54 KB
/
Main.java
File metadata and controls
172 lines (141 loc) · 5.54 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
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
package mygame;
import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Geometry;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box;
import com.jme3.light.*;
import com.jme3.math.FastMath;
import com.jme3.math.Plane;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector2f;
import com.jme3.renderer.queue.RenderQueue.ShadowMode;
import com.jme3.scene.Node;
import com.jme3.scene.shape.Quad;
import com.jme3.water.SimpleWaterProcessor;
import com.jme3.input.KeyInput;
import com.jme3.input.controls.KeyTrigger;
import java.io.*;
/**
* This is the Main Class of your Game. You should only do initialization here.
* Move your Logic into AppStates or Controls
* @author normenhansen
*/
public class Main extends SimpleApplication {
protected Geometry player;
public static boolean render = false;
public static boolean renderPop = false;
public static boolean nextTurn = true;
Data data;
public CameraControl ccontrol;
public Controls moves;
public static void main(String[] args) {
Main app = new Main();
app.start();
}
@Override
public void simpleInitApp() {
AmbientLight al = new AmbientLight();
al.setColor(ColorRGBA.White.mult(0.5f));
rootNode.addLight(al);
RenderClass.initialRender();
data = new Data (17,200000,200000);
for(int i = 0;i<5;i++){
for(int j = 0;j<17;j++){
for(int k = 0;k<17;k++){
Tile t = RenderClass.tileMap[k][i][j];
Vector3f move;
if(j%2 == 0 && t.type != -1){
Spatial model = assetManager.loadModel(t.fileName);
move = new Vector3f(j*10,i*4,k*12-6);
model.move(move);
rootNode.attachChild(model);
}
else if (t.type != -1){
Spatial model = assetManager.loadModel(t.fileName);
move = new Vector3f(j*10,i*4,k*12);
model.move(move);
rootNode.attachChild(model);
}
}
}
}
flyCam.setEnabled(false);
ccontrol = new CameraControl(cam);
moves = new Controls(cam);
initKeys(); // load my custom keybinding
DirectionalLight sun = new DirectionalLight();
ColorRGBA rays = new ColorRGBA(1,1,1,1);
sun.setColor(rays);
sun.setDirection(new Vector3f(-.2f,-.2f,-.8f).normalizeLocal());
rootNode.addLight(sun);
}
@Override
public void simpleUpdate(float tpf) {
if(nextTurn){
nextTurn = false;
data.endLoop();
data.startLoop();
}
}
public void initKeys() {
// You can map one or several inputs to one named action
inputManager.addMapping("forward", new KeyTrigger(KeyInput.KEY_W));
inputManager.addMapping("back", new KeyTrigger(KeyInput.KEY_S));
inputManager.addMapping("left", new KeyTrigger(KeyInput.KEY_A));
inputManager.addMapping("right", new KeyTrigger(KeyInput.KEY_D));
inputManager.addMapping("nextTurn", new KeyTrigger(KeyInput.KEY_N));
// Add the names to the action listener.
inputManager.addListener(moves.analogListener, "forward", "back", "left", "right","nextTurn");
}
@Override
public void simpleRender(RenderManager rm) {
if(render){
for(int i = 0;i<5;i++){
for(int j = 0;j<17;j++){
for(int k = 0;k<17;k++){
Tile t = RenderClass.tileMap[k][i][j];
Vector3f move;
if(j%2 == 0 && t.type != -1){
System.out.println(t.type);
System.out.println(t.fileName);
Spatial model = assetManager.loadModel(t.fileName);
move = new Vector3f(j*10,i*4,k*12-6);
model.move(move);
rootNode.attachChild(model);
}
else if (t.type != -1){
Spatial model = assetManager.loadModel(t.fileName);
move = new Vector3f(j*10,i*4,k*12);
model.move(move);
rootNode.attachChild(model);
}
}
}
}
}
/*else {
for(int i = 0;i<5;i++){
for(int j = 0;j<17;j++){
for(int k = 0;k<17;k++){
Tile t = RenderClass.tileMap[k][i][j];
if(t.type == 2){
int d = (int)(Math.random()*1-1);
if(d == 0){
Spatial model = assetManager.loadModel(t.fileName);
Vector3f move = new Vector3f(j*10,i*4+d,k*12);
model.move(move);
rootNode.attachChild(model);
}
}
}
}
}
}
*/
render = false;
}
}