Helicopter Game

Published October 10, 2017

It was during an incredibly off-topic venture onto the internet of 2002 during a middle school math class that I first remember seeing the “helicopter game” – a game in which players control a helicopter’s lift as the game side-scrolls through a cave of sorts, replete with stalactites and stalagmites (which the player must avoid at all costs).  A cursory google search did not reveal the original, but I have attempted to recreate the original in P5.js.

I started by defining two classes for the main gameplay elements: Heli(copter) and Wall. Heli(copter) proved to be rather simple, with the only non-obvious function being one which returned true if the helicopter was inside of one of the walls.  The helicopter experiences ‘gravity’ in the form of a downward acceleration which the player must counteract with the spacebar.  The Wall class was slightly more complex in that it needed to side-scroll the game along.  Each Wall object also had a function which returned true if it had left the screen, which allowed me to cull these objects from the wall list in the main sketch.js of the program.  Finally, the main sketch.js contained the core functionality of the program, including the controls and gamestates (isFirstGo and gameOver).

As each element I added to the program required changes and re-organization of the previous elements, the importance of physical code organization: white space and proper commenting, as well as logical code organization: which functions are contained within which other functions or objects or on their own, became readily apparent.  To abstract away complexity with classes and functions requires that they are truly independent.  I often found interconnections I didn’t realize existed because I failed to restate a stylistic function (rectMode or fill, etc.)  in each display function.

Below is my sketch.js code, with questions at the top.  The full code can be found here at the P5 editor.

https://gist.github.com/AidanNelson/5a5d90fd9be049eba7b6f9a679bd73dd