CodingTrain / Suggestion-Box

A repo to track ideas for topics
570 stars 86 forks source link

Help improving game efficiency / possible coding challenge #1405

Open MegaminxCode opened 5 years ago

MegaminxCode commented 5 years ago

Hey The Coding Train,

I've been following your tutorials and using your javascript library p5js.

Using the knowledge I could find I began making a clone of a puzzle game called BaBa is you for educational purposes.

I feel like theres too many if statements and for loops.

I was wondering if there were any tips you could give me to improve its efficiency / declutter it. And maybe in the process find something to help others and do a video on.

On another note I also think doing a coding challenge on this game would be interesting as its similar to other coding challenges you've done in the past with a bit of a twist.

heres a link to my code https://github.com/MegaminxCode/BaBaisYouClone

here is a link to the steam page of the game https://store.steampowered.com/app/736260/Baba_Is_You/

jonnytest1 commented 5 years ago
  1. you should definitely get a code formatter - its not very easy to read code if the brackets are all over the place.
  2. if you want to have your code reviewed its not helping to have random unused methods in there (mousePressed) for making your if more uncluttered :

    1. try thinking about the ifs in terms of dependencencies for example : does the player==true check depend on the key ? no so move it above the keychecks
    2. on top of that its usually more practical to turn directions into vectors that way you can just add them to the player position to achieve most goals
    3. another piece of advice that makes your code prettier and easier to understand is : you dont need an else clause if your if clause has a return at the end
    4. all in all 'install a good linter :P'