-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgamescene.pde
115 lines (97 loc) · 2.27 KB
/
gamescene.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
class GameScene implements IScene{
Board m_board;
Player m_player;
Level m_level;
SceneManager m_director;
ControlP5 m_controlGUI;
boolean m_playing;
float m_sceneTime;
GameScene(SceneManager director, PApplet app){
if (director != null){
m_director = director;
}
if(app != null){
m_controlGUI = new ControlP5(app);
}
}
void onInit(){
m_playing = true;
m_board = new Board();
m_player = new Player();
m_player.setBoard(m_board);
loadLevel("level.json",1);
textSize(8 * g_scaleFactorX);
m_sceneTime = 0;
}
void onExit(){
}
void onResume(){
textSize(8 * g_scaleFactorX);
}
void onPause(){
m_playing = false;
}
void handleInput(int k){
if(m_level.hasEnded()){
if(m_level.didGoalReach()){
if(k == '\n'){
loadLevel("level.json",m_level.m_id+1);
m_player.m_initPoints = m_player.m_points;
}
}
else if(k == '\n'){
resetLevel();
}
if(k == ESC){
m_director.changeScene(m_director.m_scenes.get(0));
key = 0;
}
}
else{
m_player.handleInput(k);
if(k == 'e'){
m_sceneTime = 0;
m_level.m_countDown = 99;
}
}
}
void run(float dt){
}
void update(float dt){
if(m_playing){
m_level.update(dt);
m_sceneTime+=dt;
}
}
void lateUpdate(float dt){
}
void loadLevel(String filename, int l){
JSONObject obj = loadJSONObject(filename);
JSONArray levels = obj.getJSONArray("Levels");
if(!levels.isNull(l-1)){
JSONObject level = levels.getJSONObject(l-1);
m_level = new Level(l,level.getInt("countdown"),level.getInt("goal"),level.getInt("maxMoves"));
onLevelInit(level);
}
else{
m_director.addScene(new EndScene(m_director,getPApplet()));
}
}
void onLevelInit(JSONObject level){
m_level.setBoard(m_board.reuseBoard());
m_level.setBoardBackground(BACKTILES.get(level.getString("background")));
m_level.setPlayer(m_player);
m_player.setBoard(m_board);
m_player.m_moves = 0;
}
void resetLevel(){
m_level.reset();
}
void draw(){
background(0,50,0);
m_level.draw();
}
void lateDraw(){
m_level.lateDraw();
}
}