Categories
Game Development Geek / Technical Personal Development

Learning How to Unit Test

I first wrote about Agile development as a lone indie years ago. I got some good comments, but it still felt like I lacked any real insight into how to be a better developer on my own. A couple of years later, after seeing someone use unit tests first-hand, I wrote about Test-Driven Game Development.

So I immediately tried to use unit tests for my next project, which was my Ludum Dare #12 entry. I stopped after encountering difficulty. I didn’t know what I was doing, and I needed to make progress. I had a deadline.

Recently, I decided to start using TDD to create a simple game. And I wanted to use it for the entire project, not just the easy parts. I created a simple design for a game involving vampires, and set to work.

And immediately I hit a problem. In order to get anything useful on the screen, I needed to use libSDL. How do you go about writing unit tests that make use of a library? I don’t want my test binary to open and close windows, manipulating hardware, and otherwise resulting in weird side effects. Ok, no problem. I’ll just create an abstraction layer between the game and libSDL. I called it HardwareLayer, but then ran into another problem. The HardwareLayer would need to use libSDL directly, so all I’ve done is put the hard-to-test code in a new class. Well, maybe I can make an interface, but how does one test-drive his way to an interface? I didn’t make anything easier for me at all. Unfortunately, my lack of experience was going to bring this TDD experiment to a standstill.

But I pushed. I checked the book Test Driven Development: By Example but couldn’t find any information specific to what I was trying to do. I tried to find a TDD-centric IRC channel, but none existed that I could find. So finally, I threw out my question on Twitter, and within moments, I had a response from an expert.

Brett Schuchert of Object Mentor took the time to write up a blog post on TDDing an Interface. While his example was in Java, it was eye-opening to see how TDD gets done in a somewhat real-world example. I was able to make some progress, but still had the problem of using libSDL at some point. My inexperience questioned whether I would be using unit tests on the code that simply delegates to libSDL calls.

And Schuchert once again spent an evening writing up another blog post about hiding global methods, and this time he even used C++ and created a working project! He claims that the effort to get everything under test was simple to do since most of the issues I was having are idiomatic and therefore pretty easy to solve.

In our discussions in email, Twitter, and the blog, I had the insight I needed. I’ve since purchased Working Effectively with Legacy Code since a number of the issues I had involved dealing with untested/untestable libraries. If it is so idiomatic, I should know it, too. The book would have been very helpful with issues I’ve tried to deal with in the past, so I look forward to applying my new knowledge going forward.

Since those posts, in the time I’ve been able to dedicate to game development, my test binary doesn’t make calls to SDL directly, and my actual game does. I might still do bizarre things when it comes to TDD and unit testing, but I’m making progress that I’m reasonably confident is correct and working at all times. It helps that I recently participated in a three day TDD workshop that the Day Job sent me to, but I found that the most beneficial part was doing exercises with someone available to say whether or not I was going about it correctly enough. In fact, even the Bowling Game Kata makes a lot more sense to me as an exercise. That is, I get it now.

Categories
Game Development Personal Development

Thousander Club Update: July 6th

For this week’s Thousander Club update:

Game Hours: 576 (previous three years) + 144.25 (current year) = 720.25 / 1000
Game Ideas: 775 (previous three years) + 10 (current year) = 785 / 1000

I did minimal work on the vampire game, but it was on purpose. I had a mini-vacation to celebrate Independence Day out of town. Now that I’ve returned, I am getting back on track, although this month is filled with vacation time so I don’t expect too much game development productivity.

[tags]game, game design, productivity, personal development, video game development, indie[/tags]

Categories
Game Development Personal Development

Thousander Club Update: June 22nd

For this week’s Thousander Club update:

Game Hours: 576 (previous three years) + 142.25 (current year) = 718.25 / 1000
Game Ideas: 775 (previous three years) + 10 (current year) = 785 / 1000

I’ve been putting in some good work on my vampire game, making significant progress and writing unit tests along the way. I hope to have some screenshots in the coming weeks.

[tags]game, game design, productivity, personal development, video game development, indie[/tags]

Categories
Game Development Personal Development

Thousander Club Update: June 15th

For this week’s Thousander Club update:

Game Hours: 576 (previous three years) + 137.5 (current year) = 713.5 / 1000
Game Ideas: 775 (previous three years) + 10 (current year) = 785 / 1000

I spent more time working on the vampire game, specifically driving the development with unit tests and learning how to do so along the way. I’ll have more to say about that topic later this week.

[tags]game, game design, productivity, personal development, video game development, indie[/tags]

