-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweapon.js
More file actions
70 lines (61 loc) · 2.51 KB
/
weapon.js
File metadata and controls
70 lines (61 loc) · 2.51 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
export {playerShoot }
import {component} from './object.js'
var ammo = []
function playerShoot(myGameArea, ammo, ammoTimer, player) {
if (ammoTimer > 0 && ammoTimer < 30) {
ammoTimer++
} else if (ammoTimer = 30) { // If the timer between each shot goes above 30 frames then the player can shoot again
ammoTimer = 0
}
// If the player uses the right and up key then he shoots diagonaly
if ((myGameArea.keys && myGameArea.keys[39]) && (myGameArea.keys && myGameArea.keys[38])) {
if (ammoTimer == 0) {
ammo.push(new component(10, 10, "green", player.x + 29, player.y + 8));
ammoTimer = 1 // Starts the cooldown between each shot
ammo[ammo.length - 1].image = "BulletUpRight" // Displays the sprite
ammo[ammo.length - 1].speedX = 8 // Manages the bullet's movement
ammo[ammo.length - 1].speedY = -8
var audio = new Audio('sprite\\Audio\\ShootLaser.wav'); // Fire audio
audio.play();
}
}
if ((myGameArea.keys && myGameArea.keys[37]) && (myGameArea.keys && myGameArea.keys[38])) {
if (ammoTimer == 0) {
ammo.push(new component(10, 10, "green", player.x, player.y + 8));
ammoTimer = 1
ammo[ammo.length - 1].image = "BulletUpLeft"
ammo[ammo.length - 1].speedX = -8
ammo[ammo.length - 1].speedY = -8
var audio = new Audio('sprite\\Audio\\ShootLaser.wav');
audio.play();
}
}
if (myGameArea.keys && myGameArea.keys[39]) {
if (ammoTimer == 0) {
ammo.push(new component(10, 10, "green", player.x + 20, player.y + 8));
ammoTimer = 1
ammo[ammo.length - 1].image = "BulletRight"
ammo[ammo.length - 1].speedX = 8
var audio = new Audio('sprite\\Audio\\ShootLaser.wav');
audio.play();
}
}
if (myGameArea.keys && myGameArea.keys[37]) {
if (ammoTimer == 0) {
ammo.push(new component(10, 10, "green", player.x, player.y + 8));
ammoTimer = 1
ammo[ammo.length - 1].image = "BulletLeft"
ammo[ammo.length - 1].speedX = -8
var audio = new Audio('sprite\\Audio\\ShootLaser.wav');
audio.play();
}
}
return [ammo, ammoTimer]
}
function bulletvisible(ammo) {
for (var i = 0; i < ammo.length; i++) {
ammo[i].newPos() // Modification of the bullet's position
ammo[i].update() // Displays the bullet
}
return ammo
}