GameDev 2019 Week 2: Towers
Building Towers and Path Finding14.01.2019 - 11:49
Today I started to implement the tower building mechanic. First I added ray casting to figure out which tile of the map is clicked on and while I was at it also added a red or green quad that moves with the mouse and indicates whether the tile is obstructed or not. Secondly I worked on the network messages needed for building and a very simple user interface for building.
Additionally I changed the way the inital player adding was done in multiplayer games, so the game now supports custom player names. And the mapping of client IDs to player IDs was improved, so if 2 players want to play a 4 player map, they may choose to use the slots for players 2 & 4.
Finally I added a simple stats user interface which shows the playing players, how many kills they have and how much money they have - the stats which are displayed may get changed later though.
To simplify the process of creating new towers or changing them I want to make the game as data driven and extendable as I can. Therefore towers are defined in tower blueprint files in json format. Every map will be able to specify a list of tower blueprints it wants to use. So I did the grunt work of creating some classes needed for this, like a TowerBlueprint class, which handles the parsing of the files and stores all the data for a blueprint, or a TowerManager, which will handle most tower related things.
Mostly finished the tower building logic and started with the graphical side of towers. To properly render towers I had to change the map renderer so it can also include other objects into its rendering process, at some point I will have to improve the messy code for all of this, but not today(tm). So I was now able to build and render towers, or rather Treewers or Towees:
Then I added hitboxes and ray casting to the towers and an outline shader when the tower is selected.
To finish the day I made a simple tower model:
I added a model scale to the tower blueprint files, because the towers was as big as the map and I needed a way to scale it easily. I could have changed the scale in blender but I tend to keep models in whatever scale I made them in blender and change them in my programs, because I may want to use models in different projects with different scale requirements, and I dont want to export multiple versions of the same model from blender. I also fixed my edit fields to allow different input modes again, so they now properly support numbers only, alphanumerical characters only and passwords. I then used this new feature and added an edit field to set your own multiplayer name. Finally another file type was added: game data files, I never know what to call things, but these files are what defines a game or a map. At the moment they include the list of all tower blueprints used by the game and also a list of players and a list of waypoints per player.
One of the main features of tower defenses I always liked was the ability to create mazes, so today I added a path finder into the game and a debug renderer to show me the path:
I use A* on the nav mesh of the map. The pink line is the direct output of A* and the blue line is the path with path smoothing applied. The nav mesh has a node on every tile and when a tower is build the node is marked as obstructed and no longer considered by the path finder. The path smoothing had a few bugs at first but after a while it worked properly:
by Christian - 14.01.2019 - 11:49