Commit c0da62cc authored by Yannick Armand's avatar Yannick Armand

Les particules font exploser les mines/dynamites

parent 4b2693b6
......@@ -290,6 +290,18 @@ export default class Game extends BaseGame {
collide(block, projectile)
}
}
for (const particle of this.getParticles()) {
for (const block of this.getBlocks()) {
const collision = Hit.circleHitCircle(
particle.getCollisionShape(),
block.getCollisionShape(),
)
if (collision)
collide(particle, block)
}
}
}
this.mouse.update()
......
......@@ -5,6 +5,7 @@ import Crate from './block/Crate'
import BlockDynamite from './block/Dynamite'
import BlockMine from './block/Mine'
import Entity from './Entity'
import Particle from './Particle'
import Bullet from './weapon/projectile/Bullet'
import Grenade from './weapon/projectile/Grenade'
import Projectile from './weapon/projectile/Projectile'
......@@ -48,6 +49,10 @@ class Collision {
if (mine.canExplode())
mine.setActive(true)
}
public static onParticleOverlapsMine(particle: Particle, mine: BlockMine): void {
mine.explode()
}
}
const collisions: { [key: string]: { [key: string]: (e1: any, e2: any) => void } } = {
......@@ -84,6 +89,11 @@ const collisions: { [key: string]: { [key: string]: (e1: any, e2: any) => void }
[Barrel.name]: Collision.onSmokeGrenadeOverlapsBlock,
[Crate.name]: Collision.onSmokeGrenadeOverlapsBlock,
},
[Particle.name]: {
[BlockDynamite.name]: Collision.onParticleOverlapsMine,
[BlockMine.name]: Collision.onParticleOverlapsMine,
},
}
export function collide(e1: Entity, e2: Entity): void {
......
import Circle from './Circle'
import Entity from './Entity'
import Game from './Game'
import Player from './Player'
import Point from './Point'
......@@ -31,7 +32,7 @@ function randomElement<T>(items: Array<T>): T {
return items[Math.floor(Math.random() * items.length)]
}
export default class Particle {
export default class Particle implements Entity {
private game: Game
private position: Point
......@@ -158,6 +159,10 @@ export default class Particle {
return new Circle(this.position.getX(), this.position.getY(), radius)
}
public getCollisionShape() {
return this.getCircle()
}
private remove(): void {
this.game.removeParticle(this)
}
......
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