Rate the code of my game!

Started by
6 comments, last by BigThink 9 years, 5 months ago

I finished this 2 months ago but I feel like I should share it here:

Heres a video of an uncomplete build:



Why not post a video of the finished version? It crashed often, that's why I could not record it to the finish point.

Heres the entire engine if you guys want to download it:
https://www.dropbox.com/sh/ja99dfxbp0opnc1/AADXrhPzdoui1ivcWBdA_s-fa?dl=0
download it as a complete zip file

As for those of you who just want to install and run it:
https://www.dropbox.com/home/zelda%202

This was huge drain on my mind. I just don't feel like coding anymore after this game and haven't even touched C++ since late September.

Take a look at my code and give me some feedback for the last time!

Advertisement

Hmm...looks cool and quite complete, congratz smile.png Only watched the video, but it seems to be really a finished game..


It crashed often, that's why I could not record it to the finish point.

I dont review your code, but this is something you need to work on. Whenever you encounter a crash, stop development immediatly, try to reproduce and try to understand the cause. The latter is the most important part of development, always track the cause of an error, understand it, fix it, continue development (it is really sad how many developers put a try/catch clause around a null pointer exception angry.png ).

It took me a while to find the code, the first thing I have to say is... the .h files are meant to be used for declaration, the implementation should be in .cpp files. You're writing everything together. It works, but it's a really standard practice to separate in 2 files.

You're using a lot of globals, this can create bugs more often and makes bug fixing a lot harder. Try initializing what you need only when you need it, and try sending as a parameter only what an object or method should have access to. For example, look at main.cpp, inside the while loop you're using a "link" variable that's magically there, it's not clear where you created that object.

Code like thise one is confusing:


if(state == titleScreen)
{}
else if(state == fileScreen)
{}
else if(state == overworld)
{

Why check for those states if you don't do anything?

Also, that if/else/if chain is really unmaintainable, there's a lot of repeated code in there and maybe it should be designed around the State pattern.

You're using A LOT of magic numbers, you're using exact pixel values like "1274", it's obvious why you don't want to code anymore, I imagine it was a real pain to test and fix bugs that way. I see a lot of code like this one:


                    //First town
                    if(owlink.sprite.x+owlink.sprite.width > 1216 &&
                       owlink.sprite.x+owlink.sprite.width < 1248 &&
                       owlink.sprite.y+owlink.sprite.height >1216 &&
                       owlink.sprite.y+owlink.sprite.height <1248)
                    {
                        link.linkSprite.x = 96;
                        link.linkSprite.y = 481;
                        link.linkSprite.direction = 1;
                        ChangeState(state, town1);
                    }

It looks like you're doing collision detection the hardest way possible, it would be a lot easier if you model things with a collision box, with all those position and size values as attributes, and make an iteration over all the boxes. I see you have some kind of collision detection for enemies, you can do the same for doors.

Try something like a Door class with x, y, width and height position, and a "nextState" attribute, so you can rewrite that code to something like:


               for (/*iterate over all the doors*/) {
                    if(owlink.over(door))
                    {
                        // I guess all this values are related to each state, so I changed it to a function
                        //link.linkSprite.x = 96; 
                        //link.linkSprite.y = 481;
                        //link.linkSprite.direction = 1;
                        link.setStartingPosition(door.nextState);

                        ChangeState(state, door.nextState);
                        break; //Stop iterating if you changed state
                    }
                }

You also do things like this:


        else if(state == zeldaPalace)
        {
            link.doJump();
            link.attack();
            link.flinchAnim(); 
        }
        else if(state == town1)
        {
            link.doJump();
            link.attack();
            link.flinchAnim(); 
        }

You know you can use && and || operators when writing a condition, right? You should write that code this way:


        else if(state == zeldaPalace || state == town1) // add all the states that repeat this code
        {
            link.doJump();
            link.attack();
            link.flinchAnim(); 
        }

Or you can try with a switch instead of chained if/else code:


        switch(state) {
        // more states with their own block of code
        
        case zeldaPalace:
        case town1: // add all the states that repeat this code
            {
                link.doJump();
                link.attack();
                link.flinchAnim();
                break;
            }
        }

You repeat a lot of code (which makes it redundant) but also comment redundant things that make everything larger than it should. Things like:


                //Draw link
                link.drawLink();

Can be totally avoided, that comment makes it look like it's something you should know before continuing, but then you read the code and it says the same.

Also, talking about redundant things a "drawLink" method on the "link" object could be called just "draw"... if you want to draw link you write "link.draw" and it's already clear enough. And inside the Link class some attribute names start with "link"... "linkCamera", "linkSprite", "linkInput"... just name them "camera", "sprite", "input", they belong to link since you defined those attributes in the class already.

Try to keep comments up to date, or make the code self documented. For example:


//Draws link onto the screen, 1 = right 0 = left
void Link::drawLink()

It looks like you had at a time a parameter on that function that could have a value of 1 or 0. You don't have that, but the comment is still there. If you write self documented code you can at one time have this:


void Link::drawLink(FacingDirection dir)

And a FacingDirection enum with "left" and "right" as valid values, and you don't need a comment. If later you decide to remove the parameter, there's nothing else to update.

Talking about Direction enum, you're redefining that enum in different classes, this enum in particular could be defined in globals.h, once.

There's a lot of repeated code everywhere, and the file distribution makes it harder to understand, I'll stop right now, everything I said happens again and again in every file.

Try cleaning things, avoid repeated code and hardcoded pixel values as much as possible, try thinking more about objects and classes and do some research on common design patterns used in games.

EDIT: Looking at the video it's amazing that you did that much, I suggest you keep coding, you can do a lot more in the same time if you have more practice.

mah eyes they are bleeding!

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max, Watch Dogs: Legion

You probably want to remove those download links unless you have permission from Nintendo to distribute their sprites. (It is never a good idea to post evidence of your own violations on a public forum)
[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

mah eyes they are bleeding!


My code will make you bleed till your demise


You're using A LOT of magic numbers, you're using exact pixel values like "1274", it's obvious why you don't want to code anymore, I imagine it was a real pain to test and fix bugs that way. I see a lot of code like this one:

Quoted for emphasis. Though what I find most obvious, and this is not an insult at all, just a candid observation, is that you're working on a goal well beyond your current abilities. If you have enough perseverance and determination, you can still achieve your goal, but as you've found out, it loses a lot of appeal.

And it really has next to nothing to do with developing in C++. Globals, magic numbers, poor code structure, these will all create code that is painful to work with in any language you choose to develop in.

Being able to relatively quickly refactor code is an underrated ability. It can be very useful in fighting code atrophy. Your code could use a lot of refactoring. It would have little to no impact on the outward appearance of the game, but it could (potentially) significantly improve your motivation to continue working on the project. The video shows promise, you've already accomplished quite a bit with it, but when I look at the code, it's very clear what the source of your 'mind drain' is.

Wow man, I understand how that took lots of energy, but man that is so well done haha, nice!

My new YT channel about game creation is out!!!

https://www.youtube.com/channel/UCGCv7wwpwETEH0kkd_CYlfQ

Exciting stuff to come;)

This topic is closed to new replies.

Advertisement