Categories
Game Development Personal Development

Thousander Club: June 8th

For this week’s Thousander Club update:

Game Hours: 576 (previous three years) + 133 (current year) = 709 / 1000
Game Ideas: 775 (previous three years) + 10 (current year) = 785 / 1000

I worked a bit more on my small vampire game, although I was running into trouble with unit testing. There were a couple of development sessions in which there was either no tangible result produced or it was thrown away. I initially felt as if those sessions were a waste of time, but they did provide insight into what I was trying to accomplish.

[tags]game, game design, productivity, personal development, video game development, indie[/tags]

Categories
Game Development Personal Development

The Game Development Habit

This past week, I decided to focus specifically on the habit of doing game development, mostly programming, for an hour a day. At some point each day, I sit down with my laptop, and I refuse to allow any distractions to stop me for at least an hour. I could do more, but I should do at least that hour per day. I can easily wake up early, do my hour, and then go about getting ready for the day job. Then I also have the evening free to either work on game development or relax or focus on some other task. Successful authors will write a set number of words per day. Successful direct marketers will write an hour per day. Why not borrow this habit for game development?

Since the important thing was developing the habit of daily game development, it didn’t matter too much whether I accomplished a little or a lot in that hour. That is, if I wrote a bunch of code that I’m unhappy with and end up deleting, it’s still better than not having written it, not having learned from it, and not ever seeing a better way afterwards. I’m not hacking, of course. I’m simply saying that if one day happens to result in worse quality than others, I’m not going to see it as a setback since the important thing is that I produced something rather than nothing, which is what I usually accomplish.

The bad news: I only did 5 hours. Out of seven days, I kept the practice up on five of them. One day I woke up late, and when I thought I could do my hour in the evening, I was reminded about a charity event I planned on attending. On another day, I also woke up late, helped some friends move, and had hardly any free time that day.

The good news: since I usually do 0-2 hours per week, five hours is still an improvement. Also, these were high quality hours. I made more progress this past week than I have in the last few weeks.

So what have I learned? Regular game development means sustained focus. When you work for an hour per week, it’s easy to be distracted or feel confused when you finally do get back to working on game development. If you do it each day, however, it’s easier to remember what you were doing from the previous session. Wednesday’s hour isn’t standalone. It has the power of Monday and Tuesday’s hours behind it to give you momentum as you work. Also, if you don’t finish something in a session, you know you will tackle it tomorrow.

Duh? Yeah. But there is still something about experiencing both cases and seeing the difference to really make it clear.

A surprising benefit: I felt better about doing other things with my time. Once I got my hour in, I was at ease with taking time to read, wash dishes, talk to a friend on the phone, or go out. Normally, I’m in a constant state of unease about doing anything because I always feel like I should be working on game development. At the end of the week, I find time and time again that I’ve only worked on the act of creating a game for an hour or two at most, and the next week I just feel worse when it happens again. This past week, however, was anxiety-free for the most part. Go to a cookout and then to a birthday party later? I already did my hour this morning, so I’m good to go! I felt good about accomplishing that hour each time, too.

It would help if I could do the hour at the same time each day. Ideally, it would be first thing in the morning. I used to wake up at 5:30AM every morning, but I fell out of that habit some time ago. Relatively recently I managed to wake up at 6:30AM consistently. The problem is that the previous evening’s activities can affect my ability to wake up early, which means that if I was out late with friends on Wednesday, Thursday morning I’ll be rushing to get ready for the day job, and then I’m depending on tackling the hour of game development in the evening. Of course, the whole point of waking up early is to get a head start on the day, when no one else is up and capable of distracting you, so waking up late can cause a domino effect on at least part of the week.

I’d like to see my habit provide me with a baseline of game development hours. I should always accomplish 5-7 hours for the Thousander Club each week, and on more than one occasion I should be able to double those hours with my weekends and evenings easily.

I’d say this week was a success, and I’m looking forward to seeing what I can accomplish after a month of daily game development.

Categories
Game Development Personal Development

Thousander Club Update: June 1st

For this week’s Thousander Club update:

Game Hours: 576 (previous three years) + 126 (current year) = 702 / 1000
Game Ideas: 775 (previous three years) + 10 (current year) = 785 / 1000

This past week, I worked on taking some boilerplate code from my game projects and throwing them into a library. I then started a new game project to test out my library. Although there isn’t much to it yet, here’s what I’ve got so far:

$ ./testvampiregame
Success: 1 tests passed.
Test time: 0.00 seconds.

