-
Notifications
You must be signed in to change notification settings - Fork 0
/
handleinput.js
49 lines (40 loc) · 1.42 KB
/
handleinput.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
function handleInput(dt) {
// var playerRoadSpeed = 5;
if(input.isDown('DOWN') || input.isDown('s')) {
increaseSpeed(false, 0.5);
}
if(input.isDown('UP') || input.isDown('w')) {
increaseSpeed(true, 0.5);
}
if(input.isDown('LEFT') || input.isDown('a')) {
// player.pos[0] -= playerSpeed * 2 * dt;
player.pos[0] -= 10;
}
if(input.isDown('RIGHT') || input.isDown('d')) {
// player.pos[0] += playerSpeed * 2 * dt;
player.pos[0] += 10;
}
document.addEventListener('click', function () {
player.pos[0] += 10;
});
document.addEventListener('dblclick', function () {
// alert("yy");
player.pos[0] -= 10;
});
if(input.isDown('SPACE') &&
!isGameOver &&
Date.now() - lastFire > 100) {
var x = player.pos[0] + player.sprite.size[0] / 2;
var y = player.pos[1] + player.sprite.size[1] / 2;
bullets.push({ pos: [x, y],
dir: 'forward',
sprite: new Sprite('./sprites.png', [0, 39], [18, 8]) });
bullets.push({ pos: [x, y],
dir: 'up',
sprite: new Sprite('./sprites.png', [0, 50], [9, 5]) });
bullets.push({ pos: [x, y],
dir: 'down',
sprite: new Sprite('./sprites.png', [0, 60], [9, 5]) });
lastFire = Date.now();
}
}