Jump to content
  • Advertisement
Sign in to follow this  
McGrane

Need Help With Code

This topic is 4987 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This is the code i have ...

void DrawQuad(unsigned int tex,int x, int y)
{
    
    glPushMatrix();
    glTranslatef(x, y, 0.0f);
    glBindTexture(GL_TEXTURE_2D, tex);
    glCallList(DLID);
    glPopMatrix();

}

.............................................

 void DrawEnemy(int x, int y, int lWall, int rWall)
 {
         
      if(enemWalk==true)
      x -= EWSpeed;
      
      if(enemWalk==false)
      x += EWSpeed;
      
      if(enemWalk==true)
        {
  
              switch(Frame)
              {
              case 0:
                   DrawTransQuad(TEXTURE[28], TEXTURE[29], x, y);
              break;
              
              case 1:
                   DrawTransQuad(TEXTURE[30], TEXTURE[31], x, y);
              break;
              }
    
        }

 
         if(enemWalk==false)
         {

               switch(Frame)
               {
                     case 0:
                          DrawTransQuad(TEXTURE[32], TEXTURE[33], x, y);
                     break;
                     
                     case 1:
                          DrawTransQuad(TEXTURE[34], TEXTURE[35], x, y);
                     break;
         }
     
         if(enemX < lWall)
         enemWalk=false;
      
         if(enemX > rWall)
         enemWalk=true;
      
}

}

.............................................

DrawEnemy(enemX, enemY, 450, 650);



I had this code working , but im now trying to put it together into one function, so that i can use it for more than one Enemy. But it displays the Enemy Quad, and it is animated, but doesnt move? Can someone help me with it ? Sorry about the sloppyness i was copying and pasting snips into the func and editing so its prob a mess Thanks in Advance ;)

Share this post


Link to post
Share on other sites
Advertisement
I think the problem probably has to do with not passing the x and y coordinates of your enemy by reference.

That is, if you declare the function:

void DrawEnemy(int& x, int& y, int lWall, int rWall)
{
...
}


then when you change the x and y values inside the function, they will remain changed when the function returns.

Share this post


Link to post
Share on other sites

if(enemWalk==true)
x -= EWSpeed;

and

if(enemWalk==false)
x += EWSpeed;

only changes 'x' for one pass of the function. if you change 'x' to be a reference, changes to 'x' affect the original variable, and your enemies would probably be moving.

EDIT: i'm too slow typing messages....

Share this post


Link to post
Share on other sites
Yea sound, its moving now, but this part still doesnt work

if(x < lWall)
enemWalk=false;

if(x > rWall)
enemWalk=true;




He just keeps walk :P

Any ideas?

[edit] i got it working, thanks for the help ;)

[Edited by - mcgrane66 on October 24, 2004 4:18:34 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!