diff --git a/Script.js b/Script.js index 708d1e2..e9d4c30 100644 --- a/Script.js +++ b/Script.js @@ -33,13 +33,13 @@ var playerShipImg = new Image(); playerShipImg.src = 'img/fighterShip.png' var bg0 = new Image(); -bg0.src = 'img/bg_0.png'; +bg0.src = 'img/SpritesPlanet/BlueGiant.png'; var bg1 = new Image(); -bg1.src = "img/bg_1.png"; +bg1.src = "img/bg_0.png"; var bg2 = new Image(); -bg2.src = "img/bg_2.png"; +bg2.src = "img/bg_0.png"; @@ -199,8 +199,10 @@ function clearGame() { function updateGame() { addStarField(); + planet.update(); + player1.update(); - + game.frames++; } @@ -208,6 +210,8 @@ function updateGame() { function drawGame() { + planet.draw(); + player1.draw(); enemy.draw(); @@ -319,11 +323,6 @@ class backgroundObj{ } - - -let background1 = new backgroundObj(bg0, 0, 0, game.speed*3); -let background1a = new backgroundObj(bg0, 2000, 0, game.speed*3); - let background2 = new backgroundObj(bg1, 0, 0, game.speed*2); let background2a = new backgroundObj(bg1, 2000, 0, game.speed*2); @@ -341,11 +340,6 @@ function addStarField() { background2.update(); background2a.draw(); background2a.update(); - - background1.draw(); - background1.update(); - background1a.draw(); - background1a.update(); } class Missile{ @@ -403,4 +397,37 @@ class EnemyObj { } } -let enemy = new EnemyObj(800, 200, 12); \ No newline at end of file +let enemy = new EnemyObj(800, 200, 12); + + + + +class PlanetObj { + constructor(img, x, y, width, height, speed) { + this.img = img; + this.x = x; + this.y = y; + this.width = width; + this.height = height; + this.speed = speed; + this.visible = true; + } + + draw() { + if (this.visible) { + ctx.drawImage(this.img, this.x, this.y, this.width, this.height); + } + } + + update() { + if (!this.visible) return; + + this.x -= this.speed; + + if (this.x < -this.width) { + this.visible = false; + } + } +} + +let planet = new PlanetObj(bg0, 1400, 150, 400, 400, 1);