Sign in to follow this  

something wrong with this function?

This topic is 4285 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
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
If the following does not compile something is wrong, but not in the shown part of the code. What exactly is the error message?

int xpos = 0, ypos = 0;

#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

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

This topic is 4285 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this