JS Update
This commit is contained in:
parent
38795f7ac9
commit
6a9a7b8556
35
Script.js
35
Script.js
@ -39,7 +39,7 @@ var bg2 = new Image();
|
||||
bg2.src = "img/bg_2.png";
|
||||
|
||||
|
||||
|
||||
var missilesArray = [];
|
||||
|
||||
|
||||
window.onload = function () {
|
||||
@ -71,7 +71,7 @@ function keyDownPressed(e) {
|
||||
|
||||
if (e.keyCode == 32) {
|
||||
keys.fire = true;
|
||||
alert("fire");
|
||||
missilesArray.push(new Missile(player1.x + 120, player1.y + 50, 'white', 12));
|
||||
}
|
||||
}
|
||||
|
||||
@ -113,6 +113,14 @@ function drawGame() {
|
||||
|
||||
player1.draw();
|
||||
|
||||
for(var i = 0; i < missilesArray.length; i++){
|
||||
var m = missilesArray[i];
|
||||
m.draw();
|
||||
m.update();
|
||||
}
|
||||
|
||||
|
||||
|
||||
drawNewText('Score: ' +player1.score, 30, 610, 'white');
|
||||
drawNewText('Player Lives: ' +player1.lives, 1100, 610, 'white');
|
||||
}
|
||||
@ -237,4 +245,27 @@ function addStarField() {
|
||||
background1.update();
|
||||
background1a.draw();
|
||||
background1a.update();
|
||||
}
|
||||
|
||||
class Missile{
|
||||
constructor(x, y, color, speed){
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = 3;
|
||||
this.height = 10;
|
||||
this.color = color;
|
||||
this.speed = speed;
|
||||
}
|
||||
|
||||
draw(){
|
||||
ctx.save();
|
||||
ctx.fillStyle = this.color;
|
||||
ctx.fillRect(this.x, this.y, this.width, this.height);
|
||||
ctx.fill();
|
||||
ctx.restore();
|
||||
}
|
||||
|
||||
update(){
|
||||
this.x += this.speed
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user