Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Allegro functions for jumping a character

This thread is locked; no one can reply to it. rss feed Print
Allegro functions for jumping a character
zelda007
Member #12,303
October 2010

Hi,

Based on these sprites :
http://www.tutoworld.com/temp/link_mouvement.bmp

I would like to make my character jumping ;)

For the directions RIGHT and LEFT, I use rotate_sprite function and is works :)
but for the directions UP and DOWN, this function doesn't work.

If there any Allegro function to inclined a sprite ?

Is there another solution .

Thanks :)

jmasterx
Member #11,410
October 2009

allegro is intended to be low level graphics routines. If you want to jump, you have to do it yourself. Like, bool isJumping;

#SelectExpand
1 2void keyDown(Key key) 3{ 4 if(key == JUMP_KEY) 5 { 6 character.setIsJumping(true); 7 } 8} 9 10void logic() 11{ 12 13 character.handleSelf(); 14}

If you want inclined jumping you have to calculate the nornal of your incline (the slope) then find the perpendicular vector and make a unit vector. Then add a multiple of it to the position to jump higher

Explique ton problem en francais j'vais meux comprend.

zelda007
Member #12,303
October 2010

In French :

jmasterx said:

If you want inclined jumping you have to calculate the nornal of your incline (the slope) then find the perpendicular vector and make a unit vector. Then add a multiple of it to the position to jump higher

Pouvez vous m'expliquer en français ?
Je n'ai pas compris ce que tu as dit mais ce que je souhaite faire c'est lorsque le personnage saute en direction UP ou DOWN, il faut incliner le sprite d'un certain pourcentage. (au milieu du saut il se retrouvera les pieds en l'air)
Enfin c'est pas facile à expliquer, il faudrait voir une vidéo :
http://www.youtube.com/watch?v=ExBK7RRuY-E (vers une minute)

If you want to understand my problem, please watch this video :
http://www.youtube.com/watch?v=ExBK7RRuY-E (one minute)

Thanks

jmasterx
Member #11,410
October 2009

Ah ok, la j'comprend mieux.
Oublis ce que j'ai dit avant :p. Enfait, al_draw_rotated_sprite vais fair une rotation par l'angle faque dans les parametres cx, cy, il faut metre les dimensions du bitmap diviser par 2 al_get_bitmap_width(bmp) / 2 = cx, al_get_bitmap_height(bmp) / 2 = cy. Pour dx, dy, ce ci est la position ou il va etre, enfait, ce point va devenir le centre de ton bitmap. Faque c'est ta responsabiliter de trouver ou dx, dy va etre. Pour fair ca il va falouire que tu program un mechanism de sautage. Par exemple, tu peut utiliser des vector pour sa, et avec sa tu poura le controller quand il va etre haut.

zelda007
Member #12,303
October 2010

J'utilise allegro 4.2.3 donc je n'ai pas ces fonctions...
J'utilise rotate_sprite (http://alleg.sourceforge.net/latestdocs/en/alleg014.html#rotate_sprite) qui fonctionne bien pour le saut dans les directions gauche et droite mais pour le haut et bas, c'est une autre histoire.
Bon je sais pas trop ce que je vais faire mais on verra... :D

Trumgottist
Member #95
April 2000
avatar

If this is a private conversation, maybe you should take it to e-mail?

If not… well, my French isn't good enough to follow you, so could you please stick with English? Thanks. :)

--
"I always prefer to believe the best of everybody - it saves so much time." - Rudyard Kipling

Play my game: Frasse and the Peas of Kejick

Evert
Member #794
November 2000
avatar

If not… well, my French isn't good enough to follow you,

Then this is a great opportunity to learn, isn't it? :P

In seriousness though: I think it's fine and great to help people who have difficulty with English in their native language. But please do provide an English translation, both for the benefit of people who don't speak the language and to help them improve their English. :)

zelda007
Member #12,303
October 2010

Oh I'm sorry, you are right !
I'm not good at English but I will try to translate :)

jmasterx said:

Ah ok, la j'comprend mieux.
Oublis ce que j'ai dit avant :p. Enfait, al_draw_rotated_sprite vais fair une rotation par l'angle faque dans les parametres cx, cy, il faut metre les dimensions du bitmap diviser par 2 al_get_bitmap_width(bmp) / 2 = cx, al_get_bitmap_height(bmp) / 2 = cy. Pour dx, dy, ce ci est la position ou il va etre, enfait, ce point va devenir le centre de ton bitmap. Faque c'est ta responsabiliter de trouver ou dx, dy va etre. Pour fair ca il va falouire que tu program un mechanism de sautage. Par exemple, tu peut utiliser des vector pour sa, et avec sa tu poura le controller quand il va etre haut.

Oki. I understand.
Forget that I have said before. In fact, al_draw_rotated_sprite does a rotation by angle thanks to cx and cy parameters, you have to put these parameters with bitmap size and divide per 2. Ex : al_get_bitmap_width(bmp) / 2 = cx and al_get_bitmap_height(bmp) / 2 = cy
For dx and dy parameters, this is the position where the character will be, this point will be the center of the bitmap.
You can use vector to do that and you could control when your character will jump ;)

zelda007 said:

J'utilise allegro 4.2.3 donc je n'ai pas ces fonctions...
J'utilise rotate_sprite (http://alleg.sourceforge.net/latestdocs/en/alleg014.html#rotate_sprite) qui fonctionne bien pour le saut dans les directions gauche et droite mais pour le haut et bas, c'est une autre histoire.
Bon je sais pas trop ce que je vais faire mais on verra... :D

I use allegro 4.2.3 so I haven't al_XXX functions.
I use rotate_sprite (http://alleg.sourceforge.net/latestdocs/en/alleg014.html#rotate_sprite) which works fine for the direction LEFT and RIGHT but not for the direction UP and DOWN.
Have you got any idea ?

You can watch this video to understand my problem :
http://www.youtube.com/watch?v=ExBK7RRuY-E (one minute)

Sorry for our private replies :(

Any ideas ? Thanks

jmasterx
Member #11,410
October 2009

rotate_sprite should in fact work similarly to al_draw_rotated_sprite so you can just substitute parameters that I discussed to get the same result

Dx, Dy, -> destination point
Cx, Cy -> point on bitmap that will rotate around Dx, Dy
angle -> angle of rotation in fixed or radians. (fixed means a circle has 256 degrees instead of 2Pi degrees or 360 degrees)

al_draw_rotated_bitmap(bmp,
Cx, Cy, Dx, Dy, angle, flags);

void rotate_sprite(buffer, bmp, Dx, Dy, fixed angle);

Shouldn't that work? It is supposed to rotate it around its center so you are only responsible for finding Dx Dy which you should do by using a vector to simulate physics and force

for example:

a simple triangle would yield

                   *(200,100, angle = Pi / 4)


*(0,200, angle = 0)             *(400,200,angle = 0)

zelda007
Member #12,303
October 2010

Euh, I haven't any cx, cy parameters but maybe this function is appropriate :

Quote:

void pivot_sprite(BITMAP *bmp, BITMAP *sprite, int x, int y, int cx, int cy, fixed angle);
http://alleg.sourceforge.net/latestdocs/en/alleg014.html#pivot_sprite

But I don't know how to use it... Have you got any example ?

jmasterx
Member #11,410
October 2009

You do not need Cx and Cy for rotate sprite because it already rotates around the center of the bitmap, whereas pivot sprite and al_draw_rotated_bitmap are more flexable and allow for a custom center.

Go to: