I've tried everything I could think of, and I still can't get the onwall checks to be correct:
PHP Code:
function onTimeOut() {
if (this.distgone < this.dist) {
temp.x = this.x+1; temp.y = this.x+1;
temp.dx = temp.x+(this.velocity*cos(this.anglex));
temp.dy = temp.y+(this.velocity*(-sin(this.angley)));
temp.dir = getdir(temp.dx-temp.x, temp.dy-temp.y);
if (!onwall(temp.dx,temp.dy)) {
this.x += this.velocity*cos(this.anglex);
this.y += this.velocity*(-sin(this.angley));
this.distgone += this.velocity;
this.velocity = (this.velocity/5)*4;
}
else {
temp.bx = onwall(temp.dx,temp.y);
temp.by = onwall(temp.x,temp.dy);
if (temp.bx && temp.by) {
this.anglex = pi - this.anglex;
this.angley = this.anglex;
}
else {
if (temp.bx) this.anglex = pi - this.anglex;
if (temp.by) this.angley = pi - this.angley;
}
temp.dx = this.x+1+(this.velocity*cos(this.anglex));
temp.dy = this.y+1+(this.velocity*(-sin(this.angley)));
if (!onwall(temp.dx,temp.dy)) {
this.x = temp.dx-1;
this.y = temp.dy-1;
this.distgone += this.velocity;
}
this.velocity = (this.velocity/5)*3;
}
if (this.velocity <= .005) this.dist = this.distgone = 0;
else setTimer(0.05);
}
}
I only have the angles split into x and y because of checking if it's hitting a wall vertically or horizontally. That's the only way I could think of doing it.
This is really starting to frustrate me.