31 Things, Day 15: Programming

31 things I'd rather be doing right now

There is something very satisfying for me about programming. I’m specifically referring to coding here; it’s part problem-solving, part art. The problem to solve can be small (make this mess of text into a nice table), or big (make a game).  The art part is the design of the code “building blocks” that will work together to make a computer program. The term used among programmers is “elegant code,” and I think it is an apt word. If you can create some code that can be reused for many things, both now and in the future, you just saved a lot of time. You never have to touch it again, because you know it works. I love that.

Take this example from my own game code, which I find to be very elegant, (if I do say so myself). A tile-based game is a grid where objects can move in any direction to a tile next to it. Sometimes an object can’t move for various reasons, maybe it’s blocked by a wall. In any case, a game needs to be able to handle an object moving from one tile to another.



When I first made my Heroquest game, the code handled moving objects very specific to the game. I would never be able to use the code again, because it was very closely tied to only that game. Later, I discovered I could refactor that code and make it reusable. In order to do that, I had to completely generalize what was happening when an object moved from one tile to another. It doesn’t matter if the game is Heroquest or Monopoly or Sorry!

This is what I came up with:

When a pawn wants to move in a certain direction, follow these steps

  1. Does the pawn meet the prerequisites to be able to move in the first place? If no, do something else because they are not met. Otherwise, continue
  2. Are Diagonal moves allowed? If no, does the pawn want to move diagonally? If yes, do something else because diagonal moves are not allowed. Otherwise, continue
  3. Does the tile the pawn wants to move to exist? If no, do something else because the tile can not be found. Otherwise, continue
  4. Is the tile the pawn wants to move to accessible based on where the pawn is now? If no, do something else because the move is blocked. Otherwise, continue
  5. If you got this far, the move will now happen:
  6. Process/do the physical move itself
  7. Evaluate the ramifications of the move to the pawn, the surrounding area, and/or the whole game itself
  8. Do any post-move processing (clean up, things that always happen at the end of a move, etc)

Now I had a skeleton framework to make some reusable code, and I could use it any game I wanted. Here is the actual code:

