Commit 706767da authored by Yannick Armand's avatar Yannick Armand

Application des conseils de tslint

parent 1bb4fb37
......@@ -33,10 +33,10 @@ export class Keyboard {
public release(k: number): boolean {
const last = this.lasts[this.lasts.indexOf(k)]
if (last != -1)
if (last !== -1)
this.lasts.splice(k)
return last == k
return last === k
}
private onKeyUp(e: KeyboardEvent): void {
......
......@@ -59,12 +59,12 @@ export default class Mouse {
// Au moment où le bouton est enfoncé
public press(): boolean {
return this.click == this.mtime
return this.click === this.mtime
}
// Au moment où le bouton est levé
public release(): boolean {
return this.loose == this.mtime
return this.loose === this.mtime
}
public wheel(): WheelDirection {
......
......@@ -90,6 +90,9 @@ export default class Game {
this.lastUpdate = now
for (const i in this.players) {
if (!this.players.hasOwnProperty(i))
continue
const player = this.players[i]
player.update(this.dt)
}
......
......@@ -13,12 +13,12 @@ export default class ImageManager {
private path: string
// Fonction appelée une fois les images chargées
private callback: () => void
private callback: (() => void) | null
public constructor() {
this.images = {}
this.path = 'assets/img/'
this.callback = () => { }
this.callback = null
}
// Obtenir une image par son nom
......@@ -55,9 +55,9 @@ export default class ImageManager {
const imageLoaded = () => {
nbImagesToLoad -= 1
if (nbImagesToLoad == 0) {
this.callback()
}
if (nbImagesToLoad === 0)
if (this.callback)
this.callback()
}
// L'image n'a pas pu charger
......
......@@ -29,46 +29,48 @@ export class Map {
h: number,
x: number,
y: number,
min_r: number,
base_r: number,
max_path: number,
minR: number,
baseR: number,
maxPath: number,
) {
this.noiseAngle = new OSimplexNoise()
this.noiseRadius = new OSimplexNoise()
this.noiseAngle.setSeed(this.seed + h)
this.noiseRadius.setSeed(this.seed + h)
let dir_x = 1
let dir_y = 1
for (let i = 0, count2 = max_path ; i < count2 ; i++) {
let dirX = 1
let dirY = 1
for (let i = 0, count2 = maxPath ; i < count2 ; i++) {
const angle = this.noiseAngle.noise2D(i / 100, i / 100) * Math.PI * 2
const radius = min_r + (this.noiseRadius.noise2D(i / 500, i / 500) + 1) / 2 * base_r
const radius = minR + (this.noiseRadius.noise2D(i / 500, i / 500) + 1) / 2 * baseR
for (let j = 0, count1 = (2 * radius) ; j < count1 ; j++) {
for (let k = 0, count = (2 * radius) ; k < count ; k++) {
if ((j - radius | 0 * j - radius | 0) > (radius * radius) || (k - radius | 0 * k - radius | 0) > (radius * radius)) {
if (
(Math.floor(j - radius) * Math.floor(j - radius)) > (radius * radius) ||
(Math.floor(k - radius) * Math.floor(k - radius)) > (radius * radius)
) {
continue
}
// y * width + x
// cf. http://stackoverflow.com/a/2151141/1974228
const xpos = x + j - radius | 0
const ypos = y + k - radius | 0
const index = xpos + (ypos * w) | 0
const xpos = Math.floor(x + j - radius)
const ypos = Math.floor(y + k - radius)
const index = Math.floor(xpos + ypos * w)
cells[index] = 1
}
}
x += Math.cos(angle) * dir_x
y += Math.sin(angle) * dir_y
x += Math.cos(angle) * dirX
y += Math.sin(angle) * dirY
if (x < 0 || x >= w) {
dir_x = -dir_x
}
if (x < 0 || x >= w)
dirX = -dirX
if (y < 0 || y >= h) {
dir_y = -dir_y
}
if (y < 0 || y >= h)
dirY = -dirY
x = clamp(x, 0, w - 1)
y = clamp(y, 0, h - 1)
......@@ -84,32 +86,32 @@ export class Map {
this.worm(cells, MapWidth, MapHeight, 0, MapHeight, 3, 5, 500)
this.worm(cells, MapWidth, MapHeight, MapWidth, MapHeight, 3, 5, 500)
for (let x = 0 ; x < MapWidth ; x++) {
cells[x] = 0
cells[(MapHeight - 1) * MapWidth + x] = 0
for (let xx = 0 ; xx < MapWidth ; xx++) {
cells[xx] = 0
cells[(MapHeight - 1) * MapWidth + xx] = 0
}
for (let y = 0 ; y < MapHeight ; y++) {
cells[y * MapWidth] = 0
cells[(y + 1) * MapWidth - 1] = 0
for (let yy = 0 ; yy < MapHeight ; yy++) {
cells[yy * MapWidth] = 0
cells[(yy + 1) * MapWidth - 1] = 0
}
this.walls = []
for (let y = 0 ; y < MapHeight ; y++)
this.walls[y] = []
for (let yyy = 0 ; yyy < MapHeight ; yyy++)
this.walls[yyy] = []
let y = -1
for (let i = 0 ; i < cells.length ; i++) {
const x = i % MapWidth
if (x == 0)
if (x === 0)
y++
const cell = cells[i]
if (cell == 0)
if (cell === 0)
this.walls[y][x] = 0
else
this.walls[y][x] = -1
......@@ -146,7 +148,7 @@ export class Map {
for (let y = 0 ; y < MapHeight ; y++) {
for (let x = 0 ; x < MapWidth ; x++) {
if (this.getWall(x, y) != -1) {
if (this.getWall(x, y) !== -1) {
level.drawImage(
game.getImageManager().getImage('wall'),
x * Game.TILE_SIZE,
......@@ -205,7 +207,7 @@ export class Map {
for (let x = pos.getX() - 2 ; x < pos.getX() + 2 ; x++) {
for (let y = pos.getY() - 2 ; y < pos.getY() + 2 ; y++) {
if (this.getWall(x, y) != -1) {
if (this.getWall(x, y) !== -1) {
const wall = new Rect(
x * Game.TILE_SIZE,
y * Game.TILE_SIZE,
......
......@@ -15,16 +15,16 @@ export default class OSimplexNoise {
this.seed = seed
if (seed === null) {
for (let i = 0 ; i < 256 ; i++)
this.randArray[i] = Math.random() * 256
for (let j = 0 ; j < 256 ; j++)
this.randArray[j] = Math.random() * 256
return
}
const source = new Int8Array(256)
for (let i = 0 ; i < 256 ; i++)
source[i] = i
for (let k = 0 ; k < 256 ; k++)
source[k] = k
const a = 6
const b = 1
......@@ -47,7 +47,7 @@ export default class OSimplexNoise {
this.randArray[i] = source[i]
source[r] = source[i]
if (i == 0)
if (i === 0)
break
i--
......
......@@ -4,6 +4,8 @@ import Player from './Player'
import Point from './Point'
import { rand } from './Util'
/*
const colors = [
'rgb(255, 50, 8)',
'rgb(232, 98, 14)',
......@@ -11,6 +13,8 @@ const colors = [
'rgb(35, 117, 179)',
]
*/
const PARTICLE_DAMAGES = 3
// Converti des degrés en radians
......
......@@ -176,8 +176,6 @@ export default class Player implements Entity {
return this.getCircle()
}
public onOverlaps(entity: Entity): void { }
/*
public render(ctx: CanvasRenderingContext2D): void {
......@@ -444,7 +442,7 @@ export default class Player implements Entity {
public play(name: string, force: boolean = false): void {
const nextAnimation = this.animations.getAnimation(name)
if ((this.animations.getCurrentAnimation() != nextAnimation || force) && nextAnimation)
if ((this.animations.getCurrentAnimation() !== nextAnimation || force) && nextAnimation)
this.animations.setCurrentAnimation(nextAnimation)
}
......
......@@ -61,13 +61,13 @@ export default class Game extends BaseGame {
client.uuid = uuidv4()
const player = new Player(this)
player.setUuid(client.uuid)
const clientPlayer = new Player(this)
clientPlayer.setUuid(client.uuid)
client.emit(PlayerEvent.Joined, {
x: player.getPosition().getX(),
y: player.getPosition().getY(),
color: player.getColor(),
x: clientPlayer.getPosition().getX(),
y: clientPlayer.getPosition().getY(),
color: clientPlayer.getColor(),
uuid: client.uuid,
yours: true,
mapSeed: this.getMap().getSeed(),
......
......@@ -11,7 +11,10 @@
"array-type": [ true, "generic" ],
"no-string-literal": false,
"object-literal-shorthand": false,
"arrow-parens": [true, "ban-single-arg-parens"]
"arrow-parens": [ true, "ban-single-arg-parens" ],
"no-console": false,
"object-literal-sort-keys": false,
"interface-name": [ true, "never-prefix" ]
},
"rulesDirectory": []
}
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