-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
49 lines (40 loc) · 1.57 KB
/
script.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
import { Runner } from './resources/dino_game/offline.js';
window.addEventListener('load', () => {
const trexGameContainer = document.querySelector('.trex-game');
const configContainer = document.querySelector('.config-box');
const spirit1xFileInput = document.getElementById('sprite-1x');
const spirit2xFileInput = document.getElementById('sprite-2x');
// Clear the spirit file input value on load
spirit1xFileInput.value = '';
spirit2xFileInput.value = '';
let runner = new Runner(trexGameContainer);
// On keypress 'F' enable Arcade mode
document.addEventListener('keydown', event => {
if (event.key === 'f') {
runner.setArcadeMode();
// hide advance configs
configContainer.style.display = 'none';
}
});
// Handle sprite file selection and update assets
spirit1xFileInput.addEventListener('change', event => {
const file = event.target.files[0];
if (file) {
const imgUrl = URL.createObjectURL(file);
document.getElementById('offline-resources-1x').src = imgUrl;
// Destroy the existing instance and initialize game new a new spirit file
runner.destroy();
runner = new Runner(trexGameContainer);
}
});
spirit2xFileInput.addEventListener('change', event => {
const file = event.target.files[0];
if (file) {
const imgUrl = URL.createObjectURL(file);
document.getElementById('offline-resources-2x').src = imgUrl;
// Destroy the existing instance and initialize game new a new spirit file
runner.destroy();
runner = new Runner(trexGameContainer);
}
});
});