public void move(TileOccupier pawn, Compass dir) {
  if (movePrerequisitesMet(pawn))
    if (!(!diagonalMovesAllowed() && dir.ordinal() > 3))
      AbstractTile targetTile = 
        tileMap.getAdjacentTile(pawn.getLocation(), dir);    
      if (targetTile != null)
        movePreProcessing(pawn, pawn.getLocation(), targetTile, dir);
        if (tileMap.isEnterableFromOppositeDirection(targetTile, dir) ||
          ignoreTileBoundaries(pawn, dir))
          processMove(pawn, pawn.getLocation(), targetTile, dir);
          evaluateMove(pawn, pawn.getLocation(), targetTile, dir);
          movePostProcessing(pawn, pawn.getLocation(), targetTile, dir);
        else { processMoveBlocked(); }
      else { processTargetTileNotFound(); }
    else { processNotAllowedDiagonalDirection(); }
  else { processMovePrerequisitesNotMet(); }

Not that long at all. And the way it works is that any game I make in the future will be able to use it because it is abstract. I simply have to make some concrete decisions about what happens in the particular game at the various stages of the move. (For example, one game may yell at you when try to move diagonally; another game may do nothing at all.)

For the non-programmer types reading this blog, this post may have been boring. But whenever I look at that code above – something I made all on my own – I think, “wow, that was a really elegant design.”

And then it makes me want to go code something!

So that’s another thing I’d rather be doing now, programming.

31 Things, Day 14: Playing Video Games

31 things I'd rather be doing right now

I love video games. Not all video games, mind you; I have specific types I like. What I love is the interactivity of the art form. Yes, I consider video games an art form. Whether the game designers have created a story for me, or I create the story from playing, the adventure, to me, is as real as reading a book or watching a movie. The creativity of the games’ stories, concepts or graphics appeal to my artistic side, and the execution of the mechanics of the gameplay appeal to my technical/programmer side. What’s not to love?

Still the best game ever.

Still the best game ever.

Once a game has its hooks in me it’s hard to pull away. I know because if I’m not careful they can consume my time and thought. These days as a husband and father, I purposely try to limit my screen time, for the health of all. I’m not always successful. There’s a twinge of selfishness that creeps up now and then, and I choose games over real life. But I’m much better at controlling that aspect of myself today than I was years ago.

The Atari 2600, Nintendo Entertainment System (NES) and Super Nintendo Entertainment System (SNES) were the video game consoles that started it all for me. As a shy and quiet kid who didn’t play sports or go outside that much, video games were my form of adventure, competition, and yes, escape. Later I moved on to PC gaming, and because of its versatility it remains my favorite platform; I circled back to consoles with the Nintendo Gamecube and Nintendo Wii, and even dabbled in iOS games with my Apple iPod Touch, but I still remain a loyal PC gamer.

Was never caught up in the story more than FF2

Was never caught up in the story more than FF2

My favorite types of games are simulation/city-building games (Dwarf Fortress, The Sims, SimCity, Banished), complex strategy war games, (Age of EmpiresCivilization, Europa Universalis), open-ended role-playing games (Elder Scrolls), story-based role-playing games (Final Fantasy, Eschalon), Exploration/Puzzle games (Myst, Portal), Sandbox games (Terraria, Minecraft) and Action-Adventure games (The Legend of Zelda, Rogue Legacy). Those are all mostly single player games for a reason: not a big fan of multiplayer games, usually because I’m not good enough to go against people who play all day.


The city of Vivec, Morrowind

The city of Vivec, Morrowind

So many games, so little time, but I enjoy them when I can (key word enjoy, not conquer), but mostly try to keep my head above water so that I don’t miss real life at the same time.

As an artist/writer/gamer/programmer, it should come as no surprise that I want to create my own games. We’ll talk about that tomorrow.

So that’s another thing I’d rather be doing now, playing video games.

How I Wrote a Novel, Part Three

(continued from part one and part two)

So I had just finished writing half a novel in a month (50,000 words!), and after an honest critique I had to face an uncomfortable truth: it wasn’t really a novel.  I had a choice to make.  I could either wallow in self-pity, go back to making it a video game, or start educating myself on just what a novel really is.

After some wallowing, I decided I didn’t want this story to be a game.  I wanted it to be a book.  So the education began.

I’m a fairly adept writer.  I don’t say that to sound arrogant, I know I’m far from a great writer, but I also know that this is a talent I have had for a long time.  If you peruse my site, you’ll see I’ve been writing for over ten years.  Never published, mind you, but that’s only because I’ve never tried yet.  I’m man enough to admit when I don’t know something, though, and I was faced with something I did not know: what makes a novel good enough that people will buy it?

I’ll be creating a list of resources soon so that people can see all the things I’ve read up on over the last year.  For now, I’ll list just three things that had a major impact on shapping my novel’s story.

First, I had to boil the whole thing down to a protagonist who wants something, and give the story a theme.  My first attempt had a protagonist, sure, but he was just thrown into the middle of saving the world because I, the writer, made it happen that way.  Fine for a video game, not really believable for a novel.  So I searched my heart, decided on the “big picture” story I wanted to tell, and I found my theme.  From there, I used that theme to drive the motivations of my main character so that he had a reason for doing the things he did.  Every obstacle in his way equaled a scene of action, and those scenes together formed a plot.

Second, I had to structure that plot.  For this, I found the Ten Scene Tool from The Writer’s Little Helper to be an excellent resource.  The general idea of this tool is to create rising and falling tension, a point of no return, a climax and a resolution, and break them down into ten key scenes.  The novel only has ten scenes?  Of course not, but it has ten really important ones, and they form the skeleton of the story.  Everything else built around them, filled in the gaps so to speak.

Third, I needed some guidance from a master.  To that end, I read Stephen King’s On Writing.  I recommend this book to anyone who wants to write.  Not only is it an encouraging read, he is refreshingly honest about what it takes to write in a way that people like to read today.

As I said, there were a lot of things I looked at, but these three were essential.  Another final piece I found everywhere I searched was, “Finish it.”  I had to resist going back to the first half and begin editing.  I made myself write another 60,000 words before ever looking at the first 50,000 again.  It took me 8 months, but I’m glad I did that way.  Now I could look at my huge document and say, “alright, draft one is done.  I did it.  I really wrote a novel.”  It was a great accomplishment, and those of you who have done it know the feeling.

NOW, I had to piece together two halves of a book and make sure they told a coherent story.  Oh what fun.

…Continued in part four

How I Wrote a Novel, Part Two

(continued from part one)

National Novel Writing Month, affectionately known as NaNoWriMo to its participants, occurs every November, with the goal of writing 50,000 words in 30 days. Quick math: that’s 1,667 words a day, about 5 double spaced pages. When you break it down like that, it doesn’t seem all that bad, does it?

What, just me?

Alright, I know I’m not your average guy–or person for that matter. I like complicated things. Really complicated things. My wife says my leisure activities are more complex than most people’s jobs. She’s probably right. My favorite books are thousands of pages long encompassing hundreds of characters involved in intricate interweaving plots (Lord of the Rings, Song of Ice and Fire). My favorite video games take hours of dedicated gameplay over many months to unravel all the deep lore and nuance of the designers’ vision (Elder Scrolls, Zelda, Civilization). My favorite board games cost over $50, take hours to play (or an hour to take your turn), and involve great strategic thinking and planning (Axis & Allies, Agricola). My ideal movies are hours long, with artsy camera work, strange plots and lots of quiet reflection afterwards (The Fountain, The Thin Red Line).  I like my music to be multi-layered, in odd time signatures, busy, and out there (Genesis, Yes).

So, write a book in a month? Game on.

October 2010 was planning time. The rules were that you couldn’t have any prose before Nov 1, but you could have an outline. I took all month to write a ten page outline and I also drew a map. (Fantasy books need maps, you know.) I had just joined a writing critique group, so I had 8 people who knew what I was doing. I told many other friends and family. I highly recommend this strategy: the more people you tell, the harder it will be to quit, because you will have to tell them.

Nov 1 arrived and I hit the ground running. I wrote during lunch at work, and at night at home. Sometimes it flowed so fast that I was done in an hour. Other days I had to stretch myself for 3 hours to get anything down. Sometimes I didn’t make the daily quota, other days I got ahead. I took Thanksgiving Day off. I kept a good pace. Here’s my actual chart:

National Novel Writing Month, November 2010

National Novel Writing Month, November 2010

Yes, I charted it. I’m a geek, so what? It worked though, because you notice the end there? Yeah, I did it. I won. 50,000 words in one month. Unbelieveable, right? You know what was even more unbelieveable?

I was only halfway through my book. Argghh.

For my own sanity, and my wife’s, I took a break. All of December. During that month I let my critique group take a look at the first chapter. I know, I know, you shouldn’t let anyone read your first draft. It really wasn’t that bad, though. I wanted to see what they thought.

They liked it. A lot. Praise felt good. Well, there was one guy who didn’t really like it. He’s been published before, I better listen, right? He came to the group after I started. He didn’t know the origin of my story. And what did he have to say?

“It doesn’t read like a novel. It sounds more like a role playing video game.”

Uh oh.

…Continued in part three

How I Wrote a Novel, Part One

My novel wasn’t a novel at first.  It began as a video game.


Since the mid 90’s I have always wanted to make my own Role Playing Game (RPG) in the style of my old-school SNES favorite Final Fantasy II (IV if we’re being true to Japanese numbering).   I still do.  Making games takes time, though.  I worked on learning programming over the course of many years, and only gave a little bit of thought to the story line.

A few years ago I discovered RPG Maker XP, and then the easier-to-use RPG Maker VX.  Wonderful tools, just a little too expensive and too short of a trial period.  But I started making something I really liked without the hassle of coding.  It was fun.  And lo and behold, a story emerged.

The demo ran out of time, but I kept writing the outline for the story.  That was fun too.

Then life happened. Depression happened.  Life ambitions fizzled, and with it my life’s focus.  A dark page.

I can’t remember why I started thinking about the old game, but it was around the summer of 2010.  I guess I just wanted to be creative again.  I looked over my notes.  It was pretty good.  Complex story.  A bit cliche, but standard fare for the RPG genre.  I remember thinking about the first task the game required: go to the temple cellar and kill all the rats (a deliberate cliche).  I remember picturing the lead character, Adain, swatting away rats with a pole, the weakest weapon in the game.  In my mind it looked like a movie.  Wait, what if I wrote it down like a story?  I hadn’t written fiction in 10 years or so.  But sure, why not?  I wrote a paragraph.  Wow, pretty good again.   Not bad for a depressed guy. But it sat for a while.

And then in October of 2010 I saw something that would change my life:  National Novel Writing Month.

…Continued in part two