Replica of the Tron arcade game.
LightCycle.demo.mp4
This was my contribution to a group project for my first-year undergraduate studies at SUTD. I was responsible for:
- Creating a terminal-based main menu to serve as a 'launcher' for each group member's game
- Creating this game
The rubrics dictate that we use only Python standard libraries. This necessitated building a helper class to handle vector calculations.
Full project (including all other members' work) can be found here.
- Run MainMenu.py in your favourite terminal.
- Type 5 and press the Enter key to select the LightCycle game.
Files for the other games are not included in this repository; they can be acquired seperately here.
- Choose a desired resolution and difficulty level. The difficulty level determines the speed of both players.
- Player 1 (
cyan
) moves using the WASD keys. Player 2 (orange
) moves using the ← → ↑ ↓ (arrow) keys. - To win, make your opponent collide with the map boundaries or any player's "tail".
Pressing Esc quits the game instance.
Function | Description | Parameter(s) |
---|---|---|
choose_option(filename) |
|
String filename Name of text file, in string format (e.g. “settings.txt”). The first line of the text file contains a message to be displayed. Subsequent lines contain the list of options to choose from (one option per line). Each option should have a Displayed value followed by an Actual value, separated by a pipe |. The Actual value should be a callable function/method. |
Function | Description | Parameter(s) | Returned value(s) |
---|---|---|---|
choose_option(filename) |
|
String filename Name of text file, in string format (e.g. “settings.txt”). The first line of the text file contains a message to be displayed. Subsequent lines contain the list of options to choose from (one option per line). Each option should have a Displayed value followed by an Actual value, separated by a pipe |. The Actual value should be a callable function/method. |
NIL |
draw_square(size, colour, x_offset, y_offset, fill=True) |
|
Integer size length of square’s sides String colour colour of square’s outline and/or fill Integer x_offset x position of square Integer y_offset y position of square Boolean fill whether to fill square with colour (defaults to True ) |
NIL |
in_boundary(head, res) |
|
Vector head Vector instance to checkInteger res resolution of game window |
Boolean True if x and y attributes of head are within boundaries, False otherwise. |
render() |
|
NIL | NIL |
main() |
|
NIL | NIL |
Attribute | Description |
---|---|
x |
Instance attribute. Represents the x-component of the Vector . |
y |
Instance attribute. Represents the y-component of the Vector . |
dir |
Instance attribute. A String describing the direction of the Vector . Can be any of the String s from the directions class attribute. |
hash |
Instance attribute. Stores the hash value of the Vector instance, or None if the Vector is not hashed. |
directions |
Class attribute. A List containing the possible dir s a Vector can have. |
unit_vectors |
Class attribute. A Dictionary containing unit vectors as keys referencing their corresponding dir strings. |
Method | Description | Parameter(s) | Returned value(s) |
---|---|---|---|
__init__() |
|
Integer/Float x x-component of the vector. Integer/Float y y-component of the vector. |
Vector instance |
x() |
|
NIL | Instance attribute x
|
x(new_x) |
|
Integer new_x Value to assign to instance attribute x
|
NIL |
y() |
|
NIL | Instance attribute y
|
y(new_y) |
|
Integer new_y Value to assign to instance attribute y
|
NIL |
dir() |
|
NIL | Instance attribute y
|
translate(translator) |
|
Vector translator Vector to be added to self . |
NIL |
rotate(new_dir) |
|
String new_dir Intended dir after rotation transformation is complete. |
NIL |
copy() |
|
NIL |
Vector instance |
__eq__(other) |
|
Vector other A Vector to perform the equality check against. |
NIL |
__hash__() |
|
NIL | NIL |