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

Started by
3 comments, last by RazeDev 16 years, 4 months ago
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
Advertisement
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 :)
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
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.
No Excuses
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; 

This topic is closed to new replies.

Advertisement