-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjiljil-index.html
119 lines (102 loc) · 3.29 KB
/
jiljil-index.html
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
115
116
117
118
119
<html>
<head>
<title>JiLJiL</title>
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1">
<style>
body {
background-color: #f0f0f0;
}
body,
html {
height: 100%;
margin: 0;
padding: 0
}
#canvas-container {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
min-width: 320px;
min-height: 240px;
}
}
</style>
<link id='jiljilIcon' rel="icon" href="BITMAP/1.ico"></link>
</head>
<body>
<div id="canvas-container">
<canvas id="game-canvas" style='image-rendering: pixelated; image-rendering: crisp-edges; image-rendering: -moz-crisp-edges; image-rendering: -webkit-crisp-edges;'></canvas>
</div>
<script src="jiljil.js"></script>
<script src="jiljil-ui.js"></script>
<!-- <audio src='https://raadshaikh.github.io/jiljil-js/WAVE/BGM1.wav' crossOrigin='anonymous'></audio> -->
<script>
window.scale = 1;
window.width = 320;
window.height = 240;
window.fps = 36;
const canvasContainer = document.getElementById("canvas-container");
const gameCanvas = document.getElementById("game-canvas");
gameCanvas.focus();
gameCanvas.width = scale*width;
gameCanvas.height = scale*height;
if('ontouchstart' in window){
const touchCanvas = document.createElement('canvas');
touchCanvas.id = 'touch-canvas';
touchCanvas.width = scale*width;
touchCanvas.height = scale*height;
touchCanvas.style.imageRendering = 'pixelated';
<!-- touchCanvas.style.borderStyle = 'solid'; -->
<!-- touchCanvas.style.borderWidth = '1px'; -->
canvasContainer.appendChild(touchCanvas);
}
const touchCanvas = document.getElementById('touch-canvas');
const ui = new GameUI(gameCanvas, touchCanvas);
const game = new Game();
ui.setGame(game);
setInterval(game.update.bind(game), 1000/fps);
window.keysBeingPressed = {
'ArrowLeft': false,
'ArrowRight': false,
'ArrowUp': false,
'ArrowDown': false,
'Escape': false,
' ': false,
'f': false,
'g': false,
'k': false,
'z': false
};
document.addEventListener('keyup', (e) => {
keysBeingPressed[e.key] = false;
}, true);
document.addEventListener('keydown', (e) => {
keysBeingPressed[e.key] = true;
}, true);
function getMousePosition(canvas, event) {
let rect = canvas.getBoundingClientRect();
let x = event.clientX - rect.left;
let y = event.clientY - rect.top;
return [x, y];
}
document.addEventListener('visibilitychange', function() {
if (document.visibilityState != 'visible') {
window.audioContext.suspend();
game.gameState = 'escmenu';
}
<!-- if (document.visibilityState === 'visible'){ -->
<!-- window.audioContext.resume(); -->
<!-- game.gameState = game.previousGameState; -->
<!-- } -->
});
<!-- document.addEventListener("blur", function() { --> this isn't working for some reason
<!-- test(); -->
<!-- window.audioContext.suspend(); -->
<!-- game.gameState = 'escmenu'; -->
<!-- }); -->
<!-- function test(){console.log('test');}; -->
</script>
</body>
</html>