This week I got the chance to go back and refine my previous project, the Dodgeball game, using functions, objects, and arrays to simplify what was admittedly bonkers code.

I struggled mightily with recreating my vision for the game with the assignment. In preparation for the assignment, I familiarized myself with arrays, objects, translate, and creating my own functions.

While I was able to recreate much of what I intended using this improved code in separate chunks, I failed to put them all together towards my intended outcome. I did not give myself enough time to ask for help when I encountered questions. For example: (1) I’m not sure I understand exactly what counts as a return function; (2) When is more appropriate to use functions versus objects versus arrays? It seemed like all three were useful in refining my Dodgeball code but I couldn’t get it all to fit together.

First I tried to consolidate my code by creating a drawCircle() function to represent the various glowing dodgeballs and using translate() and a for() loop to multiply them across the screen:

Click here for the link to the p5.js editor.

Then I tried to vary their size by using scale() but I couldn’t figure out how to get it to work:

Click here for the link to the p5.js editor.

While futzing with that I realized I could further “clean up” my code by making the balls an object:

Click here for the link to the p5.js editor.

I continued fiddling around, trying to vary the size of the balls using this logic, but ultimately failed to do so in time. I am definitely guilty of waiting to long to start and not having time to ask someone what I was getting wrong. This was as far as I got:

Click here for the link to the p5.js editor.

I finally gave up with this tack and just put all the various values I had made up for the ball coordinates in my original work into arrays:

Click here for the link to the p5.js editor.

I continued to try and vary the speeds of the balls but couldn’t figure out how to do it. I’m also not sure if this fulfilled the requirements of the assignment. Does this count as a return function?

I also made note of the other things I want to apply to this project in the near future:

At one point, I gave up trying to apply the assignment requirements to the Dodgeball game and tried out functions on another project, the Secret Smiley. But even there I wasn’t sure if what I was doing what the assignment was asking of me. I added the drawSmiley function and made it follow the mouse and that was about it:


 Click here for the link to the p5.js editor.

I’d like to try to make it a stamp that stamps a smiley using mousePressed(). I know I saw an example of something like that before but couldn’t remember where. I need to start a repository of code I like so I can easily find it again.

October 16, 2017