Commit c0da62cc authored by Yannick A.'s avatar Yannick A.

Les particules font exploser les mines/dynamites

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