Commit 9cf31183 authored by Yannick Armand's avatar Yannick Armand

Les collisions se font aussi sur le serveur

parent f6569231
import Mine from '../common/block/Mine'
import Camera from '../common/Camera'
import { collide } from '../common/Collision'
import { PlayerEvent } from '../common/Event'
import BaseGame from '../common/Game'
import Hit from '../common/Hit'
......@@ -247,60 +246,6 @@ export default class Game extends BaseGame {
const player = players[i]
player.render(this.ctx)
for (const projectile of this.getProjectiles()) {
const collision = Hit.circleHitCircle(
player.getCircle(),
projectile.getCircle(),
)
if (collision)
collide(player, projectile)
}
for (const block of this.getBlocks()) {
const collision = Hit.circleHitCircle(
player.getCircle(),
block.getCircle(),
)
if (collision)
collide(block, player)
}
for (const particle of this.getParticles()) {
const collision = Hit.circleHitCircle(
player.getCircle(),
particle.getCircle(),
)
if (collision)
particle.onPlayerOverlaps(player)
}
}
for (const projectile of this.getProjectiles()) {
for (const block of this.getBlocks()) {
const collision = Hit.circleHitCircle(
block.getCircle(),
projectile.getCircle(),
)
if (collision)
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)
}
}
}
......
import Block from './block/Block'
import { collide } from './Collision';
import Hit from './Hit'
import ImageManager from './ImageManager'
import { Map } from './Map'
import Particle from './Particle'
......@@ -105,6 +107,69 @@ export default class Game {
for (const particle of this.particles)
particle.update(this.dt)
const players = this.getPlayers()
for (const i in players) {
if (!players.hasOwnProperty(i))
continue
const player = players[i]
for (const projectile of this.getProjectiles()) {
const collision = Hit.circleHitCircle(
player.getCircle(),
projectile.getCircle(),
)
if (collision)
collide(player, projectile)
}
for (const block of this.getBlocks()) {
const collision = Hit.circleHitCircle(
player.getCircle(),
block.getCircle(),
)
if (collision)
collide(block, player)
}
for (const particle of this.getParticles()) {
const collision = Hit.circleHitCircle(
player.getCircle(),
particle.getCircle(),
)
if (collision)
particle.onPlayerOverlaps(player)
}
}
for (const projectile of this.getProjectiles()) {
for (const block of this.getBlocks()) {
const collision = Hit.circleHitCircle(
block.getCircle(),
projectile.getCircle(),
)
if (collision)
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)
}
}
}
public getImageManager(): ImageManager {
......
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