Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
FogNetwork
GitHub Repository: FogNetwork/Tsunami
Path: blob/main/public/games/files/algaes-escapade/js/main.js
1036 views
1
gamejs = require('gamejs');
2
font = require('gamejs/font');
3
4
//Preload all the required images
5
gamejs.preload([
6
'img/splash-screen.png','img/new-game.png', 'img/bg.png','img/player.png',
7
'img/blank.png','img/switch.png','img/door.png','img/goal.png',
8
'img/platform-left.png','img/platform-right.png',
9
'img/platform-middle.png', 'img/selected.png',
10
'img/scorecard-background.png','img/game-window.png',
11
'img/reset.png', 'img/star-off.png', 'img/star-on.png',
12
'img/menu-button.png', 'img/next-button.png', 'img/end.png'
13
]);
14
15
gamejs.ready(function() {
16
17
var display = gamejs.display.setMode([800, 600]);
18
19
//Ensure that all required files are included
20
include_once([
21
'lib/startMenu.js'
22
]);
23
24
var mainSurface = gamejs.display.getSurface();
25
var mainWindow = new startMenu();
26
var self = this;
27
28
// msDuration = time since last tick() call
29
var tick = function(msDuration){
30
mainSurface.fill("#FFFFFF");
31
32
//Handle user input
33
mainWindow.handleInput( mainSurface );
34
35
//Update the worlds objects
36
mainWindow.update( msDuration );
37
38
//Draw the new objects
39
mainWindow.draw( mainSurface );
40
};
41
42
//Set up listeners for the body when a scorecard is present
43
$('body').keydown(function(event){
44
//Only check key presses if the scorcard is shown
45
if ( $('#game_scorecard').is(":visible") )
46
{
47
switch ( event.keyCode )
48
{
49
//Enter and e will all move to the next level
50
case 13:
51
case 69:
52
$('#game_scorecard .nextLevel').click();
53
event.preventDefault();
54
break;
55
//Escape will quit to the menu
56
case 27:
57
$('#game_scorecard .mainMenu').click();
58
event.preventDefault();
59
break;
60
//r will reset the level
61
case 82:
62
$('#game_scorecard .resetLevel').click();
63
event.preventDefault();
64
break;
65
}
66
}
67
});
68
69
//Remove the loading bar
70
$('#preload').remove();
71
$('#gameWindow').show();
72
73
//Set up the tick function, run at 60fps
74
gamejs.time.fpsCallback(tick, self, 60);
75
});
76
77