Planet
This commit is contained in:
parent
1052bc7292
commit
bd8b83461f
57
Script.js
57
Script.js
@ -33,13 +33,13 @@ var playerShipImg = new Image();
|
|||||||
playerShipImg.src = 'img/fighterShip.png'
|
playerShipImg.src = 'img/fighterShip.png'
|
||||||
|
|
||||||
var bg0 = new Image();
|
var bg0 = new Image();
|
||||||
bg0.src = 'img/bg_0.png';
|
bg0.src = 'img/SpritesPlanet/BlueGiant.png';
|
||||||
|
|
||||||
var bg1 = new Image();
|
var bg1 = new Image();
|
||||||
bg1.src = "img/bg_1.png";
|
bg1.src = "img/bg_0.png";
|
||||||
|
|
||||||
var bg2 = new Image();
|
var bg2 = new Image();
|
||||||
bg2.src = "img/bg_2.png";
|
bg2.src = "img/bg_0.png";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -199,8 +199,10 @@ function clearGame() {
|
|||||||
function updateGame() {
|
function updateGame() {
|
||||||
|
|
||||||
addStarField();
|
addStarField();
|
||||||
|
planet.update();
|
||||||
|
|
||||||
player1.update();
|
player1.update();
|
||||||
|
|
||||||
game.frames++;
|
game.frames++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,6 +210,8 @@ function updateGame() {
|
|||||||
|
|
||||||
function drawGame() {
|
function drawGame() {
|
||||||
|
|
||||||
|
planet.draw();
|
||||||
|
|
||||||
player1.draw();
|
player1.draw();
|
||||||
|
|
||||||
enemy.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 background2 = new backgroundObj(bg1, 0, 0, game.speed*2);
|
||||||
let background2a = new backgroundObj(bg1, 2000, 0, game.speed*2);
|
let background2a = new backgroundObj(bg1, 2000, 0, game.speed*2);
|
||||||
|
|
||||||
@ -341,11 +340,6 @@ function addStarField() {
|
|||||||
background2.update();
|
background2.update();
|
||||||
background2a.draw();
|
background2a.draw();
|
||||||
background2a.update();
|
background2a.update();
|
||||||
|
|
||||||
background1.draw();
|
|
||||||
background1.update();
|
|
||||||
background1a.draw();
|
|
||||||
background1a.update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class Missile{
|
class Missile{
|
||||||
@ -403,4 +397,37 @@ class EnemyObj {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let enemy = new EnemyObj(800, 200, 12);
|
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);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user