Commit b18cb72d authored by Yannick Armand's avatar Yannick Armand

Intégration des barils explosifs

parent 724233ea
......@@ -53,6 +53,12 @@ class Collision {
public static onParticleOverlapsMine(particle: Particle, mine: BlockMine): void {
mine.explode()
}
public static onParticleOverlapsBarrel(particle: Particle, barrel: Barrel): void {
barrel.decreaseHealth(particle.getDamages())
particle.remove()
}
}
const collisions: { [key: string]: { [key: string]: (e1: any, e2: any) => void } } = {
......@@ -93,6 +99,7 @@ const collisions: { [key: string]: { [key: string]: (e1: any, e2: any) => void }
[Particle.name]: {
[BlockDynamite.name]: Collision.onParticleOverlapsMine,
[BlockMine.name]: Collision.onParticleOverlapsMine,
[Barrel.name]: Collision.onParticleOverlapsBarrel,
},
}
......
......@@ -46,7 +46,7 @@ export default class Particle implements Entity {
private color: string
private damages: number | null
private damages: number
// Créer une particule
public constructor(game: Game) {
......@@ -65,7 +65,7 @@ export default class Particle implements Entity {
this.color = 'rgb(255, 255, 255)'
this.damages = null
this.damages = 0
}
// Mise à jour d'une particule
......@@ -174,7 +174,11 @@ export default class Particle implements Entity {
return this.getCircle()
}
private remove(): void {
public getDamages(): number {
return this.damages
}
public remove(): void {
this.game.removeParticle(this)
}
}
......@@ -259,7 +259,7 @@ export default class Player implements Entity {
this.health -= value
if (this.health < 0)
this.health = 0
this.health = 0
}
// Monter la vie
......
import Explosion from '../Explosion'
import Game from '../Game'
import Block from './Block'
const BASE_HEALTH = 120
export default class Barrel extends Block {
private health: number
public constructor(game: Game, x: number, y: number) {
super(game, x, y, 25, 25)
this
.setSolid(true)
.setImage(game.getImageManager().getImage('block/barrel'))
this.health = BASE_HEALTH
}
public update(dt: number): void {
super.update(dt)
if (this.health <= 0)
this.explode()
}
public decreaseHealth(value: number): void {
this.health -= value
if (this.health < 0)
this.health = 0
}
public explode(): void {
const explosion = new Explosion(this.getGame(), this.getPosition().clone())
explosion.explode()
this.getGame().removeBlock(this)
}
}
......@@ -23,7 +23,7 @@ export default class Flamethrower extends Weapon {
const particle = new Particle(this.getGame())
.setPosition(position.clone())
.setSpeed(180, 220)
.setLifetime(0.3, 0.7)
.setLifetime(0.4, 0.6)
.setRadius(3, 6)
.setAngle(angle - 30, angle + 30)
.setColor([
......@@ -31,6 +31,10 @@ export default class Flamethrower extends Weapon {
'rgb(255, 140, 0)',
'rgb(255, 215, 0)',
])
.setDamages(3)
// @todo Même solution magique que Projectile
particle.update(0.08)
this.getGame().addParticle(particle)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment