-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMainGame.js
More file actions
103 lines (77 loc) · 2.8 KB
/
MainGame.js
File metadata and controls
103 lines (77 loc) · 2.8 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
// singleton class for the main game
// a singleton class should use init() for initialization
var MainGame={
// define props here
developer: "Ludocracy III",
// the game var
game: null,
// the board var
board: null,
// the Map Selector
// mapSelector: null,
// The HUD
hud: null,
// the people var
population: null,
// singleton func to initialize
initialized: false,
init: function(g){
if(MainGame.initialized===true)
return;
// now init
MainGame.initialized=true;
// set game var
MainGame.game=g;
// Prevent default right click behavior
MainGame.game.canvas.oncontextmenu = function (e) { e.preventDefault(); }
// set population var
MainGame.population=null;
// set global var
/*global Global*/
MainGame.global=Global;
// Start the turn timer
MainGame.global.turnTimer = g.time.create(false);
MainGame.global.turnTimer.start();
// Start the game timer
MainGame.global.gameTimer = g.time.create(false);
MainGame.global.gameTimer.start();
console.log('[MainGame] init with (w,h)=('+g.width+','+g.height+')');
console.log('[MainGame] TELEMETRY IS ' + (Telemetry.live ? 'ACTIVE' : 'DEACTIVATED'));
},
// start the game
start: function(){
console.assert(MainGame.initialized);
console.log('[MainGame] start...');
// Play Music
MainGame.music = MainGame.game.add.audio('game_loop');
MainGame.music.play('', 0, 1, true); // Confusing, but should set the track to loop at full volume
//MainGame.music.loopFull(1.0);
// create board
var stage=MainGame.game.cache.getJSON('stageMain');
/*global Board*/
MainGame.board=Board.fromJSON(JSON.stringify(stage));
// Make sure board initializes with good road states
for (var i = 0; i < MainGame.board.tileCount(); i++) {
MainGame.board.at(i).updateRoadConnections();
}
/*global Population*/
MainGame.population=Population.createNew(stage.population);
/*global Hud*/
MainGame.hud = Hud.createNew();
/*global updateHomes*/
updateHomes(false);
Global.updateYearViewData();
//MainGame.global.updateFreedomUnrest();
/*global Tutorial*/
Tutorial.generate();
},
nextTurn: function(){
// MainGame.board.nextTurn();
// MainGame.population.nextTurn();
/*global CoalitionQuest*/
CoalitionQuest.generate(Global.turn, MainGame.population.highList());
// Everything is currently being handled in Global.nextTurn()
MainGame.global.nextTurn();
// TODO
},
};