diff --git a/Script.js b/Script.js index 6f8b485..35974a5 100644 --- a/Script.js +++ b/Script.js @@ -26,8 +26,11 @@ var keys = { + + +// Untuk background var playerShipImg = new Image(); -playerShipImg.src = 'img/pixelShip.png' +playerShipImg.src = 'img/fighterShip.png' var bg0 = new Image(); bg0.src = 'img/bg_0.png'; @@ -39,9 +42,38 @@ var bg2 = new Image(); bg2.src = "img/bg_2.png"; + + + +var enemyImgArray = []; +enemyImgArray.length = 7; + +var enemy1 = new Image(); +enemy1.src = "img/alien_0.png" + + var missilesArray = []; + + +var backgroundMusic = document.createElement('audio'); +backgroundMusic.src = "music/Muriel-BobbyRichards.mp3"; + +var laser = document.createElement("audio"); +laser.src = "music/laser2.mp3"; + + + + + + + + + + + + window.onload = function () { init() } @@ -57,6 +89,8 @@ function init() { function keyDownPressed(e) { if (e.keyCode == 87) { keys.up = true; + backgroundMusic.play(); + backgroundMusic.volume = 0.8; } else if (e.keyCode == 83) { keys.down = true } @@ -72,6 +106,11 @@ function keyDownPressed(e) { if (e.keyCode == 32) { keys.fire = true; missilesArray.push(new Missile(player1.x + 120, player1.y + 50, 'white', 12)); + + + laser.currentTime = 0; + laser.play(); + laser.volume = 0.4; } } @@ -101,6 +140,9 @@ function clearGame() { ctx.clearRect(0, 0, canvasWidth, canvasHeight); } + + + function updateGame() { addStarField(); @@ -109,10 +151,16 @@ function updateGame() { game.frames++; } + + function drawGame() { player1.draw(); + enemy.draw(); + + enemy.update(); + for(var i = 0; i < missilesArray.length; i++){ var m = missilesArray[i]; m.draw(); @@ -268,4 +316,38 @@ class Missile{ update(){ this.x += this.speed } -} \ No newline at end of file +} + + + + + + + + + + + +class EnemyObj { + constructor(x, y, speed) { + this.x = x; + this.y = y; + this.width = 170; + this.height = 105; + this.image = enemy1; + this.speed = speed; + this.health = 100; + this.damage = 10; + } + draw() { + ctx.save(); + ctx.drawImage(this.image, this.x, this.y, this.width, this.height); + ctx.restore(); + } + + update() { + this.x -= this.speed; + } +} + +let enemy = new EnemyObj(800, 200, 12); \ No newline at end of file diff --git a/img/alien_0.png b/img/alien_0.png new file mode 100644 index 0000000..60406ec Binary files /dev/null and b/img/alien_0.png differ diff --git a/img/alien_1.png b/img/alien_1.png new file mode 100644 index 0000000..3fefd1f Binary files /dev/null and b/img/alien_1.png differ diff --git a/img/alien_2.png b/img/alien_2.png new file mode 100644 index 0000000..cef2b5c Binary files /dev/null and b/img/alien_2.png differ diff --git a/img/alien_3.png b/img/alien_3.png new file mode 100644 index 0000000..ba5c1ec Binary files /dev/null and b/img/alien_3.png differ diff --git a/img/bg_0. Seamless looping animation b/img/bg_0. Seamless looping animation deleted file mode 100644 index 45bb862..0000000 Binary files a/img/bg_0. Seamless looping animation and /dev/null differ diff --git a/img/fighterShip.png b/img/fighterShip.png new file mode 100644 index 0000000..21d5849 Binary files /dev/null and b/img/fighterShip.png differ diff --git a/music/Muriel-BobbyRichards.mp3 b/music/Muriel-BobbyRichards.mp3 new file mode 100644 index 0000000..6a9e45c Binary files /dev/null and b/music/Muriel-BobbyRichards.mp3 differ diff --git a/music/laser.mp3 b/music/laser.mp3 new file mode 100644 index 0000000..3ac6b9b Binary files /dev/null and b/music/laser.mp3 differ diff --git a/music/laser2.mp3 b/music/laser2.mp3 new file mode 100644 index 0000000..483ce59 Binary files /dev/null and b/music/laser2.mp3 differ