-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
73 lines (63 loc) · 1.89 KB
/
main.js
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
function playSound(name) {
sounds[name].play();
}
function gameLoop() {
if(fullscreen){
var s = Math.min(document.body.offsetWidth,(document.body.offsetHeight) * 4/3)
gameCanvas.width = s;
gameCanvas.height = s*3/4;
}
renderAll();
camx -= Math.sign(camx - camxgoal)*Math.pow(Math.abs(camx - camxgoal), 0.8) * 0.2;
if(Math.abs(camx - camxgoal)<1){
camx = camxgoal;
camcallback();
camcallback = function(){};
}
window.requestAnimationFrame(gameLoop);
}
function init(){
cvs = document.getElementById("gameCanvas");
ctx = cvs.getContext("2d");
cvs.addEventListener('mousedown', handleMouseEvent);
cvs.addEventListener('touchstart', handleMouseEvent);
cvs.addEventListener('mousemove', handleMouseEvent);
cvs.addEventListener('mouseup', handleMouseEvent);
cvs.addEventListener('touchend', handleMouseEvent);
document.addEventListener("keydown",handleKeyEvent);
screenScale = {x:1, y:1};
initPhysics()
loadAudio(audioFiles);
loadImages(imgNames);
}
function start(){
dlg = new IntroDialog();
sb = new StatusBar();
sb.setMoneyEnabled(false);
sb.setNextTurnEnabled(false);
camx = 0;
camxgoal = 0;
money = 1000000;
week = 0;
window.requestAnimationFrame(gameLoop);
}
function loadImages(names) {
var count = names.length;
var loaded = function() { if (--count == 0) start(); };
sprites = {};
for(var n = 0 ; n < names.length ; n++) {
var name = names[n];
sprites[name] = new Image();
sprites[name].onload = loaded;
sprites[name].src = "img/" + name + ".svg";
}
}
function loadAudio(names) {
var count = names.length;
sounds = {};
for(var n = 0 ; n < names.length ; n++) {
var name = names[n];
sounds[name] = new Audio();
sounds[name].src = "Sounds/" + name + ".wav";
}
}