research collision
This commit is contained in:
@@ -49,9 +49,12 @@ function updateMonster(monster, dt) {
|
||||
|
||||
if (!monster.dead) {
|
||||
updateEntity(monster, dt)
|
||||
console.log('log TILE ', TILE)
|
||||
// ! TILE ist immer nur eine feste Zahl "16"
|
||||
if (
|
||||
overlap(player.x, player.y, TILE, TILE, monster.x, monster.y, TILE, TILE)
|
||||
) {
|
||||
// ! Erklärung wie das hier funktioniert und evtl. eine allgemeine Funktion daraus machen, die prüft, ob etwas Vertikal kollidiert.
|
||||
if (player.dy > 0 && monster.y - player.y > TILE / 2) killMonster(monster)
|
||||
else if (player.vul) {
|
||||
reduceHitpoints(player, 1)
|
||||
|
||||
@@ -22,6 +22,10 @@ function bound(x, min, max) {
|
||||
} */
|
||||
|
||||
function overlap(x1, y1, w1, h1, x2, y2, w2, h2) {
|
||||
// ! Die overlap Funktion gibt immer einen boolean zurück!
|
||||
// * Erklärung: Es wird von allen Seiten geprüft, ob es eine Überschneidung gibt.
|
||||
// bspl: overlap(player.x, player.y, TILE, TILE, monster.x, monster.y, TILE, TILE)
|
||||
// ? Kann ich die erweitern/verbessern mit einer Abfrage ob das zweite Objekt solid ist?
|
||||
return !(
|
||||
x1 + w1 - 1 < x2 ||
|
||||
x2 + w2 - 1 < x1 ||
|
||||
|
||||
Reference in New Issue
Block a user