Commit 3328ba87 authored by Yannick Armand's avatar Yannick Armand

Premiers fumigènes

parent 0edb1244
import Game from '../../Game'
import Point from '../../Point'
import Circle from '../../Circle'
import Entity from '../../Entity'
import Game from '../../Game'
import Point from '../../Point'
export default abstract class Projectile implements Entity {
// Jeu
......@@ -84,7 +84,7 @@ export default abstract class Projectile implements Entity {
const velocity = new Point(
Math.cos(this.angle),
Math.sin(this.angle)
Math.sin(this.angle),
)
velocity.scale(this.speed)
......@@ -108,6 +108,26 @@ export default abstract class Projectile implements Entity {
return this.velocity
}
public getCenter(): Point {
const middle = this.getMiddle()
return new Point(
this.position.getX() + middle.getX(),
this.position.getY() + middle.getY(),
)
}
public getCircle(): Circle {
const position = this.getCenter()
const radius = (this.width + this.height) / 4
return new Circle(position.getX(), position.getY(), radius)
}
public getCollisionShape() {
return this.getCircle()
}
protected getGame(): Game {
return this.game
}
......@@ -143,33 +163,17 @@ export default abstract class Projectile implements Entity {
return this
}
private getMiddle(): Point {
return new Point(
this.width / 2,
this.height / 2
)
protected getPosition(): Point {
return this.position
}
public getCenter(): Point {
const middle = this.getMiddle()
private getMiddle(): Point {
return new Point(
this.position.getX() + middle.getX(),
this.position.getY() + middle.getY()
this.width / 2,
this.height / 2,
)
}
public getCircle(): Circle {
const position = this.getCenter()
const radius = (this.width + this.height) / 4
return new Circle(position.getX(), position.getY(), radius)
}
public getCollisionShape() {
return this.getCircle()
}
private decreaseLifetime(dt: number): void {
if (typeof this.lifetime !== 'number')
return
......
import Explosion from '../../Explosion'
import Game from '../../Game'
import Particle from '../../Particle'
import Projectile from './Projectile'
const SLIDER = 0.98
const INITIAL_SPEED = 400
const SPEED_LIMIT_BEFORE_SMOKE = 50
const SPEED_LIMIT_BEFORE_EXPLOSION = 2
export default class SmokeGrenade extends Projectile {
......@@ -11,7 +15,7 @@ export default class SmokeGrenade extends Projectile {
const image = this.getGame().getImageManager().getImage('projectile/smoke-grenade')
this.setSize(11, 11)
.setSpeed(400)
.setSpeed(INITIAL_SPEED)
.setImage(image)
}
......@@ -20,21 +24,33 @@ export default class SmokeGrenade extends Projectile {
this.slowDown()
if (this.canSmoke())
this.smoke()
if (this.isTooSlow())
this.explode()
this.remove()
}
private slowDown(): void {
this.getVelocity().scale(SLIDER)
}
private canSmoke(): boolean {
return Math.abs(this.getVelocity().getX()) < SPEED_LIMIT_BEFORE_SMOKE
}
private isTooSlow(): boolean {
return Math.abs(this.getVelocity().getX()) < SPEED_LIMIT_BEFORE_EXPLOSION
}
private explode(): void {
// @todo Lâcher la fumée
private smoke(): void {
const particle = new Particle(this.getGame())
.setPosition(this.getPosition().clone())
.setSpeed(24, 68)
.setLifetime(1, 6)
.setRadius(20, 60)
.setAngle(0, 360)
this.remove()
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