Dobrze, znalazłem już odpowiedź, może to nikomu nic nie powie ale zgodnie z regulaminem:
3. Najlepszeodpowiedzi,głosowanie,zgłoszenia,ukrywanie
[...]
3.1.1. W razie znalezienia odpowiedzi w sposób inny niż poprzez pytanie zadane na forum, Pasjonat ma obowiązek podania źródła, z którego uzyskał odpowiedź lub wytłumaczenie, jak do niej doszedł.
Muszę podać rozwiązanie.
Więc zamiast kodu:
for(x=0; x<12; x++){
for(y=0; y<15; y++){
if(mapTiles[x][y]==0){
var rect1 = {x: this.x+this.xVel-(this.sideLenght/2), y: this.y+this.yVel-(this.sideLenght/2), width: this.sideLenght, height: this.sideLenght}
var rect2 = {x: y*60, y: x*60, width: 60, height: 60}
if (rect1.x < rect2.x + rect2.width &&
rect1.x + rect1.width > rect2.x &&
rect1.y < rect2.y + rect2.height &&
rect1.height + rect1.y > rect2.y) {
this.yVel = 0;
this.xVel = 0;
}
}
}
}
Napisałem:
for(x=0; x<mapSizeY; x++){
for(y=0; y<mapSizeX; y++){
if(mapTiles[x][y]==0){
var rect1 = {x: this.x+this.xVel-(this.sideLenght/2), y: this.y-(this.sideLenght/2), width: this.sideLenght, height: this.sideLenght}
var rect2 = {x: y*60, y: x*60, width: 60, height: 60}
if (rect1.x < rect2.x + rect2.width &&
rect1.x + rect1.width > rect2.x &&
rect1.y < rect2.y + rect2.height &&
rect1.height + rect1.y > rect2.y) {
this.xVel = 0;
}
var rect1 = {x: this.x-(this.sideLenght/2), y: this.y+this.yVel-(this.sideLenght/2), width: this.sideLenght, height: this.sideLenght}
if (rect1.x < rect2.x + rect2.width &&
rect1.x + rect1.width > rect2.x &&
rect1.y < rect2.y + rect2.height &&
rect1.height + rect1.y > rect2.y) {
this.yVel = 0;
}
}
}
}
Zamiast sprawdzać kolizji ogólnie sprawdziłem ją w osi x i y oddzielnie.
Wątek zamykam.