add collision with enemies

master
Fabien Freling 2021-08-12 13:50:52 +02:00
parent b860968ef5
commit 7eb109cf92
1 changed files with 14 additions and 5 deletions

View File

@ -326,15 +326,24 @@ class World {
i = i + 1
}
}
if (_player.alive) {
if (!(fgCheck(_player.x - _player.bw / 2, _player.y - _player.bh / 2) &&
fgCheck(_player.x - _player.bw / 2, _player.y + _player.bh / 2) &&
fgCheck(_player.x + _player.bw / 2, _player.y + _player.bh / 2) &&
fgCheck(_player.x + _player.bw / 2, _player.y - _player.bh / 2))) {
//System.print("collision with foreground")
var bx = _player.x - _player.bw / 2
var by = _player.y - _player.bh / 2
if (!(fgCheck(bx, by) &&
fgCheck(bx, by + _player.bh) &&
fgCheck(bx + _player.bw, by + _player.bh) &&
fgCheck(bx + _player.bw, by))) {
_player.die()
_vfx.add(Explosion.new(_player.x, _player.y))
}
for (e in _enemies) {
if (collide(bx, by, _player.bw, _player.bh, e.x, e.y, e.w, e.h)) {
_player.die()
_vfx.add(Explosion.new(_player.x, _player.y))
}
}
}
}