Compressed assets & improved main gameplay
This commit is contained in:
@@ -3,7 +3,7 @@ import Player from "./player.js"
|
||||
import { Bullet, Meteor, Turret } from "./gameObjects.js"
|
||||
import { Renderer } from "./renderer.js"
|
||||
import { setFastTurret, setHeavyTurret, setLaserTurret, setStandardTurret } from "./turretTypes.js"
|
||||
import SoundEffect from "./soundEffect.js"
|
||||
import { SoundEffect } from "./soundEffect.js"
|
||||
|
||||
export default class Game {
|
||||
|
||||
@@ -28,7 +28,7 @@ export default class Game {
|
||||
heavy: 100
|
||||
}
|
||||
|
||||
SoundEffect.setEffectVolume(0.3)
|
||||
SoundEffect.setVolumeAll(0.3)
|
||||
|
||||
document.addEventListener("keydown", (event) => {
|
||||
switch(event.key) {
|
||||
@@ -85,12 +85,6 @@ export default class Game {
|
||||
this.canvas.addEventListener("mouseup", () => this.setTurretFire(false))
|
||||
this.canvas.addEventListener("dblclick", () => this.setTurretFire(!this.turretFire))
|
||||
|
||||
const volumeInput = document.getElementById("volume")
|
||||
volumeInput.addEventListener("change", () => {
|
||||
console.log('volume', volumeInput.value)
|
||||
this.player.gain.gain.value = volumeInput.value / 10
|
||||
})
|
||||
|
||||
this.setGameOver()
|
||||
this.player.audio.addEventListener('ended', () => {
|
||||
this.setGameOver(true)
|
||||
@@ -172,10 +166,6 @@ export default class Game {
|
||||
setTurretFire(fire) {
|
||||
this.turretFire = fire
|
||||
this.renderer.turrets.forEach((turret) => turret.animationRunning = fire)
|
||||
|
||||
// if (!fire) {
|
||||
// SoundEffect.play(SoundEffect.turretRelease)
|
||||
// }
|
||||
}
|
||||
|
||||
setAmmoCounter() {
|
||||
@@ -201,16 +191,14 @@ export default class Game {
|
||||
const deltaLastShot = performance.now() - turret.lastShot
|
||||
if (deltaLastShot > turret.firingRate) {
|
||||
const angle = turret.angle - ((Math.floor(Math.random() * turret.spread) / 1000) * (Math.random() < 0.5 ? -1 : 1))
|
||||
this.renderer.bullets.push(new Bullet(turret.x , turret.y, angle, turret.bulletSprite, turret.damage))
|
||||
this.renderer.bullets.push(new Bullet(turret.x , turret.y, angle, turret.bulletSprite, turret.damage, turret.aoe, turret.aoeSize, turret.percing, turret.bulletHealth))
|
||||
turret.lastShot = performance.now()
|
||||
// SoundEffect.play(turret.sound)
|
||||
}
|
||||
|
||||
this.nextTurretToFire = this.nextTurretToFire < this.renderer.turrets.length - 1 ? this.nextTurretToFire + 1 : 0
|
||||
}
|
||||
|
||||
spawnMeteor() {
|
||||
// meteors[Math.floor(Math.random() * this.meteors.length)]
|
||||
this.renderer.meteors.push(new Meteor(this.canvas.width, this.canvas.height, this.currentLevel.maxHealth, this.currentLevel.meteorImg, this.currentLevel.meteorImgList))
|
||||
}
|
||||
|
||||
@@ -225,7 +213,7 @@ export default class Game {
|
||||
const damageTaken = this.renderer.render()
|
||||
|
||||
if (damageTaken > 0 && this.currentLevel.title !== "MainMenu") {
|
||||
SoundEffect.play(SoundEffect.explosionBig)
|
||||
SoundEffect.explosionBig.play()
|
||||
this.health -= damageTaken
|
||||
}
|
||||
|
||||
@@ -234,19 +222,13 @@ export default class Game {
|
||||
|
||||
// Slow updates
|
||||
if ((now - this.lastSlowUpdate) > 1000) {
|
||||
console.log('SLOW')
|
||||
if (this.turretFire) {
|
||||
console.log('SET AMMO', this.ammoCurrent, this.ammo)
|
||||
this.ammo.laser += this.ammo.laser < 100 ? 5 : 0
|
||||
this.ammo.fast += this.ammo.fast < 100 ? 5 : 0
|
||||
this.ammo.standard += this.ammo.standard < 100 ? 5 : 0
|
||||
this.ammo.heavy += this.ammo.heavy < 100 ? 5 : 0
|
||||
this.ammo.laser = this.ammo.laser + 1 < 100 ? this.ammo.laser + 1 : 100
|
||||
this.ammo.fast = this.ammo.fast + 5 < 100 ? this.ammo.fast + 5 : 100
|
||||
this.ammo.standard = this.ammo.standard + 2 < 100 ? this.ammo.standard + 5 : 100
|
||||
this.ammo.heavy = this.ammo.heavy + 0.5 < 100 ? this.ammo.heavy + 2 : 100
|
||||
|
||||
this.ammo[this.ammoCurrent] -= 6
|
||||
|
||||
if (this.ammo[this.ammoCurrent] <= 0) {
|
||||
this.ammo[this.ammoCurrent] = 0
|
||||
}
|
||||
this.ammo[this.ammoCurrent] = this.ammo[this.ammoCurrent] - 5 > 0 ? this.ammo[this.ammoCurrent] - 5 : 0
|
||||
|
||||
this.setAmmoCounter()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user