Posts

Showing posts with the label tile

how can I detect collision in a 2D tile game map

how can I detect collision in a 2D tile game map I made this basic game where I drew a map and a player, the player can move anywhere but how can I make so that it wont move when its on the tile[1] in the map? also when I try to check if the player.x is greater than 50 it could go left it works but than if I click 2 keys at once it goes through const context = document.querySelector("canvas").getContext("2d"); var rgb = 'rgb(' + Math.random()*256 + ',' + Math.random()*256 + ',' + Math.random()*256 + ','+Math.random() + ')'; document.onload = Loop(); var width = 1500; var height = 800; function Loop(){ var width = 1500; var height = 800; context.canvas.height = height; context.canvas.width = width; this.interval = setInterval(Update, 1000/100); } const Player = function(x, y, w, h, color) { this.x = x; this.y = y; this.w = w; this.h = h; this.speedY = 0; this.speedX = 0; this.Draw = function(){ context.f...