Sign in to follow this  

A few exercises?

This topic is 3842 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'm still trying to get into the use of graphics with c++, and I've decided to use SDL. I have a book by ernest from gamedev about SDL's functions and capabilities, and whenever I try to put what I read to use, I usually stop working on the project because I feel like I'm not getting anywhere. I was wondering if maybe someone could make up a few exercises or problems to work on using SDL so maybe I could get some program using SDL running and learn it instead of saying I'll learn it and never do it. At first I wanted to make a pong clone, but I don't know how to move the bitmap for the paddles and ball. If I could get a hint about that, maybe that itself could be my exercise to get the basics of SDL going and move on from there into deeper graphics usage. So I'd really appreciate if someone could make up some exercise I could do to learn SDL a little better and put it to use, and maybe help me get the movement of a ball and paddle (moving the bitmaps and in the future learn more about collision testing). Thanks P.S. If you could give me some hints on how to perform a small test if the ball hits the paddle or not, I'd appreciate it a lot :)

Share this post


Link to post
Share on other sites
Palidine is right...since SDL is very popular there are a lot of good tutorials on the net.
But you're looking for some excercises, so I'll tell you what I've done when I started with SDL:

1. I wrote a simple screensaver using basic primitive builtin functions like putpixel, SDL_FillRect. Playing around with surfaces, blitting, resolutions and so on to 'get a feeling for it'.

2. I wrote a simple 'moving pictures' app by displaying a background picture (green ground) and a little picture (maybe 40x40, representing the 'player') and let the little picture move around by using the arrow keys. This should be easy and let's you use/understand the event handling system and displaying pictures. I then expanded the app by using a srccolourkey to render a specified colour blank and by making the 'player' face different directions, according to the direction he's moving in.

3. I wrote an app that can play a sound (wav) by using SDL's builtin sound functions. Then expanding it to a little jukebox, by playing different sounds when different keys are pressed and building functions for manipulating the volume, playing/looping/stopping sounds and displaying title and interpret while the sound is playing. Then expanding it again, to use SDL's MPEG-lib to play mp3's or also mpeg-videos.

4. Now you should be ready for your first framework/engine. Incorporate all the things you've learned from step 1-3 into a neat little framework consisting of different classes for images/sounds/events/... with the functionality to do all the common used tasks with as less effort as possible.

5. When you've finally successfully accomplished that, then use it to write a little game (I wrote a point&click adventure game like GabrielKnight2, Urban Runner, Ripper,...(I don't know how these are called), where you have an image, then click on sth. and then a sound/video is played or some text is displayed. Basically just an interactive movie. This should be really easy now, because your framework/engine handles all the stuff for you and you just have to puzzle it together using the functions built in step 4). Maybe you notice, that your framework/engine isn't complete yet and that you need additional functionality (e.g. I needed: mouse-events, collision detection with 'hotspots', ttf-fonts, inventory, save-/load-functions, level-/chapter-management (and also a few tweaks here and there)).

When everything is done, play your game and think to yourself, that you've really done well. Promote yourself from the SDLnoob- to the SDLuser-level. :P
The framework should now be reusable (with a bit of tweaking of course/or at least parts of it) for any SDL project you'll write, so make sure, that it works properly by extensively testing it for stability and performance (I like valgrind to check the memory usage).


As for your problems:

Moving the paddle/ball bitmap: Just set the new position of the bitmap, blit and update (and do that over and over again).
Collision detection: Check if the bounding rect of the ball is colliding with the bounding rect of the paddle by checking if any coordinates of the bounding rect of the ball are the same as any coordinates of the bounding rect of the paddle.

Share this post


Link to post
Share on other sites

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