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. You can watch the original 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 also find slides 477-518 in the slide presentation helpful.
- Move background to
setup(), declare two variables forxandyand initialize each to 200. Change the background color to blue, and make a slightly smaller black rectangle inside of it to make the light cycle arena. - In
draw()set thestroke()to white and then draw apoint()at (x,y). After that, increasexby 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() {
var 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
gameOvervariable at the top of your program and intialize it tofalse. - Add an
ifstatement to check ifnotBlack()istrue. If so, display a "GAME OVER" message. and setgameOvertotrue. - Add another
ifstatement above the previous one. IfgameOveristrue, thenreturn; - Replace the code in
draw()that makesxone bigger with fourifstatmeents
- If
directionis 37, makexsmaller by 1 - If
directionis 38, makeysmaller by 1 - If
directionis 39, makexbigger by 1 - If
directionis 40, makeybigger by 1
- Add a
function keyPressed()that changesdirectionto matchkeyCode. That is:
- If
keyCodeis 37, setdirectionto 37 - If
keyCodeis 38, setdirectionto 38 - If
keyCodeis 39, setdirectionto 39 - If
keyCodeis 40, setdirectionto 40
- Run the program. Once a person clicks on the screen, the light cycle should now be able to turn with the arrow keys
- There is a video lesson on the above steps: Starting the tron assignment
- 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.
If you have completed the above steps and are having a problem with your tron game on a Chromebook where the game ends everytime you turn left or up, try making these changes:
- Reduce the frame rate to half speed in
setup()by callingframeRate(30) - Increase the stroke weight to 2 by calling
strokeWeight(2)
- In
draw()move the light cycle by 2 pixels instead of 1
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! Possible extensions inlcude:
- 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!)
Cali
Audrey
Damian
Leah
Irisa
Elliot
Josh
Emely
Tiffany
Juan
Elvin
Ben
Justin