-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgame.js
More file actions
43 lines (39 loc) · 1.36 KB
/
game.js
File metadata and controls
43 lines (39 loc) · 1.36 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
var isInitiated = false;
function updateBullets() {
for(var i = 0; i < player.bullets.length; i++) {
switch(player.bullets[i].facing) {
case(1):
player.bullets[i].x += 5;
if(player.bullets[i].x > player.bullets[i].targetX) player.bullets[i].isAlive = false;
break;
case(2):
player.bullets[i].x -= 5;
if(player.bullets[i].x < player.bullets[i].targetX) player.bullets[i].isAlive = false;
break;
case(3):
player.bullets[i].y += 5;
if(player.bullets[i].y > player.bullets[i].targetY) player.bullets[i].isAlive = false;
break;
case(4):
player.bullets[i].y -= 5;
if(player.bullets[i].y < player.bullets[i].targetX) player.bullets[i].isAlive = false;
break;
default:
break;
}
}
player.bullets = player.bullets.filter(function(bullet) {
return bullet.isAlive;
});
}
function gameUpdate() {
if(!isInitiated) {
loadAssets();
playMusic(AudioAssets.menuMusic);
setInitPlayerPos((CANVAS_WIDTH / 2), (CANVAS_HEIGHT - 128));
initInputs();
isInitiated = true;
}
iterateClock();
updateBullets();
}