-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.coffee
73 lines (61 loc) · 2.44 KB
/
index.coffee
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
# This file initializes data for the game.
# Different "scenes" are included at the bottom of the file.
# For info on how the scenes work see the relevant gameState file.
#
# The game object itself is initialized in game.coffee.
require('phaser')
# show warning before navigating from the page
window.onbeforeunload = () ->
return 'You will lose your progress!'
window.fillVersionSpans = () ->
$('.version-number').text(globalData.version)
Game = require('game');
window.globalData = {
gameDir:'', # TODO: fix duplicated on gameData
baseUrl:(if location.host == '7yl4r.github.io' then '/the-oregon-trajectory/' else '/')
w: 800,
h: 600,
engineDelay: 100, # ms of delay for engine shutdown (sound only)
lastEngineFire: 0,
inMenu: false,
calcFuel: () ->
return (
globalData.game.fuel
+ globalData.stats.fuel
- globalData.stats.main_fuel*globalData.game.miningFuelExpenseThrust
- globalData.stats.secondary_fuel*globalData.game.miningFuelExpenseRotate
- globalData.stats.bullets*globalData.game.miningFuelExpenseFiringBullet
)
,
calcCredits: () ->
return globalData.game.money + globalData.stats.credits
};
window.util = {
absPath: (path) ->
# use this anywhere you need an absolute path to a file.
# pass path without preceeding / or ./
return globalData.baseUrl+path
}
$(document).ready( ()->
window.globalData.gameData = new Game()
# version number display
version = '0.0.0';
$.get(globalData.gameDir+'/package.json', {}, (data, textStatus, jqXHR)->
globalData.version = data.version
window.fillVersionSpans()
, 'json')
globalData.game = new Phaser.Game(
globalData.gameData.w,
globalData.gameData.h,
Phaser.CANVAS,
'game-container-div'
)
# set up phaser game states
globalData.game.state.add('boot', require('./gameStates/boot'))
globalData.game.state.add('mining', require('./gameStates/mining/mining'))
# globalData.game.state.add('ship-chooser', require('./gameStates/shipChooser'))
globalData.game.state.add('travel-screen', require('./gameStates/travelScreen/travelScreen'))
globalData.game.state.add('shop', require('./gameStates/shop'))
globalData.game.state.add('game-over', require('./gameStates/game-over'))
globalData.game.state.start('boot') # change this to start directly into a state for testing
)