Dallin Toth
Tony Qian
April 10, 2015
Computer Science 275 Final Project
Python TD

This simple tower defence game was our final project for this class. We enjoyed working through it and learning about how to use pygame. To start the game just place all the files in one directory, change into that directory and use python3 main.py to call the default map. It is possible to make new maps and enter them in as an argument in the command line but our code only includes this one. Some functionality needs to be added to the bulk of the code. Our main game loop is in main.py and gui.py handles our instance of the gui (buttons, units, placement etc).

Map:
We started by loading a map from the tdmap.lvl file, which is a text file consisting of numbers 0 to 4 representing the tiles we want to place down on our background surface. In our load_level function create a laid out map by blitting the tile images to a map_bg surface, this surface would then be blitted to the display surface when appropriate. While creating this map_bg surface we additionally make a dictionary of the (x,y) coordinates of each tile as the key with the tile type as the value as well as a path_list list with the (x,y) coordinates of each tile that is 1 (rock) that the enemy moves on. The dictionary is used for reference for many things such as what tile the mouse is hovering over so we can determine if a turret can be placed there. We used the path_list in our find_path function for an algorith to compute a path (ordered list of (x,y) tuples) for the enemies to follow. 

Toolbar:
There are buttons for sending the wave, building 3 types of turrets, selling a turret and quitting the game here. If your mouse is on top they will light up and information for the button will be displayed in the red info box right of the toolbar. The red info box left of the toolbar displays money (used to buy turrets), health (decreases when enemies reach the nexus) and the wave number aka the level you got to.

Enemy
This little guy is able to move from our cave toward the nexus along the path that we computed for it. These guys are able to hurt the nexus once they reach the end of the path, they will deduct one from the path and will be deactivated and removed (at the moment the only way to get rid of these units is to allow them to hit the nexus since towers cant attack them). The health of these enemies will increase by 2 per wave and their current health is displayed on top of the unit. Only one will be sent per wave, we originally planned to send multiple and have the number of enemies per wave increase. Fixing this to allow more enemies to be sent would be trivial because we had not yet figured out the targetting system so at the time of the demo date we had not yet succeeded in doing this.

Towers
We created 3 kinds of towers. Each one has different cost and damage (displayed on top of the turret). These can only be placed on a grass tile (no water, dirt, nexus, or the spawn cave), if you hover over a non-placable tile, an 'X' will appear showing that it can't be placed there. You also cannot build a turret on top of another turret, if you try, although an x will not display (we could not come up with an efficient way to compare the cursor position with the x/y positions of all the placed turrets in order to display the hovering x), no money will be deducted and a new turret will not be created.  As of yet we have not been able to create a targeting system for them (range/shooting), so they cannot target/damage the attacking enemies.

Problems we encountered:
One of the difficulties we ran into when building this game was actually learning how to use pygame and understanding all the basic properties of the game engine. It took us quite some time trying to build the map, create the animation effect of a moving enemy, constructing the main hub where you could interact with the game (the toolbar and info display). Also we had trouble in determining a very good algorithm that would find the shortest distance between the beginning and end of the enemy's attack path. Ideally we would want to mimic something like our Dijkstra's algorithm that found the least cost path between start and end. For the functionality of the game We did manage to send a single enemy per wave with its health displayed, however we could not figure out how to send multiple enemies or how to have the turrets target these enemies, and animate a projectile at them. We could create and remove the enemies and turrets using deactive() and activate() which were very useful for creating units, destroying them when they reached the nexus, buying turrets and selling themusing the sell button, however we did not get to have these turrets units interact with the enemy units. We also did not get to implement range for our turrets as we did not get to the point where they could interact with the enemy units, they only possess damage and interact with our economy.