Skip to main content
GameDev.net gamedev.net
🔒 Locked

my first 2d game, please critisize my code/game

Started by graveyard filla Feb 27, 2004 at 5:40 PM 12 replies 2.8k views
Original Post
graveyard filla
graveyard filla
high, my first 2d game (pong clone with a twist ) is finnally complete. i made it in c++ using SDL. i would REALLY appreciate any feedback (be nice) on the code(ESPECIALLY if you know anything about SDL), i made this from scratch with only help from you guys on this board. if anyone could take a look at the code, and give me (constructive) critisism, i would appreciate it. you can download the .exe and the source here or if thats down click here thanks for all your guys help!! if it wasnt for you guys it would have been much harder to do all this. ps, if you do read the code, try to forgive me when you get to the Draw_Score() function. i know its really sloppy, i hacked it togeather and got to lazy to fix it. works great tho . thanks guys. [edited by - graveyard filla on February 27, 2004 6:41:15 PM] [edited by - graveyard filla on February 27, 2004 12:52:50 AM]
FTA, my 2D futuristic action MMORPG
Charleh
Charleh
lol, that is deeply disturbing :D
Chryzmo
Chryzmo
Haha, that was certainly entertaining.
picklejuice
picklejuice
you''ve certainly taken pong to a new level
oh and could you capitalize the P in pong? I misread the first time, don''t ask
graveyard filla
graveyard filla
did anyone look at the code? its what i was most concerned about. even if you dont know SDL just look and tell me because im doing a similar design to make a pacman clone now. thanks for your comments im glad someone found it entertaining
FTA, my 2D futuristic action MMORPG
Squirell
Squirell
i did pretty much the same thing you did a long time ago so i could probably look at it. But your site started crying about excedding transfer limits...cant look at it tell you get that fixed
Spudder
Spudder
I had a look at the source, couldn't download the .exe for some reason. What i would advide to you is to split the code into different files instead of just the two you have know - perhaps split the code up into classes?

I would recommend splitting the Do_All_Collision() into separate smaller methods which will make it easier for anyone reading your code (and even yourself in a few months time) to see what is going on as a 308 line method is pretty big

EDIT: another slight improvement which will make your image blitting faster is to convert your image surfaces to the screen surface using SDL_DisplayFormat(), this returns a new surface so maybe write an image loading function which could load/convert the surface and optionally set the colourkey at the same time?

[edited by - Spudder on February 28, 2004 12:22:13 PM]
graveyard filla
graveyard filla
hey spudder

thanks for going through my code. i appreciate at least one person helping me anyway, i didnt understand your last comment. what does SDL_DisplayFormat do? and how does it work? more details? what do you mean convert my image surface to the screen surface? i thought you could only have one image at a time on a surface? now im really confused. thanks a lot man. peace
FTA, my 2D futuristic action MMORPG
Greatwolf
Greatwolf
I think what Spudder means is that when you load up the images in your game they don't necessarily use the same color & bit format as your screen surface. So when you actually blit the images onto the screen surface itself, guess what?! It's going to convert the image to the same format as the screen on-the-fly. Now imagine doing this for every frame, you can see where there's unncessary work being done.

If you convert the images to be the same format when you load it off the bat then no conversion is needed later when you do the actual blitting to the screen surface.

Oh and good work. It's a bit disturbing hehehe. Also it would be better if we didn't have to install the game to run it.







--{You fight like a dairy farmer!}

[edited by - Greatwolf on February 28, 2004 7:04:03 PM]
--{You fight like a dairy farmer!}
DeanKnight
DeanKnight
I didn't have a chance to play the game. Your source is commented nicely. I think that it would be a good idea to work on splitting your functions into seperate classes, and C++ files. Basically, start building a library for yourself (such as an SDL_Graphics class, and SDL_Audio, and so on). It would be a good idea to get into a good habit of that before you get into bigger projects, as you may start using similar variable names for different things, and that just gets dangerous. It cuts down on the biggest part of your programming (debugging). In your classes, you have everything given public access. It is usually good practice to keep as much data objects as you can private (like SDL_Surface, xPos, etc.). Functions that are needed outside of the class (such as an SDL_Blit function) should be public. I recommend this way, because you don't want other classes messing with eachothers data, and will cause compiler errors when you write functions that mess with other class' data (which is a good thing, it's telling you that your code needs improvement). Chapters of books are written on this, really, and I couldn't go over all the details (I think I'm confusing you actually), but that's just the long and the short of it.

Also, with keeping stuff like graphics in a seperate class and Cpp file, you make the main game code cleaner, and easier to read. I use a main, just to get my game going, and an SLD_Engine class to put all my SDL Ojects together, and run my game. It doesn't even touch SDL_Graphics data (such as surfaces).

I would suggest learning more about classes, data access, and related stuff. On a small program, stuff like that isn't much of an issue, but could be on bigger projects. Other than that, and other improvents suggested, it all looks good. If you want, I could dig up a program I wrote using SDL that shows what I mean. I made it when I was learning SDL, all it does is move a graphic around. Just let me know where I can mail it or something. [edit] Better yet, just e-mail me, I'll be too busy to come back here much in the next few days, and this thread will most likely be gone (as most that I reply to). My e-mail is my user name on here @hotmail.com (I put it that way to keep spambots from tracing my e-mail, and getting more spam, heh). Give the subject line something easy to notice too (like lots of /////////////////////////////// or something).

I also didn't notice any methods that released your resources either (SDL_quit, or something, I believe it is, and just to be safe use atexit(SDL_Quit);, check the intro tutorial in the SDL reference, it should say). If you already have that last bit in there, forgive me, I just got off work, and it's late =oP. If you ever move on to DirectX, this is very important, as your program will cause memory leaks.

[edited by - DeanKnight on February 29, 2004 4:47:45 AM]
graveyard filla
graveyard filla
hey, thanks for reading my code. i actually didnt notice this untill today when i was testing the game on a friends computer. the ball moves at a non=steady rate, meaning the ball kind of jerk's along its path. i couldnt notice this on my computer i guess because its so fast and it was just doing it too fast to notice.

also, i know whats caused this problem. when i made my game frame-rate independant, i changed the way movement works, including making coordinates floats. could this maybe the cause of it? im not sure why this is happening... maybe it needs to be whole numbers..... hmm

also you can email me that source to graveyardfilla@hotmail.com thanks

[edited by - graveyard filla on February 29, 2004 4:53:01 AM]


ps- just playing the game on my computer i really cant see this jerking, im thinking maybe its just her gfx card or something? does anyone else get this, or was it just that computer? let me know, thanks

[edited by - graveyard filla on February 29, 2004 4:59:26 AM]
FTA, my 2D futuristic action MMORPG
arm
arm
Hehe, nice one mate. Bloody funny.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.