I’ve also started learning how to use git to maintain a repository. While my projects are usually in a subversion repository, on more than one occasion I’ve had my laptop disconnected from the network, which means that if I did any modifications, I couldn’t check them in. My repositories are on my desktop/server. Using git, it would be like taking a repository with me, making changes to it, and then providing the changed repository to the server once I have a network connection again. Nice!

A new game project, a new source control tool, and a new habit of game development. It’s been a good week.

[tags]game, game design, productivity, personal development, video game development, indie[/tags]

Categories
Game Design

If Art Was a Game

I am participating in the Blogs of the Round Table for the first time in many months. May’s topic:

A Game Is Worth a Thousand Words: What would one of your favorite pieces of non-interactive art look like if it had been created as a game first? May’s topic challenges you to imagine that the artist had been a game designer and supersede the source artwork–whether it be a painting, a sculpture, an installation, or any other piece that can be appreciated in a primarily visual way–to imagine a game that might have tried to communicate the same themes, the same message, to its audience.

A tall order! And yet I enjoyed doing the research for this one. The topic reminded me of The Cavern from Plowing the Dark, which was a virtual reality room. The artist was tasked with making the technology appealing, and she filled the room with virtual reality versions of famous paintings such as Rousseau’s The Dream. And yet, merely walking through a painting didn’t seem to do enough, as cool as it sounded.

Choosing My Art
I could have chosen any non-interactive art from any medium, but I decided to stick with paintings. The problem with reimagining a painting in game form is that I first had to know what the original painting was meant to be seen as. For instance, van Gogh’s Starry Night, a hallmark of freshman female dorm rooms on college campuses everywhere, would be fascinating to see as a game, except my research indicated that no one actually knows what it is supposed to signify or mean. Other paintings were made simply to be visually pleasing, and perhaps if I gave much more thought to it I could find a way to make a game that captures the essence of beauty, but I felt that it would be relatively shallow. I wanted to find a painting with meaning, something that asked the viewer to study it, and in a way, did most of the job of interactivity on its own.

I found something of it in a memory. When I was a child, I went to a Catholic grade school. One of the priests had the opportunity to go to Italy, and he had a projection slide show of some of the things he saw while there. I don’t remember much, and I don’t remember anyone saying what we were looking at, but I do remember seeing a portion of a large painting. This painting had a man, naked, covering part of his face with one hand, while cowering in an attempt to hide the rest of his body. I remember the priest making a point of noting how ashamed this person was. It made quite an impression on me.

With that, I did a search online. Was it a painting of Hell? I found some interesting ones, but nothing resembled what I remembered. Maybe it was Judgement Day? Besides finding a few Terminator references, I found quite a few artists did paintings of it. But then I found it: Michaelangelo’s The Last Judgment in the Sistine Chapel.

Wikipedia has a very large resolution image of the painting, so feel free to check it out. The figure I remembered is near the bottom right of the painting:

Ashamed

Ok, I had a painting. What was it trying to convey to the people who would see it? I did some reading, and there was much to be made about the colors or the composition or how it relates to the ceiling. What really inspired me to want to see the painting for myself one day is this wonderful article called The Terror of Salvation: The Last Judgement.

The painting is called The Last Judgement, but its focus is more upon the resurrection of the body at the end of time. There is also the idea that judgment is not a simple matter of Jesus and God counting your sins and deciding where you go. Michaelangelo was a student of Dante, who looked at salvation and damnation as human choices. Judgment is personal and internal, not imposed upon by the Deity. God simply allowed you to make your judgment. Sin wasn’t a quantity of actions. It was a state of the soul.

Designing It As a Game

There are quite a few places I could take The Last Judgment: The Game. While I would ideally have the setting be similar to the painting, I felt it was too limiting. The painting works because everyone understands that they aren’t being judged based on a single point in time. Each person has lived a life of choices before seeing the painting. It’s very powerful because people bring their personal history with them when they see it.

Therefore, Michaelangelo’s game wouldn’t start at Judgment Day. It would start at birth.

Initially, others would be making decisions for you, but as you get older, you become more capable of thinking for yourself. There wouldn’t be a need for a “sin meter” or HUD. Through your own knowledge of your actions, you should be aware of the state of your soul.

Each day in game time might be representative of a year. Perhaps one day you are poor, and you have the opportunity to steal some food. Do you? Perhaps another day you are lonely. Do you take comfort with a local prostitute?

