Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Using keyboard all over the place

This thread is locked; no one can reply to it. rss feed Print
Using keyboard all over the place
kebapmanager
Member #14,863
January 2013
avatar

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
Member #934
January 2001
avatar

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Ā 
Member #10,584
January 2009
avatar

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

kebapmanager
Member #14,863
January 2013
avatar

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Ā 
Member #10,584
January 2009
avatar

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

kebapmanager
Member #14,863
January 2013
avatar

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

LennyLen
Member #5,313
December 2004
avatar

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
Member #14,863
January 2013
avatar

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

ph03nix
Member #15,028
April 2013
avatar

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.

Go to: