-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
101 lines (83 loc) · 2.47 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
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
import './style.css';
import { Application, Container, SCALE_MODES, utils } from 'pixi.js';
import Loader from './src/Loader';
import MainMenu from './src/Menus/mainMenu';
import { AdvancedBloomFilter } from '@pixi/filter-advanced-bloom';
import { CRTFilter } from '@pixi/filter-crt';
import {Howl, Howler} from 'howler'
const Setup = () => {
// Create Application
const app = new Application({
width: 256,
height: 256,
backgroundColor: 0x000000,
});
const windowWidth = window.innerWidth;
const windowHeight = window.innerHeight;
app.spriteScale = 1;
console.log(app.view.height)
// Resize app to fit window
if (windowWidth > 1024 && windowHeight > 1024) {
app.renderer.resize(1024, 1024);
app.spriteScale = 4;
} else if (windowWidth > 768 && windowHeight > 768) {
app.renderer.resize(768, 768);
app.spriteScale = 3;
} else if (windowWidth > 512 && windowHeight > 512) {
app.renderer.resize(512, 512);
app.spriteScale = 2;
} else {
app.renderer.resize(windowWidth, windowWidth);
app.spriteScale = windowWidth / 256;
}
app.isMobile = utils.isMobile.any;
app.debug = false;
app.currentScene = new Container();
app.stage.addChild(app.currentScene);
app.music = new Howl({src: ['https://assets.samsilver.ca/zombie-arcade/sounds/music.wav'], loop: true})
app.music.play()
const musicVolume = 0.045
const fadeDuration = 4000
app.musicFadeIn = () => {
app.music.fade(0, musicVolume, fadeDuration)
}
app.musicFadeOut = () => {
app.music.fade(musicVolume, 0, fadeDuration)
}
app.musicFadeIn()
app.gameoverMusic = new Howl({src: ['https://assets.samsilver.ca/zombie-arcade/sounds/gameover.wav'], volume: 0.1})
// add filter to app
app.currentScene.filters = [
new AdvancedBloomFilter({
threshold: 0.4,
bloomScale: 0.3,
brightness: 1,
blur: 1,
}),
new CRTFilter({
curvature: 1,
lineWidth: 3 / app.spriteScale,
lineContrast: 0.4,
noise: 0.1,
noiseSize: 1,
vignetting: 0.5,
vignettingAlpha: 0.1,
vignettingBlur: 0.1,
}),
];
// Append to DOM
document.querySelector('#app').appendChild(app.view);
// Load Assets
Loader(app)
.then(({sheet, scores}) => {
sheet.baseTexture.setStyle(SCALE_MODES.NEAREST);
app.spriteSheet = sheet;
app.high_scores = scores
const mainMenu = MainMenu(app);
mainMenu.loadScene();
})
.catch((err) => {
console.log(err);
});
};
Setup();