Sign in to follow this  

[SDL] - need advice on approach to game feature!

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

hi, i would call myself an amateur at SDL and C++..I am currently studying computer games software development at university and currently am creating a game using SDL in a module. It has to be a top-scrolling shooter, for this i am using a repeating background, which when it reaches the end it draws the same background again to give the impression of movement. The problem is i want to when it reaches the boss sprite, lock the screen and set boundaries around this area for the boss fight. So far, the way i have thought of implementing this is by using the keyboard event handling to not let it go beyond certain boundaries when pressing certain keys i.e. case: keydown_up If ship is over -8000 in the y { player cannot move forward } And then carry on much in the same vein. But this is very fiddly and im wondering if anyone could suggest a better approach? thankyou dmaidwell

Share this post


Link to post
Share on other sites
also another quick one...

i need to map the joystick controls for the ps2

I can find the GP2X case numbers for the buttons, but i need the numbers for the ps2 buttons so i can define them in a class and use them in the joystick handling event...i could not find them on the internet when i looked it would be greatly appreciated :)

Share this post


Link to post
Share on other sites
your top question is a bit broad because you do not mention the way you have implemented your game..

As for the second one, looks like you will have to experiment with the ps2 joypad a bit to map the joystick.

regards

cane_ny

Share this post


Link to post
Share on other sites
Your character should never be able to go beyond the limits of the current viewport; that's just good practice in general. The generic version of this is:

(x,y in screen-relative coordinates)
if (x < 0) x = 0;
if (y < 0) y = 0;
if (x > ScreenWidth) x = ScreenWidth;
if (y > ScreenHeight) y = ScreenHeight;


The locking of the screen is more dependent on how you've implemented scrolling, and I think it would be necessary that you elaborate on what your scroll code does at the moment before a solution could be suggested.

Share this post


Link to post
Share on other sites
I have something to add to liquiddark's advice:


if (x < 0) x = 0;
if (y < 0) y = 0;
if (x + CHARACTER_WIDTH > WORLD_WIDTH) x = WORLD_WIDTH - CHARACTER_WIDTH;
if (y + CHARACTER_HEIGHT > WORLD_HEIGHT) y = WORLD_HEIGHT - CHARACTER_HEIGHT;




I've tested this using SDL. Suppose the entire background (aka world) can fit inside a 800x600 window. If you have a surface at x:800 and y:600, then parts of the surface will go off of the screen. So you do need to know the width/height of the surface, so when you move it the surface won't move off of the screen, like I said, use this:


if (x_or_y + CHAR_WIDTH_OR_HEIGHT > WORLD_WIDTH_OR_HEIGHT)
x_or_y = WORLD_WIDTH_OR_HEIGHT - CHARACTER_WIDTH_OR_HEIGHT;

Share this post


Link to post
Share on other sites

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