This week I’ve been doing several things, but the most difficult task in my eyes was to do a slight rewrite of another persons class. It’s not that the code that I had to rewrite was bad from the start, it’s just that it was writtenwith singleplayer in mind and we’re doing a multiplayer game where the server is doing all the calculations. This task was about getting the Commander to work, which is the last piece of the puzzle so to speak.
Commander – The missing link
The first thing I did was to look at the code that our other programmer had written, asked him a lot of questions what the different parts did, because in order to change something you need to understand what is going on, where it is doing something and how it is all connected, because if there is one thing I’ve learned when it comes to Unity is that without a proper overview of the code and where you’re going with the code (it is generically so, but in Unity it turns uglier quicker) you get lost very quickly. It’s easy to attach a piece of code to a game object, but if you don’t know that it is attached to a game object or it is attached to a different game object and you need to look into that object in order to know what’s going on.
In any case after some research into that code, looking at the tutorial the other coder was looking at, the picture of what was doing what became clearer. I decided to fix some of the issues that were bothering me however before implementing the multiplayer part, so I added functionality so that you can cancel the building. By that I mean that if you clicked on the key that gave you a tower, you had to place the tower before you could do something else. I fixed that by removing the temporary object that was created and easily enough you could cancel the building by rightclicking. Second thing I fixed was that you couldn’t drag the building outside your building zone. If you wanted to drag it outside it would stop where the border to the “legal” and “illegal” placement location.
Network – instantiate
The last bit of the coding process of the commander was to have it instantiating the building across the network. What is really nice about Unity, and I believe I’ve written this before, is that the networking functionality is really easy to accomplish. However since the server is what controls everything I needed to make it so that the client triggers an RPC call to the server. The server then makes an instance of the prefab on all the other clients. Now technically, thinking about it in retrospect I should have done it a little bit different, however I still need to work on this on Monday, because even though we have a version where the commander works, I need to implement a way for him to toss out healing to the players and also give buffs to the champions. But we do have a playable version now even if it is a bit sketchy and not really working as we want the game to work.
To show some kind of progress here’s some screenshots of how the game looks. The circles were buff circles that I created just to have something that shows on the screen visually so that we know which area is affected.
Next week
Next week is going to be a crunching week. The official Alpha is next Friday, now that is all fine and dandy, but what we need to do is to get the programmers together and get some kind of unity in how we are going about our code. In the beginning we just started coding because we wanted results fairly quickly, which we got after two weeks. Then all of a sudden it’s like the programming tasks have come to almost a full stop. I know we are programming, but it seems to be going so much slower now. I know it is because in the beginning almost everything we did was progress and now we are modifying the code that others have done to fit with future features etc etc. However we have lost some momentum because we are 3 different types of coders, with different ways of working. In the beginning this didn’t seem to be a problem, but now it seems to be a problem because we have code that is meant to be used for something, but are used for other things. We have created the same types of scripts to be used for different things etc. The reason for writing this isn’t to say that we are having major issues, but rather that this is a situation that we should have avoided and since I’m the lead programmer I should have in retrospect taken the time to set up a plan for how it should look. So that’s a tip for those who are interested, even though it is only a 10 week project, take a couple of days to come up with a workable plan, we all know plans change, but at least give some thought into the structure and have people code after that structure. It saves you time in the end, because then everyone knows which classes you have and what they are intended for.