Commit af302b3a authored by Yannick Armand's avatar Yannick Armand

Simplification de l'affichage des miniatures des armes

parent 245a77fa
......@@ -9,6 +9,7 @@ export default class Dynamite extends Weapon {
super(game, 'Dynamite')
this.setBaseLatency(0.5)
this.setMiniatureIndex(0)
}
public getType(): WeaponName {
......@@ -27,10 +28,4 @@ export default class Dynamite extends Weapon {
return true
}
public renderMiniature(ctx: CanvasRenderingContext2D): void {
const img = this.getGame().getImageManager().getImage('weapons-miniatures')
ctx.drawImage(img, 0, 0, 16, 16, 0, 0, 16, 16)
}
}
......@@ -8,13 +8,14 @@ import WeaponName from './WeaponName'
export default class Flamethrower extends Weapon {
constructor(game: Game) {
super(game, 'Lance-flammes')
this.setMiniatureIndex(7)
}
public getType(): WeaponName {
return 'flamethrower'
}
// Tir du joueur
public fire(position: Point, angle: number): boolean {
angle = -radiansToDegrees(angle)
......@@ -36,11 +37,4 @@ export default class Flamethrower extends Weapon {
return true
}
// Affichage de la miniature
public renderMiniature(ctx: CanvasRenderingContext2D): void {
const img = this.getGame().getImageManager().getImage('weapons-miniatures')
ctx.drawImage(img, 7 * 16, 0, 16, 16, 0, 0, 16, 16)
}
}
import Point from '../Point'
import Weapon from './Weapon'
import Game from '../Game'
import Point from '../Point'
import GrenadeBullet from './projectile/Grenade'
import Weapon from './Weapon'
import WeaponName from './WeaponName'
export default class Grenade extends Weapon {
......@@ -9,6 +9,7 @@ export default class Grenade extends Weapon {
super(game, 'Grenade')
this.setBaseLatency(0.5)
this.setMiniatureIndex(1)
}
public getType(): WeaponName {
......@@ -27,10 +28,4 @@ export default class Grenade extends Weapon {
return true
}
public renderMiniature(ctx: CanvasRenderingContext2D): void {
const img = this.getGame().getImageManager().getImage('weapons-miniatures')
ctx.drawImage(img, 16, 0, 16, 16, 0, 0, 16, 16)
}
}
......@@ -9,6 +9,7 @@ export default class Gun extends Weapon {
super(game, 'Pistolet')
this.setBaseLatency(0.5)
this.setMiniatureIndex(2)
}
public getType(): WeaponName {
......@@ -27,10 +28,4 @@ export default class Gun extends Weapon {
return true
}
public renderMiniature(ctx: CanvasRenderingContext2D): void {
const img = this.getGame().getImageManager().getImage('weapons-miniatures')
ctx.drawImage(img, 32, 0, 16, 16, 0, 0, 16, 16)
}
}
......@@ -9,6 +9,7 @@ export default class Mine extends Weapon {
super(game, 'Mine')
this.setBaseLatency(0.5)
this.setMiniatureIndex(3)
}
public getType(): WeaponName {
......@@ -27,10 +28,4 @@ export default class Mine extends Weapon {
return true
}
public renderMiniature(ctx: CanvasRenderingContext2D): void {
const img = this.getGame().getImageManager().getImage('weapons-miniatures')
ctx.drawImage(img, 48, 0, 16, 16, 0, 0, 16, 16)
}
}
import Game from '../Game'
import Point from '../Point'
import Rocket from './projectile/Rocket'
import Weapon from './Weapon'
import Game from '../Game'
import WeaponName from './WeaponName'
import Rocket from './projectile/Rocket'
export default class RocketLauncher extends Weapon {
constructor(game: Game) {
super(game, 'Bazooka')
this.setBaseLatency(2)
this.setMiniatureIndex(4)
}
public getType(): WeaponName {
return 'rocket-launcher'
}
// Tir du joueur
public fire(position: Point, angle: number): boolean {
if (!this.canFire())
return false
......@@ -28,11 +28,4 @@ export default class RocketLauncher extends Weapon {
return true
}
// Affichage de la miniature
public renderMiniature(ctx: CanvasRenderingContext2D): void {
const img = this.getGame().getImageManager().getImage('weapons-miniatures')
ctx.drawImage(img, 64, 0, 16, 16, 0, 0, 16, 16)
}
}
......@@ -9,6 +9,7 @@ export default class Shotgun extends Weapon {
super(game, 'Fusil à pompe')
this.setBaseLatency(1)
this.setMiniatureIndex(5)
}
public getType(): WeaponName {
......@@ -39,10 +40,4 @@ export default class Shotgun extends Weapon {
return true
}
public renderMiniature(ctx: CanvasRenderingContext2D): void {
const img = this.getGame().getImageManager().getImage('weapons-miniatures')
ctx.drawImage(img, 5 * 16, 0, 16, 16, 0, 0, 16, 16)
}
}
import Game from '../Game'
import Point from '../Point'
import SmokeGrenadeBullet from './projectile/SmokeGrenade'
import Weapon from './Weapon'
import Game from '../Game'
import WeaponName from './WeaponName'
import SmokeGrenadeBullet from './projectile/SmokeGrenade'
export default class SmokeGrenade extends Weapon {
constructor(game: Game) {
super(game, 'Fumigène')
this.setBaseLatency(2)
this.setMiniatureIndex(8)
}
public getType(): WeaponName {
return 'smoke-grenade'
}
// Tir du joueur
public fire(position: Point, angle: number): boolean {
if (!this.canFire())
return false
......@@ -28,11 +28,4 @@ export default class SmokeGrenade extends Weapon {
return true
}
// Affichage de la miniature
public renderMiniature(ctx: CanvasRenderingContext2D): void {
const img = this.getGame().getImageManager().getImage('weapons-miniatures')
ctx.drawImage(img, 128, 0, 16, 16, 0, 0, 16, 16)
}
}
......@@ -9,6 +9,7 @@ export default class SubmachineGun extends Weapon {
super(game, 'Mitraillette')
this.setBaseLatency(0.1)
this.setMiniatureIndex(6)
}
public getType(): WeaponName {
......@@ -27,10 +28,4 @@ export default class SubmachineGun extends Weapon {
return true
}
public renderMiniature(ctx: CanvasRenderingContext2D): void {
const img = this.getGame().getImageManager().getImage('weapons-miniatures')
ctx.drawImage(img, 6 * 16, 0, 16, 16, 0, 0, 16, 16)
}
}
......@@ -15,6 +15,8 @@ export default abstract class Weapon {
private baseLatency: number
private latency: number
private miniatureIndex: number | null
constructor(game: Game, name: string) {
this.game = game
......@@ -25,6 +27,8 @@ export default abstract class Weapon {
this.baseLatency = 0
this.latency = 0
this.miniatureIndex = null
}
public update(dt: number): void {
......@@ -39,6 +43,22 @@ export default abstract class Weapon {
return this.hasAmmo() && this.latency <= 0
}
public renderMiniature(ctx: CanvasRenderingContext2D): void {
if (this.miniatureIndex === null)
return
const MINIATURE_SIZE = 16
const img = this.getGame().getImageManager().getImage('weapons-miniatures')
const index = this.miniatureIndex
ctx.drawImage(img, index * MINIATURE_SIZE, 0, 16, 16, 0, 0, 16, 16)
}
public abstract getType(): WeaponName
public abstract fire(position: Point, angle: number): boolean
protected hasAmmo(): boolean {
return this.ammo > 0 || this.hasInfiniteAmmo()
}
......@@ -77,6 +97,12 @@ export default abstract class Weapon {
return this.game
}
protected setMiniatureIndex(miniatureIndex: number): this {
this.miniatureIndex = miniatureIndex
return this
}
private hasInfiniteAmmo(): boolean {
return this.infiniteAmmo
}
......@@ -88,10 +114,4 @@ export default abstract class Weapon {
if (this.latency < 0)
this.latency = 0
}
public abstract getType(): WeaponName
public abstract fire(position: Point, angle: number): boolean
public abstract renderMiniature(ctx: CanvasRenderingContext2D): void
}
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