Some choices aren’t quite so obvious or clear-cut. Do you make fast friends with some of nefarious elements in your society? Do you become a bad influence on someone else? Do you steal bread for someone who is hungry? Do you stay at home when you could be productive? If someone strikes you, do you strike back? Do you lie to protect a friend from a bully? Do you lend a panhandler money, not knowing what he is going to use it for? Do you destroy a group of small houses that have been there for decades to make room for a large condominium that can bring in more money to the community?

Essentially, the game is about making decisions. Perhaps circumstances might be different for each play session, but the choices are always in the player’s control. Based on those decisions, of course, your life and the lives of those around you are affected. Perhaps you live a life of luxury, but depending on how you got there, you might have few friends, many enemies, and a lot of debt. Perhaps you give away all of your earnings, but because you never save any for yourself, your capability to earn and therefore give is limited. Perhaps in an effort to avoid committing sinful acts, you lock yourself in your room, but by doing so you waste your potential as a human being.

At the end of the player’s life, it is Judgment Day. An angel shows you a book, detailing the decisions you made. Jesus stands before you, and he waits for you to decide whether you have lived a life worthy of salvation or whether your actions clearly showed a desire for damnation.

That’s It?

That’s it. The idea behind the game is to allow the player the chance to explore a life of different choices. Judgment Day is not simply a matter of counting up what you think are the wrong actions and subtracting them from the number of right actions in the hopes that you came out to a positive goodness rating. It would be more introspective, more personal. Jesus isn’t angry or pleased to see you. He isn’t going to send you to Hell. You are.

Couldn’t the player lead an evil life and then decide to be saved anyway? Yes, and the game wouldn’t stop them. The game doesn’t deal with the aftermath of your decision. If you choose to sin your way to Judgment Day and simply think you can click on the “Salvation” button, sure, you could complain that the game is broken. Another way of looking at it: you’ve missed the point. Judgment Day is yours to take seriously. The game isn’t going to enforce it for you any more than God is. Read the account of your life that the angel is showing you. The game would keep track of choices, including omissions, as well as telling you about the other people in your life and how your actions affected them. Recognize that the choices you make color who you are, and that you, faced with the knowledge of all of your decisions, get to decide whether such a life makes you worthy of salvation.

If Art Was a Game

I really enjoyed the challenge of this month’s topic. Another painting I wanted to make a game out of was Nighthawks at the suggestion of a good friend of mine. Making a game about the emptiness or loneliness of modern urban life is something I hope another Round Table blog takes up before May is over.

Categories
Game Design Game Development Marketing/Business Personal Development

An iPhone App in 8 Days

Stephen over at Unobserved Musings wrote about an ambitious plan he tackled with a colleague: creating an iPhone app in 8 days. It’s not 8 days of straight development for this project, either. He and his colleague have other obligations, too.

Is what we are attempting even possible? Can two individuals really give up all of their free time, and perhaps much of their sleeping time, for 8 days, just to make a single product on the side of their other commitments? Success or not, it’s going to be a wild ride – but Josiah and I are determined to push ourselves and prove to ourselves we are capable of anything.

Over the course of the next few days, screen shots were uploaded, and details of the development process were hinted at. By the end of 8 days, a finished game was indeed ready, and it was soon available for purchase for iPhone users everywhere. After a week, Stephen posted about the first week of sales.

Bottom line: sales were disappointing, mostly due to the fact that of the people playing the game, only a small percentage were doing so legally.

On the other hand, in a little over a week, Stephen has created a game that he can sell, and his marketing efforts are still kicking into gear. And he does have legitimate sales, which still seem to be coming in. I’m more encouraged by the fact that he was able to start selling a game that didn’t exist as of a couple of weeks ago! When I created Sea Friends, it took me a month, and I felt that was fast!

After only 8 days, Stephen now has something that can be nurtured or abandoned. If sales start to pick up, great, but if not, he only lost a little over a week of development time and has learned so much from doing so. Sounds win-win to me.

Categories
Game Development Personal Development

Thousander Club Update: May 25th

For this week’s Thousander Club update:

Game Hours: 576 (previous three years) + 120.75 (current year) = 696.75 / 1000
Game Ideas: 775 (previous three years) + 10 (current year) = 785 / 1000

I wrote some test code to see if I could create my own static library. This way, when I create a game, I can include my library as if it was any other library while also getting the benefit of keeping boilerplate code in one place. Soon when I write a future C++ game, I can have it derive from my GBEngine. B-)

I’d like to build up the habit of programming every morning for an hour. Some authors will write so many words per day, and I know I used to have a habit of waking up early and working on things before leaving for the day job. I’d like to regain those habits.

[tags]game, game design, productivity, personal development, video game development, indie[/tags]