-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathindex.js
More file actions
77 lines (65 loc) · 1.74 KB
/
index.js
File metadata and controls
77 lines (65 loc) · 1.74 KB
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
let screen = document.querySelector('#screen');
let cassette = document.querySelector('#cassette');
screen.style.height = innerHeight - 75 + 'px';
let canvas = document.querySelector('#canvas');
let ctx = canvas.getContext('2d');
canvas.width = 1024;
canvas.height = innerHeight - 75;
let idata = ctx.createImageData(canvas.width, canvas.height);
let buffer32 = new Uint32Array(idata.data.buffer);
let tape = new Howl({
src: ['https://cdn.jsdelivr.net/gh/ManzDev/codevember2017/assets/tape-play.mp3?1']
});
//let cursors = [];
let landed = false;
let tapeView = false;
let rocket = {
img: document.querySelector('#rocket'),
x: (1024/2 - 128),
y: -250,
speed: 2,
update: function() {
if (this.y < innerHeight - 400)
this.y = this.y + this.speed;
else {
landed = true;
enableGuardians();
}
},
render: function() {
this.img.style.top = this.y + 'px';
this.img.style.left = this.x + 'px';
}
}
function update() {
// rocket
if (!landed)
rocket.update();
rocket.render();
// noise tv
noise();
}
function loop() {
update();
requestAnimationFrame(loop);
}
loop();
function enableGuardians() {
noise = function() {};
ctx.clearRect(0, 0, canvas.width, canvas.height);
canvas.remove();
cassette.classList.add('on');
tape.play();
setTimeout(function() {
rocket.img.src = 'https://raw.githubusercontent.com/ManzDev/codevember2017/master/assets/rocket-raccoon-true.png?1';
let music = new Howl({
src: ['https://cdn.rawgit.com/ManzDev/codevember2017/master/assets/hooked.mp3'],
loop: true
}).play();
}, 2000);
}
function noise() {
let len = buffer32.length - 1;
while(len--) buffer32[len] = Math.random() < 0.85 ? 0 : -1>>0;
ctx.putImageData(idata, 0, 0);
}