1
0
Fork 0
Browse Source

feat: add collision check

And discover, that it still has some bugs

Signed-off-by: André Jaenisch <andre.jaenisch@posteo.de>
combat-scorched-earth-from-outer-space
André Jaenisch 10 months ago
parent
commit
abe72d6702
Signed by: ryuno-ki
GPG Key ID: 5A668E771F1ED854
  1. BIN
      js13kgames.zip
  2. 12
      src/js/app.js

BIN
js13kgames.zip

Binary file not shown.

12
src/js/app.js

@ -1,3 +1,4 @@
import { testBoundaries, testCollision } from './collisions.js'
import { drawShape } from './draw.js'
import { makeAstronaut, makeBottomBoundary } from './world.js'
@ -52,5 +53,16 @@ function tick () {
context.clearRect(0, 0, canvas.width, canvas.height)
drawShape(context, bottomBoundary)
drawShape(context, astronaut)
if (testBoundaries(bottomBoundary, astronaut)) {
if (testCollision(bottomBoundary, astronaut)) {
throw new Error('Game Over!')
}
}
if (astronaut.C.y - astronaut.H > canvas.height) {
throw new Error('Should have been caught earlier!')
}
window.requestAnimationFrame(tick)
}

Loading…
Cancel
Save