aboutsummaryrefslogtreecommitdiffstats
path: root/src/ru/olamedia/olacraft/game/Game.java
blob: 0980505e8d52fbbcad8c27f427c5c6d8fdcd58ee (plain)
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
package ru.olamedia.olacraft.game;

import com.jogamp.newt.opengl.GLWindow;

import ru.olamedia.camera.MatrixCamera;
import ru.olamedia.game.GameFrame;
import ru.olamedia.olacraft.events.GameEvent;
import ru.olamedia.olacraft.network.GameClient;
import ru.olamedia.olacraft.network.GameServer;
import ru.olamedia.olacraft.scene.GameScene;
import ru.olamedia.olacraft.world.dataProvider.AbstractChunkDataProvider;
import ru.olamedia.player.Player;

public class Game {
	public static Game instance = null;
	public static int port = 26002;
	public static boolean isServerRunning = false;
	public static GameServer server = new GameServer();
	public static GameClient client = new GameClient();
	public static Timer timer = new Timer();

	public MatrixCamera camera;

	public static int MODE_SINGLEPLAYER = 1;
	public static int MODE_MULTIPLAYER = 2;
	public static int MODE_SERVER = 4;
	@SuppressWarnings("unused")
	private int mode = 1;
	private boolean isRunning = false;
	@SuppressWarnings("unused")
	// player
	public Player player;

	// block world
	// private blockWorld;
	// live entities (including player and npcs)
	// private liveEntities;
	public Game() {
		this(MODE_SINGLEPLAYER);
	}

	public Game(int mode) {
		this.mode = mode;
		if ((MODE_MULTIPLAYER & mode) > 0) {
			if ((MODE_SERVER & mode) > 0) {
				// init server
			} else {
				// init client
			}
		}
		player = new Player();
		camera = new MatrixCamera();
		camera.attachTo(player);
		camera.setFov(90);
		camera.pack();
		// scene.registerLiveEntity(player);
	}

	public void start() {
		isRunning = true;
		GameEvent e = new GameEvent(null);
		e.setType(GameEvent.GAME_START);
		e.dispatch();
	}

	// Pause game in single mode
	public void pause() {

	}

	public void stop() {

	}

	public boolean isRunning() {
		return isRunning;
	}

	public void spawnMe(int x, int y, int z) {
		player.setLocation(x, y, z);
	}

	public void tick() {
		timer.update();

	}

	public static class Display {
		public static int getWidth() {
			return (int) GameFrame.getWidth();
		}

		public static int getHeight() {
			return (int) GameFrame.getHeight();
		}

		public static float getAspect() {
			return ((float) getWidth()) / ((float) getHeight());
		}
	}

	public float getDelta() {
		return (float) timer.getElapsedTime() / 1000;
	}

}