3 Answers
3

idea is to test only upper-left point and bottom-right point, which should be ok 99.99999% of the time.
(Rq : i know we could test wether the second test is in fact about the same tile, but i guess that would be slower).

Thanks for the insight regarding testing the upper left and bottom right! I am using the delta time in my actual game. The demo was just a quick one that I mocked up for you guys :)
–
Oliver BarnwellAug 19 '14 at 1:22

3

@OliverBarnwell You'll get better code reviews by not mocking up code for your question.
–
James KhouryAug 19 '14 at 1:24

I'd have thought it would've been helpful to help describe the situation? I do admit that I should've made sure my code was more to the point. For that I apologise.
–
Oliver BarnwellAug 19 '14 at 1:27

1

@OliverBarnwell If you read the faq: On-Topic It says to keep the original code intact.
–
James KhouryAug 19 '14 at 1:29

Thanks! Interesting to shift it by 0 :D I assume something like ~~ would work too :)
–
Oliver BarnwellAug 19 '14 at 1:25

@OliverBarnwell I hadn't thought of that. Might be worth a try but I'd guess thats two operations where as bit shifting is one (I think I will test out that theory sometime).
–
James KhouryAug 19 '14 at 1:27

1

Why not do x /= 20; y /= 20; at the start of the function? Also ciel should be ceil.
–
mjolkaAug 19 '14 at 1:53

x /= 20; y /= 20; would only save you one inexpensive operation. Not that it would hurt either. 6 one way, half a dozen the other way.
–
James KhouryAug 19 '14 at 5:22

I'm sure there's a way to simplify these checks, but I will leave that to someone more experienced to comment on.

if(checkmove(pos.x, pos.y-2)) {
pos.y -= 2;

The reader is left to wonder what the significance of 2 is here. You should define it in a variable so we explicitly know what it means. It is important to make your code self documenting so that it is easier to understand.

if(checkmove(pos.x, pos.y-2)) {
pos.y -= 2;
break;
} else {
break;
}

There has to be a cleaner way to implement input than if/else statements and breaks inside of a switch statement, but I do not know Javascript well enough to write the code for you. You should be using an onbuttonpressed event in the browser to call the function if I am not mistaken.

Also I did take a quick look at the full game that you linked to. I encourage you to post more of that code for review!