-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
59 lines (38 loc) · 985 Bytes
/
main.js
File metadata and controls
59 lines (38 loc) · 985 Bytes
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
// Render settings
const CANVAS_WIDTH = 192
const CANVAS_HEIGHT = 192
const BUFFER_WIDTH = 160;
const BUFFER_HEIGHT = 120;
const SPRITE_SIZE = 8;
// Game settings
const BOARD_WIDTH = 10;
const BOARD_HEIGHT = 20;
// mino type identifiers
const I_TRIMINO = 1
const L_TRIMINO = 2
const minos = []
const board = new Board(minos);
document.getElementById('testButton1')
.addEventListener('click', board.drop.bind(board))
document.getElementById('testButton2')
.addEventListener('click', board.clearLines.bind(board))
const spriteMap = {
0: [4, 0],
}
spriteMap[I_TRIMINO] = [1, 0]
spriteMap[L_TRIMINO] = [1, 1]
function update() {
board.update()
}
const state = { board }
const sprites = new SpriteSheet('sprites.png', SPRITE_SIZE, () => {
const renderer = new Renderer({
canvasId: 'canvas',
sprites,
state,
onReady: (renderer) => {
const game = new Game(state, update, renderer.render.bind(renderer));
game.start();
}
});
})