If it ain’t broken, you haven’t tested it

27 09 2010

And by you I mean me, but let’s start in the beginning. I’ve been contracted to write a game. A platformer in ActionScript 3.0, a language I knew nothing about on a platform [Flash] I’ve never even remotely tried, so it’s been an intereseting ride. But more on my adventures in AS3 land in upcoming posts. This one in particular I would like to dedicate to my two favorite beta [gameplay] testers. My wife and my daughter. And the importance of letting other people test your code.

It’s the last leg of the journey now, with the level design near completion and the core mechanics in place [being jumping, falling and colliding like there’s no tomorrow], I raised my fingers in triumpth having just finished testing the collisions myself and called out to any who dared to challenge my game.

Not five minutes later my three and a half year-old, amazing, daughter comes laughing. But dad, why is the little guy stuck in a wall??

Huh? I replied, surely some mistake was made, obviously the players are playing my game wrong. I played the same build on the desktop and found no such thing, so I asked my little tester to show me. Deftly she moved slowly to the left on a platform, fell down and got stuck in a wall. So much for testing my own game.

Some keystrokes, a coffee and forty five minutes later and the collisions were fixed [the collision tests were almost, but not quite, entirely unlike Tea; they were also a bit buggy]. I called out for more players. My wife stepped out to the plate. Played, ran, jumped, fell and collided perfectly. I smiled and left the room to make a cup of Tea [blasphemy, or sheer genius?] and when I came back there was nothing on the screen. And by that I don’t mean the screen was off but rather the entire level, player and tiles included, just vanished… Clear blue skies wherever you looked. And I looked perplexed. My wife had done something which had never occured to me; she let the timer run out and then tried to play the level AGAIN – crazy I know…

Well, some more tweaking [this time I knew exectly where the offending code was so it only took a few minutes] and it’s up and running again. And I’ve re-learnt an important lesson. Don’t play-test your own games.

As the developer I’m biased towards my playing of the level, even if I’m unaware of it, I’ll still try to view the gameplay from a code perspective; trying to fit and push all the numbers rather than just having unfamiliar fun with it. I’m not saying that is not important, it’s the developer’s job to test and see whether buildings are floating and the likes. But letting others play and break the application you’ve made [or in this case I made] in different and exciting ways only serves to create a stronger program. There’s very little point in getting upset over spilled code, in fact rejoice in testers finding broken gameplay because in the end they are there to help you create better software. I’m off to play someone else’s games for a while…

“Seasons don’t fear the reaper, Nor do the wind, the sun or the rain..we can be like they are”



23 09 2010

Phew, I’m not dead yet, although it’s been a hectic couple of weeks being crazy sick. All better now I can even stare at the computer screen for more than 10 minutes without feeling queasy. I never fully appreciate being healthy until I get sick. But with a week lost to a fever it also means a week lost for work, deadlines care very little for viruses, especially nowadays since I’m a one man programming team.

This post was originally going to be about some more binary maths but I’ve tried writing it up twice already and it didn’t work so I’m not going to press it. Binary will present itself when it wants to. Instead I’m going to take another detour and talk a bit about my coding practice. I’ve been trying my hand at different methodologies and approaches to writing code lately, I don’t know if it’s just that the old ones proved a liability as a lone programmer or perhaps I’ve grown bolder in my old age [I’m not really that old] but it felt like it was time for a change.

I’ve talked a bit before about reading up on Agile and while I wouldn’t say that I’m a devot Agilist, I have found many ideas contained within the system to resonate. The past few weeks I’ve also tried different ways to write tests, user stories and design ideas and I think I finally settled on a flow which works for me. I keep at hand three things at the moment, a good quality notebook [size A5], an open text document [.txt] and my whiteboards [I dual wield whiteboards]. Before I start programming I usually write up my stories into the text file then break them into tests. I write a few TODO notes in the notebook and start TDD. Each test I write usually ends up bringing with it more simple TODO notes which go, bullet-point style, into the notebook; each test that is complete usually also takes care of a few TODO notes so I cross them out. Once I’m satisfied that I have a robust unit of functionality [objects, functions, whatever] I stop. I stand up, write a quick UML sketch to document the system interactions visually on the whiteboards [and take a picture], then I use the uncrossed TODO notes and compile a new set of stories and tests. Rinse repeat…

It’s usually not as simple as that, I might do a design sketch beforehand to guide me through a trickier part of the system if I want a visual aid while writing the tests. Perhaps I’ll write more TODO notes, perhaps more tests, but the basic workflow is as described. It seems like things should take more time but I find usually that while I write more, more code, more notes, more of everything, the development time isn’t really changed much at all and I end up with a much cleaner codebase.

Oh and commit/push into the repository as often as I can. DVCS is, I’ve discovered, kind of like ice-cream, once I had a taste I really wanted more [although unlike ice-cream you won’t get a stomach ache from committing too much; in fact you’ll probably get one from not committing enough].

Ok, enough for today, I’ve got coffe and deadlines [in that order], but now that the fever is gone I’ll resume a more stable updating routine…

