update research collision

This commit is contained in:
StrangeD0s
2023-02-19 17:25:18 +01:00
parent a8fe40fd19
commit 09e4c2dc4b
2 changed files with 10 additions and 8 deletions
-3
View File
@@ -193,9 +193,6 @@ function main() {
// ! Vielleicht kann ich statt des setup() an dieser Stelle auch eine gameStart() Funktion erstellen, die beim erstmaligen Start alles erledigt. Später wird dann ja immer die _initLevel() aufgerufen. // ! Vielleicht kann ich statt des setup() an dieser Stelle auch eine gameStart() Funktion erstellen, die beim erstmaligen Start alles erledigt. Später wird dann ja immer die _initLevel() aufgerufen.
setup(currentLevel.levelData) // ! Was brauche ich hier, damit das variabel alle Level laden kann? setup(currentLevel.levelData) // ! Was brauche ich hier, damit das variabel alle Level laden kann?
//console.log('log monsters ', monsters)
console.log('log updateVehicle ', vehicles)
frame() frame()
} }
+10 -5
View File
@@ -49,7 +49,7 @@ function updateMonster(monster, dt) {
if (!monster.dead) { if (!monster.dead) {
updateEntity(monster, dt) updateEntity(monster, dt)
console.log('log TILE ', TILE)
// ! TILE ist immer nur eine feste Zahl "16" // ! TILE ist immer nur eine feste Zahl "16"
if ( if (
overlap(player.x, player.y, TILE, TILE, monster.x, monster.y, TILE, TILE) overlap(player.x, player.y, TILE, TILE, monster.x, monster.y, TILE, TILE)
@@ -354,8 +354,6 @@ function collectTreasure(t) {
} }
function updateEntity(entity, dt) { function updateEntity(entity, dt) {
entity.vehicle && console.log('log entity ', entity)
var wasleft = entity.dx < 0, var wasleft = entity.dx < 0,
wasright = entity.dx > 0, wasright = entity.dx > 0,
falling = entity.falling, falling = entity.falling,
@@ -420,13 +418,20 @@ function updateEntity(entity, dt) {
ty = p2t(entity.y), ty = p2t(entity.y),
nx = entity.x % TILE, nx = entity.x % TILE,
ny = entity.y % TILE, ny = entity.y % TILE,
cell = tcell(tx, ty, mapWidth), //! Was ist das hier? cell = tcell(tx, ty, mapWidth), //! Prüft ob eine Cell oben oder links angrenzt
cellright = tcell(tx + 1, ty, mapWidth), cellright = tcell(tx + 1, ty, mapWidth),
celldown = tcell(tx, ty + 1, mapWidth), celldown = tcell(tx, ty + 1, mapWidth),
celldiag = tcell(tx + 1, ty + 1, mapWidth) celldiag = tcell(tx + 1, ty + 1, mapWidth) // ! logischerweise muss das prüfen, ob eine Cell unten rechts angrenzt
// ? Ist das hier der Collision Check? // ? Ist das hier der Collision Check?
// entity.player && console.log('log cell ', cell)
// entity.player && console.log('log cellright ', cellright)
entity.player && console.log('log ny ', ny)
// entity.player && console.log('log celldiag ', celldiag)
// ! Die Collision prüft einfach nur, ob an den Player eine Cell angrenzt (!0) oder nicht (0).
if (entity.dy > 0) { if (entity.dy > 0) {
if ((celldown && !cell) || (celldiag && !cellright && nx)) { if ((celldown && !cell) || (celldiag && !cellright && nx)) {
entity.y = t2p(ty) entity.y = t2p(ty)