Using keyboard all over the place
kebapmanager

I am currently doing collision ,and I need to chechk if any of keys on keyboard is pressed at that moment ( bassicly , if it is I stop chechking my collision since I dont know better way to handle my collision) , but since this part of code is out of "main" I cant use those " keys[RIGHT]" variables if I can call them that way. Could anyone give me better solution then making one global boolean variable to chechk this .

DanielH

You can get the keyboard status at anytime. Are you using Allegro 4 or 5?

//In allegro 4, 
if ( key[ ... ] ) ...

//In allegro 5
ALLEGRO_KEYBOARD_STATE kbdstate;

al_get_keyboard_state( &kbdstate );

if ( al_key_down( &kbdstate, ... ) ) ...

taronĀ 

I see no good reason to depend on the user input while handling collisions.

kebapmanager

I am using allegro 5 , tnx for that it was really dumb for me , but I forgot that was possible ...

Yes I know its really dumb to make your collision keyboard dependete , but I ahd huge issues on handling collision , like I dont know what to do once collision is detected , so I just started using some random things , and I got it working .... ( I am not satisfied with is , but after a month of trying to get it work properly ,I dont even care anymore ... just to have it working .. :/ )

taronĀ 

Just keep track of the direction your entity is moving or the previous position. That ought to help resolving collisions.

kebapmanager

Yes I know , but Wht should I do when collision happens? , set speed to 0 ? or just set players cordinates?

LennyLen

but Wht should I do when collision happens? , set speed to 0 ? or just set players cordinates?

We can't answer that question because we don't know what sort of collision detection you are doing, or what you are trying to achieve.

kebapmanager

Well its just simple super mario stlye collision , its a platformer game so you get the idea what I want :/

ph03nix

It's an involved process to explain how to program mario style collisions, even though it's relatively simple.

I suggest you read a tutorial like this one. It's written for flash, but the logic remains the same.

Thread #612843. Printed from Allegro.cc