Turning
GEOvanne

I'm working on a dragon riding game.
So far I can make the dragon walk left and right and have it walk backwards left or right. I also made it so that when you press DOWN the dragon changes directions.

But what I really want is for the turning animation to be played while turning, I've been trying different things with the code but I just can't seem to get it to work properly.

The laptop I'm working on has no way of getting something off it but my code follows this logic:

#SelectExpand
1while(!key[KEY_ESC]) 2{ 3 if(dir==1)//left 4 { 5 if(key[KEY_LEFT]) 6 { 7 //code to play the left actions in the sprite sheet 8 } 9 if(key[KEY_RIGHT]) 10 { 11 //code to play the left actions backward in the sprite sheet 12 } 13 else 14 { 15 //dragon stand in the left pose 16 } 17 } 18 19 if(dir==2)//right 20 { 21 //similar to left 22 } 23 24 if(key[KEY_DOWN])//turn 25 { 26 //what it used to do was change the dir to 1 or 2 27 } 28 29}

Ok so the problem is with playing the turning animation from the sprite sheet.
Those sprite are in the middle of the sheet, so what I did was (when down is pressed) set 'currentframe' to the start of the animation (frame 7) and have it increment to 9 and set it to the standing pose (0 or 13).
But I just cant seem to pull of this piece properly.

Has anyone of you done something similar to this?

gnolam
GEOvanne said:

I forgot how to do the code tags

See that big button above the reply box that says "Formatting Help"? Click it. :P

Edgar Reynaldo

Code tags use angle brackets, like this : <code>code goes here...</code>

There's a simple animation class for Allegro 4 here if you want to use it. It has support for forwards / backwards / forwards and back animations, once or in a loop. It tells you when the animation is done so you can set a new one. All you have to do is declare an animation, tell it how many frames and how long to run for each loop, set each frame, and then call AdvanceFrameTime when your timer ticks and DrawOn when you need to draw. Since you have several animations, you would probably want to use a pointer to an animation and change what the pointer points to when you change animations.

van_houtte

I suggest you learn to make tic tac toe or a game of rock paper scissors first, you lack basic programming skills :D

Edgar Reynaldo

Don't pay any attention to van_houtte, he's disgruntled because he works overnights and doesn't have any friends.

Arthur Kalliokoski

he's disgruntled because he works overnights and doesn't have any friends.

Not to mention he can't use the tools of the trade...

van_houtte

KLAXXZ GAME MAKER is the tool of the trade ;D

GEOvanne

Well yeah, there IS alot for me to learn, but I have made a rock paper scissors type monster fighting game before :)

I don't have allegro 4. I had 2 computers with a compiler/allegro on it, one is in the shop waiting to be fixed and the other has busted usb ports and got allegro before 4 came out.

But I tried to analyze the animation class that you should me, I changed my code to use switch/case, but now it doesn't even go.

Edgar Reynaldo

If you want help, show code. We're not mind readers.

GEOvanne

Ok, so I finally got it to work. The problem was that I had the down code modeled after the left and right code

 if(dir==1)//left
     {
        if(key[KEY_LEFT]) //looking left and going left
        {
           x++;
           curframe ++; 
           if(curframe > 4)
           {
              curframe =1;
           }
        }

What I did was added a while loop and took out the if statement

//down button (turning action)
if(dir=1)
{
curframe = 4;
while(key[KEY_DOWN])
{
    curframe++;
    if(curframe > 7)//last frame in turn animation
    {
       curframe = 12; //standing facing the opposite direction
    }
}
dir=2;
}

Putting everything in switches helped.

Edgar Reynaldo
GEOvanne said:

What I did was added a while loop and took out the if statement

//down button (turning action)
if(dir=1)
{
curframe = 4;
while(key[KEY_DOWN])
{
    curframe++;
    if(curframe > 7)//last frame in turn animation
    {
       curframe = 12; //standing facing the opposite direction
    }
}
dir=2;
}

Putting everything in switches helped.

You do know that that while loop will almost always result in curframe being 12, and whenever dir equals 1 it will be set to 2 right? That doesn't sound like it does what you want it to.

I think you should take a look at the link to the animation class I posted earlier in this thread. If you use it, your code could be as simple as this :

#SelectExpand
1 2while (!quit) { 3 // draw 4 clear_to_color(buffer , makecol(0,0,0)); 5 current_anime->Draw(buffer , px , py); 6 blit(buffer , screen , 0 , 0 , 0 , 0 , buffer->w , buffer->h); 7 8 // wait until timer ticks 9 while (ticks < 1) {rest(1);} 10 double dt = ticks*(1.0/FPS); 11 12 // update objects 13 int loop = current_anime->AdvanceFrameTime(dt); 14 if (current_anime == &left_to_right_anime) { 15 if (loop == -1) { 16 dir = RIGHT; 17 current_anime = &face_right_anime; 18 } 19 } 20 if (current_anime == &right_to_left_anime) { 21 if (loop == -1) { 22 dir = LEFT; 23 current_anime = &face_left_anime; 24 } 25 } 26 27 // check input 28 switch (dir) { 29 case LEFT : 30 if (key[KEY_DOWN] && !old_key[KEY_DOWN]) { 31 current_anime = &left_to_right_anime; 32 } 33 break; 34 case RIGHT : 35 if (key[KEY_DOWN] && !old_key[KEY_DOWN]) { 36 current_anime = &right_to_left_anime; 37 } 38 break; 39 } 40 41 // update old key array 42 for (int i = 0 ; i < KEY_MAX ; ++i) {old_key[i] = key[i];} 43}

Thread #607832. Printed from Allegro.cc