Exercise: Handheld Game in Tinkercad¶
In the 1970s new microprocessors and digital logic enabled a generation of handheld electronic games before the advent of microprocessors powerful enough to operate LCD matrix displays. Some examples: Milton Bradley Simon, Parker Brothers Merlin, Mattel Football.
Tinkercad lacks mechanical hardware but has enough electronic I/O components to support creating simple electronic games. This exercise will explore all aspects of game development, including game design, circuit design, software design and implementation, and playtesting.
One strong hint: please start with a well-defined, simple game idea. It is easier to elaborate a working design than start with complexity.
As a reference, I have provided a complete working code and circuit sample, please see RockPaperScissors Arduino Sketch.
After this exercise, you should be able to:
Design a simple real-time handheld game.
Implement low-latency processing of asynchronous inputs and events using event-loop and state machine structures.
Write code using parameterized functions to implement action primitives.
Write code with integrated debugging using the serial port for user console communication.
Please review the following reference guides as needed:
Creative Constraints and Opportunities¶
You may use any components available in Tinkercad. However, you are strongly encouraged to start with the components we have already encountered: pushbuttons, slide switches, hobby servos, LEDs, and piezo speakers.
Please think in terms of tangible game experience. Yes, there is an LCD display component, but a purely text-based game misses the point.
Please remember games may be real-time or turn-based. In either case, timing and pacing are important elements of game design.
Scorekeeping is optional.
The game should be single-player, either a solitaire puzzle or against an active computer opponent.
Alas, there is no coin acceptor component.
Steps and observations¶
The overall objective is to create a interactive game. The following checklist will guide you through building a circuit and program to submit within a single Tinkercad sketch.
Please start with by choosing a game concept. A clear idea at the beginning will focus the rest of the work. It’s fine to adopt or adapt an existing game idea.
Plan out the essential features in advance: game play sequence, user inputs, visible and audible outputs.
Construct a circuit with the input and output components as per your design. Be sure to remember to use pullup resistors on your switches and ballast resistors on your LEDs.
Set up the shell of a text-based Arduino program to support your hardware, e.g. initialize the Serial port, initialize the output pins.
Add temporary code to test your inputs and outputs. At this stage it is helpful just to print values to the Serial port.
Set up the essential run loop. I suggest using a real-time event polling loop as I have provided in the sample, it is a versatile structure. But some games may only require a scripted sequence; for these I recommend looking at the
cond_delay()function in the Lecture Sample Code, it provides a suggestion for incorporating low-latency polling into a scripted sequence.
Incrementally add the game logic, testing at each step. Please add debugging output to the Serial Monitor as needed.
Please be sure to include user instructions in comments at the top of your code.
The result of your explorations should include:
a single circuit sketch including code, submitted as a URL to Canvas
a brief paragraph describing your game intent and outcome, submitted as text to Canvas
When it is time to submit your result for the assignment, you’ll need to click Share, then Invite people. You may then copy the generated sharing URL and submit it to Canvas.
N.B. As of Fall 2020, Tinkercad has a sharing bug, please note the following. Tinkercad Circuits sketch sharing links which include the term ‘tenant=circuits’ appear consistently to return a 404 error instead of accessing the sketch. The first workaround appears to be to exit and reload the sketch at least once before generating the share link. Alternatively, an existing link can be fixed by editing out the tenant=circuits clause, e.g. delete the text ‘?tenant=circuits’.
If you would like to explore more, please consider the following optional challenge questions.
Try adding an ‘attract mode’ to garner attention between plays.
What’s the most subtle way for the computer to cheat?
Could you have implemented your game purely in circuit logic without the Arduino?