Jump to content
  • Advertisement
Sign in to follow this  
SKATIN_HARD

something wrong with this function?

This topic is 4499 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



void CheckBounds()

  {


if (xpos >= LEVEL_WIDTH)
{
        {xpos = LEVEL_WIDTH - ship_WIDTH;}

    if (ypso >= LEVEL_HEIGHT)

 	{ypos = LEVEL_HEIGHT - ship_HEIGHT;}
}
}



I can't get it to compile but I don't see anything wrong with it. The error says: expected primary-expression before '=' token. Thanks for any tips.

Share this post


Link to post
Share on other sites
Advertisement
It was but I changed it. The variables are:

int xpos = 0, ypos = 0;

and the defines are:

#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480
#define SCREEN_BPP = 32
#define LEVEL_WIDTH = 1280
#define LEVEL_HEIGHT = 960
#define ship_WIDTH = 84
#define ship_HEIGHT = 63

Share this post


Link to post
Share on other sites
Quote:
Original post by SKATIN_HARD
It was but I changed it. The variables are:

int xpos = 0, ypos = 0;

and the defines are:

#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480
#define SCREEN_BPP = 32
#define LEVEL_WIDTH = 1280
#define LEVEL_HEIGHT = 960
#define ship_WIDTH = 84
#define ship_HEIGHT = 63


You should not put the = in those macros. Also, it is generally considered better practice to use const instead of making macros for constants.

Share this post


Link to post
Share on other sites
First, formatting your code in a way such as this would make it more readable. Second, you have a scope in there that does not really make sense.

Third, there's no = in macros.


void CheckBounds()
{
if (xpos >= LEVEL_WIDTH)
{
xpos = LEVEL_WIDTH - ship_WIDTH;

if (ypso >= LEVEL_HEIGHT)
{
ypos = LEVEL_HEIGHT - ship_HEIGHT;
}
}
}

Share this post


Link to post
Share on other sites
Quote:
Original post by SKATIN_HARD
Took out the "=" and still got the same error. I just want to limit the sprite from going off the screen.


Did you take all of them out?

Share this post


Link to post
Share on other sites
void CheckBounds()
{
if (xpos >= LEVEL_WIDTH)
xpos = LEVEL_WIDTH - ship_WIDTH;

if (ypos >= LEVEL_HEIGHT)
ypos = LEVEL_HEIGHT - ship_HEIGHT;
}

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!