LazyFoo's Per-Pixel Collision Tutorial (SDL)

Started by
2 comments, last by Motoky 10 years, 10 months ago

I have been working through these tutorials for a while now. I have been stuck a few times, but managed to overcome it on my own or through some very helpful posters on here.

I have the program all and running. The program displays to circles of the same size and you are meant to move one circle towards the other and they will collide together. Once they meet, the circle stops.

The problem I am having is with keyboard input. I've got it working in previous tutorials, but I have been slowly changing my code to spread across multiple header files and source files to make it easier to read.

I can't upload the project because it's too big as a whole. I also have trouble getting code to appear properly without it looking like a mess and readable on here.

I guess I will upload an image of each section that I am having trouble with.

Okay, from the image. The first section is where I poll for events. I then try to retrieve input for my dot object. I send that same Event structure to the function which is shown in the second section. It checks for the key down event and checks the type of key that was pressed and increases or decreases the velocity of the circle depending on the key that was pressed. It also checks to see if that key was released and then sets the velocity to 0 making the circle stop moving. Again, if nothing was pressed, it goes back to the first section and checks to see if the type of event was a quit event, control is returned to the main function in the third section.

In the third section, if the function returned false, quit becomes true and the program exits. This event works, it quits when I press on the 'X'. If I didn't press 'X', the program should return control to main and move the circle as shown in the function moveSprites(), clears the screen to white, displays the circles, flips the back buffer and caps the frame rate to 20 FPS.

It seems like a lot to follow, but for some reason, the circle just isn't moving. I've been through my code a hell of a lot and I can't see what the problem is. I've compared it to a previous SDL project and I've only changed a few things, and all I have done is handled all of my input inside the SDLManager class. I've even tried changing this project to closely match my previous project and it's still not working.

Advertisement

Nothing stands out to me at first glance. Have you tried going through it line-by-line with a debugger?

The only thing that's catching my eye is that LazyFoo's dot->handleEvents() doesn't take an argument, while yours passes the event. It doesn't look wrong though :( is there any way you could zip the code files and email them to me at my username at gmail.com and I'll see if I can do some more in depth debugging. I feel there could be something useful to learn by finding out why this doesn't work.

Yeh I can email it to you. Just make sure you have SDL all set up though.

PM me your Gmail.

Cheers.

This topic is closed to new replies.

Advertisement