Page 1 of 1

contact box

Posted: Thu Nov 13, 2014 4:09 am
by elsalvador
Can someOne help me solve this small problem..
my collision fails!! when they are in contact they work using one button but
if use 2 buttons at same time it fails?
Goal is: don't want the box to go through the other at all!

Re: contact box

Posted: Thu Nov 13, 2014 11:51 am
by kraftman
The problem is probably that you're storing the direction the player is moving in a single variable, so if they are moving both down and left then only one of those things will be assigned to l.s and checked against foe.

I'd recommend moving the collision detection of the player into the player file, scrapping the direction storage and instead just work out a new x and y coordinate, and then calculating if that new position would result in a collision with any object.

Also bear in mind that code is read a lot more than it is written, it might seem easier and quicker to write variables like "l.s" but when things get more complex, or when you come back to the code a month later, you'll wish you'd used "player.direction". As a bonus searching for "player" will return a much narrower set of results than "l"

Re: contact box

Posted: Fri Nov 21, 2014 4:13 am
by elsalvador
I'd recommend moving the collision detection of the player into the player file, scrapping the direction storage and instead just work out a new x and y coordinate, and then calculating if that new position would result in a collision with any object
So what is the difference? having it under player? and not under foe.file????
I am confuse now!