-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbullet.js
49 lines (45 loc) · 1.09 KB
/
bullet.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 () {
var directionH = 17,
directionV = 15,
power = 150,
indicator = game.objects.indicator,
velocity;
function handleKeyPress (e) {
var char = String.fromCharCode(e.keyCode);
switch (char) {
case ' ': // Space
calculateVelocity();
game.objects.bullet.mesh.setLinearVelocity(velocity);
setTimeout(game.objects.bullet.newBullet, 5000);
break;
case 'a':
directionH += 1;
break;
case 'd':
directionH -= 1;
break;
case 'w':
directionV += 1;
break;
case 's':
directionV -= 1;
break;
case 'q':
power -= 10;
break;
case 'e':
power += 10;
break;
default:
}
calculateVelocity();
}
function calculateVelocity() {
if (directionV < 0) directionV = 0;
velocity = new THREE.Vector3(-power,directionV,directionH);
indicator.setDirection(velocity.clone().normalize());
indicator.setLength(power / 10);
}
calculateVelocity();
window.addEventListener("keypress", handleKeyPress);
})();