How do I get the player in a platformer to collide with tiles My code for my for loop is
for(var i = 0; i < game.map.length; i++) {
for(var j=0; j < game.map[i].length; j++) {
if(game.map[i][j] === 2) {
drawImage(game.backgroundContext, game.images[0], game.x, game.y, 50, 50);
}
if(game.map[i][j] === 1) {
drawImage(game.backgroundContext, game.images[1], game.x,game.y,50,50);
}
if(game.map[i][j] === 0) {
game.backgroundContext.fillStyle = "#14FFDA";
game.backgroundContext.fillRect(game.x, game.y, 50, 50);
}
game.x += 50;
}
game.x = 0;
game.y += 50;
}
I was thinking to put
if(game.player.y >= game.y && game.player.y <= game.y+height) {
game.player.falling = false;
} else {
game.player.falling = true;
}
inside one of the if its equal to one (0 = background 1=floor)
Anyone have the annswer
Edit Image
(The player goes through the bricks)
Edit Due to downvotes nobody gets the bounty If it gets back to 0 downvotes I will give the bounty away