The start of my city builder prototype was to get a tilemap in place so players had a map to work with, plus a tile-based grid makes it easier to build a more ordered city. Getting the tilemap logic in place was fairly easy and was drawing coloured tiles fine, but it had some issues loading images, after some digging I found out that I needed a load handler in place to handle image drawing, so a few alterations made the code work with images too, so with this in place, I could work on the main focus of the prototype.
The building mechanics were initially simple to implement, I started with some event listeners for mouse clicks and created a boolean to check if a player is building, to test this I created a road and house asset that would change a tile on the map to the item that the player selects with a button on the webpage. Of course I needed the boolean to activate something, so I created an if statment in the render function that calls a building function if the boolean is true which did the trick for basic building.
The tricky part came when creating roads facing different directions, I originally planned to create a unified ‘smart’ road tool, but after some trial and error, it seemed out of this projects scope to implement well so I scrapped this system in favour of a rotate key that rotates pieces that the player chooses. With this I implemented an icon on screen that shows the current rotation to improve the user experience.
The final piece of the main building mechanics was a click-drag to make building lots of things easier, this was easier than I anticipated as it only required another event handler and a couple of changes to where the building boolean is called. Since this was rather quick, I used my extra coding time I allocated to adding some more buildings to the game which was some simple copying of code and drawing some new assets which gave the player some more choices when making their city.
With the main things in place this week, I can focus some more on polishing and adding some challenge elements next week to finalise the prototype, so I am pleased with my progress this week.