Sunday 29 November 2015

Map Implementation

With my final project, one of the aspects I wanted to get out the way was the map. I had planned to do this using the aid of a blog run by Red Blob Games. While I have referenced only the Introduction to A*, I will be using the majority of the blog, starting with a post on Grids and Graphs, and, as the majority of work shown on the blog is Python based, an accompanying A* Implementation guide.

Having taken some time to go over what has been covered in Grids and Graphs, I was concerned that I had proverbially jumped into the deep end. To help me get my groundings again, I decided to look towards YouTube for tutorials that may aid me in map creation. I quickly came across the video Unity3D Simple Tactics Turn Based Game Creation Tutorial by user Paul Metcalf. This tutorial is the first in a seven part series on created a turn based tactics game. I believe this series could help me implement early elements into my game, while allowing me to gain a greater understanding of the code I am working with.

I have followed through the first tutorial, which focuses on creating a grid-based map, and implements a basic movement mechanic
The map, created through a grid, and two player units

At this point, I can now create a square, grid-based map, that can have the width and length set. At this point in time, they use the same number, so will always come out as a square. There are also two player units that spawn on the map, one in the first square available, the other in the last. The game sets the player in the first square as the first player unit; the player can click on a square, and the unit will move towards that square. Once the unit has moved onto the square, it becomes the next units turn, who can do the same.

Below, I have the code I have used fully commented.
This is NOT my own code. All code was taken from the YouTube tutorial above unless stated otherwise in the comments. I have commented all code to both show my understanding of the code and tutorial, and further refine my coding knowledge as a whole.

GameManager.cs
The GameManager class is attached to an empty object in the game, that in this case also holds the lighting and camera as children.



Tile.cs
The Tile class is attached to the square prefab, so that every position on the grid has the Tile class attached.
















Player.cs
The Player class is not set to any object, instead, the UserPlayer class uses it as a parent class.
















UserPlayer.cs
The UserPlayer class is attached to the UserPlayer prefab, allowing any player to move available player units.














One of the main issues I have with this code at the moment, is that while a unit is moving, it is possible to select another tile to move, with the units turn not stopping until they have reached a destination tile. I have overlooked this for now, as I intend to implement higher level coding and pathfinding still.

From what I have done here, there are personal tweaks I am looking at implementing. These include:

  • Disallowing two units on the same space
  • Stopping mid-movement destination tile changes
My next steps though will be to focus on the implementation of classes, and a working Rock-Paper-Scissor combat system.

No comments:

Post a Comment