Making a game with functions

This week in Computational Media, we dove into functions and arrays. They really start to open up the possibilities of what can be done in code. For an assignment, we were tasked to rewrite one of our old assignments with functions, but I had already started to do that, so I decided to write a new game.

This past week, I went to an art exhibit that featured work inspired by the show Bob’s Burgers. It’s one of my favorite cartoons, and so I created a game in which Gene Belcher eats a bunch of hamburgers.

I really liked this assignment, as it gave me ample practice dealing with functions and arrays. The hamburgers are created in a separate function and initialized into an array with a constructor function. You can check some of the code here:

burgers_in_array

The most difficult part of this assignment was constraining the eyes and mouth within Gene’s face and eyes. I tried to map mouseX from 0:canvas width to the width of Gene’s face, but it did not work for some reason. I even tried to use constrain for a while, and it took me a long time to realize that my constrain function was just not being called in the correct place. So I put a constrain function at the start of my draw function, which accomplished the functionality I was achieving for.

eyes_malfunction

Take a look at the game and play around with it. I hope it’s a little fun for you guys, and let me know if you have any feedback!