annabunches.net/content/posts/2011-06-26-project-treewars-beginning.md

18 lines
8.6 KiB
Markdown
Raw Normal View History

2016-04-11 22:01:00 +00:00
---
2016-05-04 18:41:25 +00:00
excerpt_separator: <br/>
category: technology
2016-04-11 22:01:00 +00:00
layout: post
title: 'Project TreeWars: The Beginning'
date: '2011-06-26T08:00:00.000-04:00'
author: Anna Wiggins
tags:
- Programming
- SDL
- C++
- TreeWars
modified_time: '2013-10-22T11:19:51.363-04:00'
blogger_id: tag:blogger.com,1999:blog-4209116010564764361.post-5020071627931204840
blogger_orig_url: http://www.stringofbits.net/2011/06/project-treewars-beginning.html
---
My goal is two posts a week - typically, one on Wednesday and one on the weekend. This is usually a pretty easy goal to obtain - it doesn't take too much of my free time to churn out two posts between 750 and 1500 words. And yet, there almost wasn't a post this weekend. Was I playing <a href="http://www.minecraft.net/">Minecraft</a>? Nope.<br/><br/>I was writing code.<br/><br/>Programming is something I've always wanted to do professionally, but somehow I managed to end up doing enterprise technical support instead. So, it has become a hobby. And when a project really starts flowing, it is easy to lose myself in it. So I spent three days this week spending every available moment adding code to my new project: a game I'm tentatively calling TreeWars. I've managed to tear myself away from the project for a while, but rather than put it out of my mind, I've decided to blog about interesting things that happen during the development process.<br/><br/>First, meet TreeWars:<br/><br/><a href="http://stringofbits.files.wordpress.com/2011/06/treewars.png"><img class="alignnone size-full wp-image-449" title="treewars" src="http://stringofbits.files.wordpress.com/2011/06/treewars.png" alt="" width="450" height="347" /></a><br/><br/>Not much to look at, I know. But the project is still very much a work in progress.<br/><br/>Some interesting things about TreeWars:<br/><ul><br/> <li>It is my second attempt at games programming, and my first was just a software implementation of a classic abstract board game (hnefatafl). And it was written using the graphics tools in GTK (which are serviceable, but not ideal). As a result, I'm learning all sorts of interesting things about the fundamentals of programming games.</li><br/> <li>It is my first (real) attempt at graphics programming as well. I'm using SDL, and may eventually rewrite the rendering engine (and parts of the game engine) to make the game 3d and use OpenGL. Either way, I hope to make it cross-platform, although I'm currently only focusing on Linux, since it's my native platform.</li><br/> <li>It is based on <a href="http://en.wikipedia.org/wiki/Tree_%28graph_theory%29">trees from graph theory</a>, not <a href="http://en.wikipedia.org/wiki/Tree">those other kind of trees</a>.</li><br/> <li>Currently, all of those beautiful graphics are <a href="http://en.wikipedia.org/wiki/Procedural_generation">procedurally generated</a>. It is actually harder than you would think to draw a circle, at least in SDL.</li><br/> <li>It (and the idea to blog about the process) was inspired by <a href="http://www.shamusyoung.com/twentysidedtale/?p=11874">Project Frontier</a>, a fascinating project by an experienced graphics programmer who is making far more interesting things than I am with procedural content generation! But hey, give me time...</li><br/></ul><br/>So, the first step on the path to TreeWars was to learn enough SDL to generate a simple accelerated 2D image (not that it really needs to be accelerated right now, but I hope that will change in time). It turns out, this is both somewhat harder and somewhat easier than I expected.<br/><br/>I found a reasonably nice SDL tutorial <a href="http://www.sdltutorials.com/sdl-tutorial-basics/">here</a>. In fact, TreeWars was just 'sdltutorial' (with plans to start writing a game once I'd worked through some tutorial programs) until I got to lesson where you implement Tic Tac Toe, and my mind insisted 'Tic Tac Toe is boring, let's make a real game!' I justified that I often learn better when I'm puzzling out the best way to do something myself, and leapt into it.<br/><br/>The problem is, I often learn better that way, but I also often learn the <strong>hard</strong> way. I stumbled through a lot of 'wrong' ways of doing things in SDL, wasting a good deal of time hunting down the correct function (out of numerous functions available in the API) for getting a particular result. In the middle of all of that, it occurred to me that there is a knowledge level for which tutorials are never written. Tutorials are often written in a way that is so basic tha