“…Kicking around on a piece of ground in your home town, Waiting for someone or something to show you the way. “

Take 10 of these

14 09 2010

And call me in the morning…

I’ve been sick, well, actually I’m still sick but a couple of pills can go a long way to dull out a headache. It’s still hard to think so I’ll keep this post short and just talk a bit about binary.

I remember my first class of computer science, the teacher was/is an… interesting… character [but in a good way]. He walked into the classroom, yelled out his name and asked us how do we order 31 oranges if we only have one hand…

Binary is not a difficult base, not any more than any other base, my biggest hurdle of it at first was my inability to separate the value of a number from its representation. Let’s make some orange juice.

Say I have five oranges; I can count them, physically in front of me are five oranges. I can use a decimal representation for them “5” or I can invent my own representation of that value “*”. Either way, the value doesn’t change, it is the symbol representing them which does.

Right, now we get to the base representation. If we already know how to use decimal numbers [base 10] then really we know how to use all bases.
Base 10 [Decimal]
Value range: 0->9
1000 100 10 1
  0   0  3  1

Our representation here reads: 31
Let’s calculate the actual value though;
So our value is the same as our representation [makes sense since I used decimal representation to represent the value in the first place].

now in binary.
Base 2 [Binary]
Value range: 0->1
16 8 4 2 1
 1 1 1 1 1

Our representation reads: 11111
Let’s calculate the actual value;

Same value, different representation. Notice the similarities between the base representations:
Base X
Value Range: 0->(X-1)
...(X*X*X) (X*X) (X) 1

With computers we find that two bases are important, base 2 [Binary] and base 16 [Hexadecimal] because:
A. Computers “think” in binary, everything we write is actually encoded electronically as [1010101].
B. Hexadecimal representations are more compact than binary and are easily converted to binary [every bit field in the hexadecimal column corresponds to 4 bits in binary].

That’s it, nothing too complicated but it taught me an important lesson; don’t confuse the value of an object with the representation of its value. My pills are running out and my head is throbbing again but at least the dishes are done.

“Who’s gonna cry when old John dies?”

Spot the bug…

6 09 2010

Two posts, in one day, with a sick daughter… The man knows no rest!

Well, actually this isn’t a full post; just a minor correction. Two points* to those that spotted the minor logic bug hidding in the previous post’s code. I didn’t at first, then I ran the code, the character ran right; I pushed left and let go and watched him slide all the way out of the screen. I laughed then realized what I did wrong; do you?

See, my logic said before to apply friction in the opposite direction of the character’s FACING, this meant that when I turned the character around but didn’t continue moving the friction was actually applied to the direction of my current velocity… Hilarity ensued.

Easily fixed. Apply friction in the opposite direction of the current velocity. In pseudo-code [since I don’t have time for full code].
if (VelocityNow > 0) { VelocityNow = VelocityNow - Friction; }
if (VelocityNow < 0) { VelocityNow = VelocityNow + Friction; }

Hopefully nothing else goes wrong today.

*Since there aren’t any prizes, here take three

“Just another brick in the wall”

ActionScript Man to the rescue!

6 09 2010

Longest between updates but with deadlines, clients and a sick three and a half year old I just didn’t have the time to write anything. In fact, I don’t really have the time much now, the water is boiling for another cup of tea so I’ll sneak in a few words.

Like I’ve said, it has been somewhat of a hectic week. I’ve stepped away from my normal den of C++ and OpenGL and rolled into the smooth plains of ActionScript 3.0; a language I’m assured is much better than ActionScript 2.0. I haven’t developed on the Flash platform before and so I’ve no claims to the veracity of that statement but so far it’s been a very pleasurable journey.

I’m working on a one player, one level, simple yet fun [hopefully] platformer. The goals of which can be summed up as Run, Jump, Avoid and Collect. My biggest dilema so far has been whether to incorporate complex physics, no physics or simple physics for the main character’s movement.

Having little time and not enough familiarity with the the language I’ve decided against a complex system [which includes other people’s compex systems]. No physics at all seems a bit extreme so I’ve settled on a simple acceleration vs. friction mechanic.

if (mMoving)
  mVelocity.x += (mAcceleration.x * mFaceDirection) * dt;
  if (mVelocity.x>mVelocityMax.x) mVelocity.x=mVelocityMax.x;
  mVelocity.x += (mFriction.x * -mFaceDirection) * dt;
  if (Math.abs(mVelocity.x)-EpsilonValue < 0.0) mVelocity.x=0;

Fake high school physics for fun and profit. The interesting part of it is that it allows different ground tiles [upon collision] to supply modifiers for any and all of these values, resulting in a more modular game world.

Another problem I came up with was the situation where players push left and right at the same time. I’ve played around with a few solutions but none of them made me happy so I’ve made the left and right button checks mutually exculsive [that is, if you’re pushing left it won’t check for right and vice-versa]. What would you do in this situation?

Well, the dishes are done but the tea has boiled and my little one is up with a soft sort of smile so I’ll leave this post as short as it is; till next time…

“Julia dream, dreamboat queen, queen of all my dreams”