Well, first off, it's a lot more effiecient:
PHP Code:
this.x = (keydown(3) - keydown(1));
this.y = (keydown(2) - keydown(0));
playerx += this.x * this.speed;
playery += this.y * this.speed;
PHP Code:
for (direction = 0; direction < 4; direction ++) {
playerx += keydown(direction) * vecx(direction) * this.speed;
playery += keydown(direction) * vecy(direction) * this.speed;
}
Basically here, you're saying "Go by there! Then by here! ... ...", where they can cancel out... 5 right + 5 left = 0 movement. Thus, if you press the right and left movement, you would't move at all... It would prevent calculating one side, then calculating the next.
Other then that, the rest doesn't change much at all...Other then you declared a variable where I didn't. And I used tokenize. Differant ways to proceed.