Friday, September 26, 2014

Arena - The Chaos Masterpiece

As mentioned on the previous post, about 5 months ago I took my first shoot at developing programs on my own and Arena was my first contact with game programming. Surprisingly it went pretty well, I didn't expect the results that I had since I knew nothing about C. The concept is simple, a text-turn-based game where you can battle some pre-defined creatures and get stronger as you win matches, the goal is to kill the last creature in the Arena, the Behemoth. 

I started by making the player structure, this task doesn't require much programming skills and it helps to get used to the language, that's why I choose it first. Basically, I just made a bunch of switch statements and lots of printf's, both things I was already familiar with. All I've done after this was really hard to me at that time and required some time studying the C language. Funny thing to mention is that all the code I was writing was in the same file, I mean, I had a 'main.c' containing my whole game, wasn't much code but still disgusting...

I created players, enemies, visualization on console, all the trivial stuff. Then I realised that I couldn't make that work together without having the basic knowledge, I thought "This code is getting pretty messy and I still don't have anything I can play with". That was the point I stopped 'programming' and started studying for real. I needed to know how to deal with pointers, attributions, headers, how to access variables, and so on. Summing up, I started it over again, best decision ever.

This second time I started by creating all the structs that I was going to use in the beginning, all the headers and files, and while I was creating the console visual I was already putting the values typed by the user on the right fields on my variables. So in a couple of hours I had the 'create player' functions fully working. I got excited and went right to the battle system, the disaster of course.

Pointing to the wrong direction maybe? 

It took me some time and a lot of testing to figure out how to manipulate my pointers correctly...but when I got that working, it flowed pretty well. After this phase I implemented the whole battle system, level up, some techniques, the 5 enemies and then, I had a playable game at last. The main functions were done and I was still excited to make more features, so I added in-game experience calculators, two more player classes, polished all the battle printf's, and I was done. 

Finishing a match against a globin at Arena

After playing it for a while I sometimes found myself leaving the game open so I didn't lose my character progress, that's when I decided to learn how to generate .txt files with the data I needed and load a variable assigning those values, so I could load my character and keep playing from where I left off. Even though there is no serialization involved, it was really tricky for me to implement at that time, but worked pretty good for that occasion.

I never touched the code since then. I thought of refactoring almost the whole project and write it properly, but.. I can't do this... my first 'game' ever, no solving problems skills involved, everything done from the top of my head, so I decided to leave it exactly as it is, a chaos masterpiece.