Tron was a Disney movie that was released in 1982. It was one of the earliest feature films to reflect the video-game craze of the 1980s. Jeff Bridges stars as a computer programmer who becomes part of the very game that he's programming. The game is a "light cycle duel". Your light cycle races across the arena leaving a trail of laser light behind you. Light cycles can only make 90 degree turns. Touching a laser trail destroys a light cycle, so you try to drive your opponents into a light trail while avoiding the trails yourself. (Watch the Tron light cycle scene on YouTube) There are many examples of the tron light cycle game on the internet, one is at http://www.fltron.com/.
You may find slides 23 - 38 of the Functions, Algorithms and Abstractions presentation and/or this video helpful in completing the following steps.
- Move background to
setup()
, declare two variables forx
andy
and initialize each to 200. Change the background color to blue, and make a slightly smaller black rectangle inside of it - In
draw()
set thestroke()
to white and then draw apoint()
at (x,y). After that, increasex
by 1. Run your program. You should see a small white dot in the center of the screen move to the right leaving a trail behind it. - Copy the following
notBlack()
function into the bottom of your program. Make sure it not inside the curly braces of another function.
function notBlack() {
let a = get(x, y);
if (a[0] != 0) return true;
else if (a[1] != 0) return true;
else if (a[2] != 0) return true;
return false;
}
- Declare a
gameOver
variable at the top of your program and intialize it tofalse
. - Add an
if
statement to check ifnotBlack()
istrue
. If so, display a "GAME OVER" message. and setgameOver
totrue
. - Add another
if
statement about the previous one. IfgameOver
istrue
, thenreturn;
- Replace the code in
draw()
that makesx
one bigger with fourif
statmeents
- If
direction
is 37, makex
smaller by 1 - If
direction
is 38, makey
smaller by 1 - If
direction
is 39, makex
bigger by 1 - If
direction
is 40, makey
bigger by 1
- Add a
function keyPressed()
that changesdirection
to matchkeyCode
. That is:
- If
keyCode
is 37, setdirection
to 37 - If
keyCode
is 38, setdirection
to 38 - If
keyCode
is 39, setdirection
to 39 - If
keyCode
is 40, setdirection
to 40
- Run the program. Once a person clicks on the screen, the light cycle should now be able to turn with the arrow keys
- Add a
mousePressed
function that increasesdirection
by 1 with a right click and decreases it by 1 with a left click. - At this point you should have a working single player game. You should be able to operate the light cycle with either the keyboard or mouse
Once you get the basic single player game working, you can start adding other features. Your tron game doesn't have to look or work like any other, have fun and be creative! Slides 39 - 58 of the Functions, Algorithms and Abstractions presentation have more information on possible extensions like:
- Added graphics for collisions
- Added obstacles or a maze to make the game more challenging
- A timer that increases the score the longer the player avoids crashing
- The ability to restart the game
- Turbo mode and/or power ups to move the light cycle faster
- Self driving mode where like a self driving car the light cycle automatically avoids obstacles (you may find this video helpful on making an autonomous tron light cycle)
- A two player game where one person uses the mouse and the other uses the keyboard
- A computer opponent (or even multiple computer opponents for real craziness!)