954,535 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Animation Errors in a C++ allegro game

So, as a project for funzies, I decided to make a basic game where you run around the screen and get into fights when you encounter skeletons. However, I'm nowhere near the fighting parts yet.
So far, the main character only appears when he moves (no idle animation), erases rocks he passes over, and can escape the grid he's on. Here is the code for his motion. The commented out section makes pictures of the character standing pop up in places of the screen faaaar away from his location.

void movePlayer()
   {
   
      tempX = x;
      tempY = y;
   /*   if(!keypressed()) 
     {
       if(direction==1)
    {draw_sprite( buffer, standBack,y * 20, x * 20);}
    if(direction==3)
    {draw_sprite( buffer, standfront,y * 20, x * 20);}
    if(direction==2)
    {draw_sprite( buffer, standright,y * 20, x * 20);}
    if(direction==4)
    {draw_sprite( buffer, standleft,y * 20, x * 20);}
    }
   */  
      if ( (key[KEY_UP] && !key[KEY_LEFT])&& (key[KEY_UP] && !key[KEY_RIGHT]) && map[y--][x] == 3 &&objMap[y--][x]!=101)
      {
         objMap[y--][x] = 100;
         draw_sprite( buffer, runup, x * 20, y *20);              
         direction=1;
      
      }    
           
      if ( (key[KEY_DOWN]  && !key[KEY_LEFT])&& (key[KEY_DOWN] && !key[KEY_RIGHT]) && map[y ++][x] == 3 )
      {   
                
         objMap[y++][x] = 100;
         draw_sprite( buffer, rundown, x * 20, (y) *20);              
         direction=1;
      
      }                  
   
    
                
      if ( (key[KEY_RIGHT] && !key[KEY_LEFT])&& map[y][x ++] == 3)
      {
      
         objMap[y][x ++] = 100;
         draw_sprite( buffer, runright, x * 20, y * 20);
         direction=2;
           
      }
      if ( key[KEY_LEFT] && map[y][x - 1] == 3)
      {            
         objMap[y][x--] = 100;
         draw_sprite( buffer, runleft, (x) * 20, y * 20);
         direction=4;
      
      }
gamerprog
Newbie Poster
6 posts since Dec 2008
Reputation Points: 10
Solved Threads: 0
 

I had the same, but in DirectX. In DirectX I can't seem to get the image scaled that it matches the RECT it uses.
First try to get a bigger RECT, increase it if its too small and decrease when too big. (I don't know IF one uses RECT's with Allegro since I don't know Allegro).

Pynolathgeen
Light Poster
41 posts since Mar 2010
Reputation Points: 29
Solved Threads: 3
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: