8 Rules for Losing Weight Like an Engineer

Introduction

Well, it’s January, and that means that many Americans have recently made some new resolutions for 2012, and one of the most common resolutions is to lose weight. So, despite the fact that I am a software engineer and not a personal trainer or nutritionist, I’m going to offer some unsolicited advice on how to lose weight like an engineer =)

Engineers like to measure, quantize, track, and analyze data in order to achieve their goals, and this approach actually does make a lot of sense for losing weight.

Rule #1: 3500 calories is roughly equal to a pound

One of the underlying assumptions you’ll want to make when trying to lose weight like an engineer is that, roughly speaking, 3500 calories is equal to a pound of body weight. In other words, if you consume 3500 more calories in a day, a week, or a month than you burn, then at the end of that period of time you will be roughly one pound heavier. Conversely, if you burn 3500 more calories in a day, a week, or a month than you eat, then you will be roughly one pound lighter.

Rule #2: Calculate Your Caloric Baseline

Your caloric baseline is the average number of calories that you burn in a day, without factoring in workouts or exercise. This number is basically the sum of your Basal Metabolic Rate (your daily energy expenditure at rest) plus any other typical activity that you perform during your day while working, recreation, doing errands, etc. This number also happens to be the average number of calories you’d need to eat in a day to maintain the same weight indefinitely.

It would be pretty inconvenient to spend an entire day in bed hooked up to a calorimetry machine in order to calculate your basal metabolic rate, and it would also be pretty annoying to try to go about your daily business hooked up to a machine in order to figure out your caloric baseline. Fortunately, there are several caloric baseline calculators available on the web that can guesstimate your caloric needs based on your height, weight, age, and general activity level. You’ll probably want to choose the “sedentary” or “light” options so that you can track your exercise separately.

Rule #3: Calculate Your Caloric Goal

One of the biggest mistakes you can make is to try to lose too much weight at once via crash dieting. The generally accepted maximum amount of weight you should try to lose in a week is about two pounds. Why?

  • You could easily lose lean mass (muscle) in addition to fat.
  • You are physiologically and psychologically more likely to binge eat after an unsustainable crash diet.

So, let’s say you want to lose about one pound per week. So your goal is a 3500-calorie deficit per week, or 500 calories per day (when divided by seven). So subtract 500 calories from your caloric baseline and you have your average caloric goal.

Rule #4: Track What You Eat

Now that you have a caloric goal, the next step is to measure your diet to see how many calories it contains. There are a number of websites that provide calorie information and calorie tracking:

Personally, I like Daily Plate because it has a very large and easily-searchable food database, it allows you to track your exercise as well as food, and it can actually calculate and track your progress against a caloric goal.

Another thing you might want to consider, to make measuring calories easier, is to purchase a food scale and use it to determine exactly how much of certain ingredients you’re using when cooking or preparing food. For example if you’re making a sandwich, or cooking some chicken, it can be difficult to tell just how many ounces of meat you’re using without one.

Rule #5: All Calories Are Equal, Except When They’re Not

It’s true that all calories, whether they come from fat, protein, carbohydrates, or sugar, are all basically the same in that they will all cause you to gain weight if you eat too much of them. But, there are some caveats to the basic rule that “a calorie is a calorie”:

  • Your diet should include at least a sizable amount of protein so that you maintain muscle mass. Without protein, you’ll lose muscle mass fast.
  • Some foods are more filling than others per calorie, especially ones with low energy density. Fruits, vegetables, and lean proteins generally have high volume and/or fiber compared to their calorie content, so they help you feel full longer.
  • Salt is not necessarily as bad as we might think it is, but it can lead to water retention. Further, eating salty foods (like chips or fries) can lead to eating more of a food than you would have otherwise because it tastes so good.
  • Alcohol can be pretty bad for weight loss. First, because you are consuming “empty calories” that don’t actually make you feel full. Second, alcohol often leads to increased appetite, which explains late night post-drinking cravings for Jack in the Box. This article does a really good job of explaining alcohol’s overall effect on weight loss.

Rule #6: Track What You Do

If you calculated your daily caloric needs as a “sedentary” or “light” lifestyle, then you’ll want to keep track of how many calories you burn while doing exercise. There are three basic ways to track calories burned while working out:

  1. If you’re using a cardio machine, such as a treadmill or elliptical machine, these will generally estimate your calories burned based on your weight and your speed. However, cardio machines are notorious for overestimating calories burned while exercising.
  2. Use an online calories burned calculator to guesstimate how many calories you’ve burned. This is also not particularly accurate because these calculators assume a relatively consistent amount of calories burned per sport, but intensity levels can vary greatly among individuals.
  3. Buy and use a Heart-Rate Monitor with a calorie count feature. This should take the actual intensity of your workout into account and should be much more accurate than the other two methods.

In addition to the overestimation problem of counting calories, there’s another problem – we tend to focus on the total calories burned of an exercise, not the net caloric burn. In other words, we fail to subtract the extra calories we burned working out versus what we would have been doing instead (like working or using the computer). So when you track calories burned, you might want to intentionally under-report them or possibly not track them at all.

Rule #7: Track What You Weigh

This one is pretty simple. Get an accurate bathroom scale and make it a habit to weigh yourself every day right after you wake up (and after going to the bathroom). Your weight tends to be most “stable” in the morning, so this is the best time to do it. Why do this?

  • It keeps you accountable. Psychologically, it’s much harder to let yourself go and overeat if you see your numbers creeping up.
  • It gives you more data to play with, and engineers love data.

The second part is kind of a joke, but if you track your daily weight you could use it to plot a moving average to see how your weight is trending over time. Since weight tends to fluctuate day-to-day, it can be more visually motivating to see your weight tending downward over time as you stick to your caloric goals.

Rule #8: Weight Isn’t Everything

It’s funny, we tend to make resolutions like “Lose 10 pounds this year”, but we fail to account for the fact that losing weight and losing fat are not quite the same thing. We also tend to equate fitness with being thin, but they’re really not the same thing at all.

If you’ve been tracking your diet and your exercise, you may have noticed that it’s far easier to eat one less slice of pizza than it is to jog for half an hour per day, so you might be tempted to skip exercising and just focus on your diet. But this would be a mistake.

Consider this – would you rather be a slightly overweight person who runs half-marathons, or a very skinny person who can barely walk from their house to their car without getting winded? Let’s be honest, the first person is more fit, and fitness is more important than weight for health.

Further, for every pound of muscle mass that you have, your basal metabolic rate goes up, because those muscles are hungry for calories (especially protein). So over time as you develop more muscle from working out, lifting weights, or doing sports, it should become easier to burn more fat.

I could write an entirely new post on various pros and cons of different exercises and sports, but suffice to say that you should definitely include some kind of regular exercise into your routine while trying to lose weight, in order to maintain muscle mass while losing fat.

Top Ten Things I Like About Seattle

10. Portland / Vancouver

Both Portland and Vancouver are only a few short hours away from Seattle by car, or if you prefer, you can take the train. I’ve been to Portland a few times and I really like it. I’ve also spent about a week in Vancouver and it’s also a pretty cool place to be. I have to admit, I prefer the Portland / Vancouver combo to Houston and Dallas.

9. Sushi / Thai / Indian / Teriyaki / Chinese

Let’s face it, Seattle is not known for its Tex-Mex. But once you get over that (if that’s possible), you can learn to enjoy the diverse range of Asian cuisine available here. I’m especially fond of the Sushi… and the Indian… and the Thai. Okay, I’ll only pick my top three.

8. Nerd Culture (VG Live, PAX, Microsoft, etc.)

The nerd culture is very strong in Seattle / Bellevue, and I kinda like it. This is true of Austin too of course, but in Seattle I have attended PAX and Video Games Live, neither of which I did in Austin. Most of my best friends in Seattle play video games with me, which is all kinds of awesome. For some reason my friends in Austin were much harder to convince to play video games with me – weird!

7. Stone Gardens, Vertical World, and Marymoor Park

Seattle is host to two competing climbing gym companies, Verical World and Stone Gardens, and this is a good thing. Between the two and the three Seattle / Redmond locations, you can go for an awesome bouldering experience, an awesome toprope/lead experience, or a mix of both. Vertical World even hosts an “outdoor club” in the summer which takes people out for climbing on Friday evenings. Awesome. These gyms are truly key for the rainy winter season.

Marymoor Park is also excellent, because it features a sizable outdoor climbing structure in the park where you can climb for the completely reasonable price of $1 to park. This is a great place to practice some crack climbing and leading, if you’re into that sort of thing.

6. Greenlake

Seattle has a lot of bodies of water all over the place. Lake Washington, Lake Sammamish, even South Lake, but my favorite is Greenlake. A relatively small lake north of downtown Seattle, this lake features a 2.8 mile bike/walk path which is absolutely beautiful in the summer. This is my favorite place to run 2.8 miles.

5. Mount Rainier

I’ve never climbed Mount Rainier, but on a really clear day you can see it from Seattle, and it looks awesome. Like a huge distant giant, guarding over the city. You can make a pretty good day trip out of driving around this huge mountain, taking in views from Crystal Mountain, Sunrise Lookout Point, and more. You can also see it from the air when you fly into or out of Seattle.

4. Long Summer Days

The northern latitude makes winters miserable, but the summers more than make up for it. The omnipresent rain goes away, the weather turns into sunny 70s nearly every day, and best of all, the sun doesn’t go down until 9pm in June. I’m not kidding, it’s amazing.

3. Snowboarding at Snoqualmie, Stevens, Crystal, Bachelor, and Whistler

Washington isn’t known for its snow, and it’s certainly no rival to Colorado, but compared to Texas, it’s a winter wonderland. There’s actually quite a bit of variety available between Canada, Washington, and Oregon, with Snoqualmie, Steven’s Pass, Crystal Mountain, Mt. Bachelor, and more. I haven’t even been to them all yet. And did I mention Whistler? It’s like the biggest mountain ever. Seriously. It’s much bigger than Vail.

2. Surfing at Westport

I had no idea when I moved to Seattle that surfing was even an option here. But it is, thanks to the small town of Westport. The city doesn’t produce waves, but the nearby finger jetty does, and every time I’ve been to Westport I’ve caught waves. You might want to check the surf forecast of course, but this town is only 2.5 hours from Seattle, and has 2-3 surf shops that you can rent gear at, as well as a couple great places for lunch or a post-surf snack/beer. Part of me wants to move to Westport just so I can surf every day.

1. Rock Climbing at Vantage, Exit 38, and Smith Rock

Between Exit 38, Vantage, and Smith Rock, you can easily go sport climbing within a half-hour, 2.5 hours, or 8 hours from Seattle, respectively.

Exit 38 is not particularly big, and I’m not super fond of the granite, but it’s a ridiculously convenient crag for its proximity to Seattle. Great for post-work evening climbs in the summer.

Vantage is easily my favorite sport area in Washington. It’s basically several lines of columnar basalt, varying from about 50 feet tall to nearly 100, and I absolutely love the way this rock feels. Since it’s located east of the Cascades in a somewhat desert-like part of Washington, it’s often hot and sunny here even when it’s raining and miserable in Seattle. Some truly epic climbs here, and I have only explored a portion of it.

Smith Rock is well known even outside of Oregon for being an epic place for sport climbing. There are literally hundreds of routes here, and they are stiff. It’s a bit harder to get to, since it’s about an 8-hour drive, but it’s definitely worth it for a long weekend.

In addition to these three, there are numerous other places nearby: Squamish in Canada, Index, Leavenworth, Darrington, Mount Erie, Tieton, and Mazama, half of which I’ve never even visited yet.

RenameM4A

Introduction

For better or for worse, I use iTunes to manage the music on my iPhone. And since I have to have iTunes installed on my computer, I might as well also use it to rip my audio CDs into music files. Traditionally, the file format of choice was MP3, also known as MPEG-1 Audio Layer 3. However, a few years ago I heard about a new file format called AAC (Advanced Audio Coding) promising better sound quality than MP3s at similar bitrates, which iTunes also supports. So I went ahead with a project to re-rip all of my CDs from MP3 into AAC files, which by the way, have the file extension .m4a.

The problem I encountered was that I really disliked the file/folder structure that iTunes automatically uses when it rips your CDs. There seems to be no way to customize this file/folder structure in iTunes, so if you really care about what your files are named and in what directories they are placed, as I do, you’re stuck renaming all of your music files by hand, which is a major pain.

Therefore RenameM4A was born. This simple C# program allows you to select a set of M4A files and rename them according to a rename rule.

Rename Rules: Using RenameM4A

A rename rule is a simple way of enforcing a particular file/folder structure for any M4A file that is to be renamed. Because this is a very simple project, right now the rename rules support the following tags:

As you can see, the tags are surrounded by brackets which denote some kind of information contained within the file. All AAC files have metadata embedded in them which tells you information about the track and where it came from. When RenameM4A processes each file, it looks at the rename rule and replaces any tags encountered with information gathered from the file itself. This step takes place when you press the Preview button, which generates a list of files to be renamed, giving their original file locations and the new file location.

Then, you can hit either the Rename button or the Copy button to move or copy the file according to the destination paths given in the GridView. In fact, if you want to you can edit the GridView in order to fix any discrepancies that may have occurred when running the rule. For example, you might have a track from a particular band’s album where another artist is featured. Since you want the entire album contained within the same folder, you might edit the line for that track to remove the name of the other artist from the directory name.

If you take a look at the rename rule combo box, you can also see that there are a number of pre-loaded rename rules that may appeal to you.

How is AAC better than MP3?

In short, AAC files have superior sound quality and transparency than MP3s do, for the same bitrate. Put another way, you can encode your music at a lower bitrate than an MP3 for the same sound quality. Of course, there are a lot of other improvements, including:

  • More sample frequencies
  • Up to 48 channels of audio
  • Better handling of audio frequencies above 16 kHz
  • More flexibility in designing codecs

Advanced Audio Coding File Format

A SourceForge project called Atomic Parsley appears to have a lot of good information on the MPEG-4 file format, especially as it relates to M4A files. As it turns out, the AAC data is actually just a section within an MPEG-4 file, which can actually contain all kinds of nested data. Each nested section in an MPEG-4 file is called an atom (or sometimes a box); the first four bytes of each box defines its length in bytes, the next four is the name of the box, and the rest is either data or other nested boxes. In a way, that’s pretty similar to how XML works.

Since the only thing that RenameM4A really cares about is the album, artist, year, title, and track number, it simply scans the file for the five atoms it’s interested in and grabs the data. It’s also worth noting that text data appears to be stored in UTF-8 format, so you can’t simply assume that it will be straight-up ASCII.

Recent Improvements

This blog post actually took me a ridiculously long time to write. Mainly that’s because I was a bit embarrassed to release my source code; it was written several years ago and the way it was parsing M4A files was extremely naive. Recently, I rewrote most of the parsing code to make the following improvements:

  • More intelligent parsing; use atom information to jump to the sub-atoms of interest instead of scanning the entire file for “udta” and then each meta tag.
  • Reading only part of the file; since all metadata is under the “moov” atom, RenameM4A only needs to load the portion of the file under moov. The vast majority of a music file’s size is its music data, which is under the separate mdat atom, so we can avoid loading the entire file into memory when we don’t need to.

I did a simple benchmark test of the new and old parsing algorithms by trying to parse 14 half-hour audio files ten times each. The old parser takes about 36 seconds; the new one takes 0.14 seconds; an improvement of around 270 times faster. Not bad.

Download RenameM4A Source + Executable

[RenameM4A Source + Executable]
Note: Requires .NET Framework 2.0 or later.

References

MPEG-1 Audio Layer 3

Advanced Audio Coding

MPEG-4 Part 14

Atomic Parsley

Atoms, Boxes, Parents, Children & hex (oh my)

Subject: Dissection of m4a format – msg#00046

How To Install Perforce Source Control On Your Windows Home Server

Personal Source Control

If you’re a developer like me, chances are that in addition to the programming you do at work, you probably also have some personal projects that you work on at home as well. Whether you are consulting on the side, or just want to write your own applications, it may make sense for you to have a source control server of your own. There are many benefits to having a home source control system, including:

  • Having a backup of your source code
  • Access to revision history and previous versions
  • Single repository for source code across multiple machines

These are all very good things. It’s very reassuring to know that your source code will still exist on the source control server if your hard drive should crash and burn. It’s also nice to be able to revert to previous versions of your code should you irreparably break something. And lastly being able to easily synchronize source between multiple machines, such as your desktop and laptop, is very handy.

Why Perforce?

You can of course use any source control system you are most comfortable with. I used Perforce quite a bit at National Instruments, and it makes sense to me. I like the ability to have multiple changesets at once. I like that I have a consistent, semi-permanent mapping from my hard drive to the source depot. And most of all, I like that I can install it for free.

I also previously installed an SVN server, and was using TortoiseSVN for a while to check in code on my home network. This kinda sorta works, but… I don’t really like it. It’s hard to explain, but I am so familiar with the way that Perforce works that using TortoiseSVN is a pain. For example, it doesn’t seem like there is any permanent mapping between the source server and your hard drive. You can check out a folder to anywhere, and update a folder from anywhere, but it’s really easy to screw it up. And as for checking out code, well, it seems like you don’t check it out so much as you download it locally, edit it, and then try to commit your changes. I’m sure there are people out there that use it and love it, but I can’t wrap my head around the way it’s supposed to work, and I’d rather use a paradigm much more familiar to me like the one Perforce uses.

Installing P4D

You can download the Perforce Server, called P4D, from Perforce Downloads. I chose Windows for 32-bit Intel (x86) for my machine. Install it. You can pretty much keep all of the default options.

Once it’s installed, you can take a look at your system Services, and you should see that the Perforce service is Started and is Automatic.

Create a New User and a Depot

Use the command p4 user -f from a command prompt in the Perforce directory to create a new user. Your text editor will open a temporary file used to configure your user’s options. You can stick to simply editing the full name and adding a password.

Use the command p4 depot to create a new source depot. You will probably already have a default depot called “depot”, but I added a new one because I want it to be called Root, and I wanted it to be located in D:\Root\ on my server. As before, when you execute this command a temporary document will open in your text editor. Most likely you will just want to change the Map parameter.

Fix Your Firewall

In order to allow connections from other machines on your network, you need to tell your Windows Home Server to allow connections on port 1666, because that’s the port that the Perforce server uses by default. Open up your Windows Firewall Settings, select the Exceptions tab, and click on the Add Port button. Type in “Perforce” and “1666” respectively. Now your Perforce client should be able to connect to the server.

Installing P4V

Now you’re ready to install the Perforce Visual Client, or P4V, on your desktop or laptop. Again, you can download the client from Perforce Downloads. Go ahead and install. Again, you can leave most of the options as default, but you will want to change the server name to match the name of your Windows Home Server.

Go ahead and run the Connection Setup Wizard. You will probably have to manually choose your server name, and to login with the username and password you created on the server. Don’t bother copying files from the server to your workspace, as there are no files in your depot yet.

Once that’s done, your P4V window should look approximately like this:

Creating a Client Workspace

Perforce allows each user to have a set of client workspaces, which is essentially just a way of mapping the depot folders you are interested in to a local drive on your machine. Create a new workspace like so:

Enter a name for your new workspace; generally people use some combination of their username and machine name.

Now, you have to define your client spec. The most important two fields are the Root and the View. Here I set my root to D:/Perforce/Artemis_Hexar/. All of my source files will be under this directory. Next I set my View to a single line mapping of //Root/… //Artemis_Hexar/Root/… The ellipses are a symbol that means all subfolders and files. So here I’m just saying that everything under the Root depot should go under the clientspec, in the Root directory. You can do some interesting things with the View, including exclusions and inclusions, but it’s probably not necessary for our purposes here.

Now your client probably looks something like this:

Add Files to Source Control

Lastly, it’s time to add some files to source control. Take some files that you want to add, and copy them into your clientspec root. For me that means D:\Perforce\Artemis_Hexar\Root\. Next, click on the Workspace View tab so that you can see your local disk tree instead of the depot tree. Right click on the files/folders you want to add and choose “Mark for Add…” This will add them to the default changelist.

Lastly, right-click on the default changelist and submit. You should write a comment on the reason for the change, and make sure you really do want to submit all of the files in that changelist. Now, if you go back to the Depot view, you can see that your files have been added to the depot, and you can check them out for editing, deletion, or rename.

Conclusion

So that’s it! Congratulations, now your personal projects have professional source control. Check in some code, and celebrate with the food/beverage of your choice.

My Favorite iPhone Apps (So Far)

Why I have an iPhone

So I recently won a free iPhone 3GS 16GB because I entered my name into some kind of online contest. Amazingly, the day after I submitted my name I actually won, and about a month later my iPhone came in the mail. Being a cheap bastard, and afraid of signing a 2-year contract with AT&T, I declined to get a data plan but I kept the phone anyway so that I could play with it like a shiny new toy.

Anyway, I thought I’d go ahead and share my favorite iPhone apps so far:

Facebook – Free

This one is a no brainer. It’s just like Facebook.com, except with a more intuitive interface for the iPhone. Not all of the functionality is there yet, but still, this is the fastest and easiest way use Facebook on the iPhone without doing some kind of weird zooming dance with your fingers in a Safari browser.

Twitterific – Free

I haven’t tried any other Twitter apps, but this one works pretty well. Since I don’t spend a huge amount of time on Twitter this is good enough for me. Your mileage may vary.

Skype – Free

Thanks to Skype, I can use my iPhone like a phone, without paying AT&T a dime. I still have to pay Skype of course but hey, it’s pretty cheap and it works internationally. As long as I have wifi access.

Pandora – Free

Internet radio for free on your iPhone. This is for when I get bored of listening to all of the music I already have. Of course it would also be nice if my iPhone supported actual AM/FM radio but this is the next best thing.

SpanishDict – $1

I had a hard time finding an English-Spanish dictionary that works without Internet access, and this one does. It actually also has several other features, like a word game, some key phrases, a daily word, etc., but mostly I use it for the dictionary. This came in super handy in Colombia a couple of times actually.

Spanish! – $1

Yes, another Spanish app. This one is a pretty awesome flashcard application, with 1000 Spanish words built in. It somewhat reminds me of SuperMemo, in the way that it introduces new words to you slowly and as you master words you see them less often, whereas words you miss a lot show up more often. You can try to remember the English definition of Spanish words or vice versa, and it will even pronounce all 1000 Spanish words if you touch them. This app is a really awesome way to build your vocabulary, and much easier than making your own set of real-life flash cards.

Fling! – $1

Fling is an addictive puzzle game where you basically try to fling a set of furballs in a grid toward each other in order to knock them off the board, until only one furball remains. The gameplay is simple, but the puzzles get increasingly more difficult to sequence. This one is definitely a good way to waste some time if you need to do so, for example on a long bus ride or while waiting for the waiter to finally take your order.

Cube Runner – Free

A simple “racer” type game where you steer by tilting the iPhone itself, and the object of the game is to make it through a random field of cubes without hitting any at increasing speeds. There are three difficulty levels, but even on Easy you’ll be challenged to beat your own high score.

Flight Control – $1

This game is my latest obsession, and several of my friends’ as well. Basically a random sequence of different planes enter an airfield and your job is to touch and drag them into a path that will land them onto a runway, or in the case of helicopters, a landing pad. The object is to land as many aircraft as possible without any of them hitting each other. Add in some tricky things like planes of different speeds and this game becomes a really challenging multitasking clusterfield, if you will. You can also send planes to a buddy while playing multiplayer mode on wifi or Bluetooth. Definitely check this one out.

Your Favorite Apps?

Go ahead and leave a comment and tell me what your favorite iPhone apps are. What am I missing?

HexarViz: An XNA Music Visualizer

Media Player Visualization Data

Recently, at a local Microsoft GameDevz meeting that I attended, we had a short 45-minute contest to see which 2-3 person team could come up with the coolest visualization given a relatively simple XNA project that retrieves visualization data from the song currently playing in the Media Center. HexarViz is an evolution of the project that my partner Daniel Taylor and I came up with during this competition.

The way to retrieve music visualization data from XNA is very simple. Call the MediaPlayer.GetVisualizationData method in XNA 3.0 or later, and you will retrieve an object of type VisualizationData. The VisualizationData class provides only two properties, Samples and Frequencies. The former is an array of 256 float values from -1.0 to 1.0 indicating the raw amplitude of the currently playing sound sample. The latter is an array of 256 float values from 0 to 1.0 indicating the logarithmic scaled power value of each frequency band in the currently playing sound sample – essentially the result of a FFT on the sound data. The frequency distribution seemed like a more obvious choice to use in a visualizer, so that’s what we used.

HexarViz

The idea for this visualizer was inspired by the standard horizontal bar UI that is typically used to display the currently playing frequency bands. It looks like this:

And in fact, this is the first part we implemented, by using a simple 10×10 white square as a texture, and drawing one red rectangle per frequency band, from the left side of the screen to the right. But, let’s be honest, that’s boring, because it’s been done a million times.

We wanted something more interesting, so I thought maybe it would be cool to make the frequency band values rotate around a center point, kinda like a circle. Except since each rectangle drawn rotationally this way will have a different length depending on its power value – so the shape of this sound circle will change drastically over time. Here’s basically what that looks like:

This image depicts pretty closely what we ended up with for the competition, in about 45 minutes. We also had a few rudimentary features:

  • Previous Song / Next Song
  • Sound Circle Rotation

But like I said, HexarViz is an evolved version of the results of that competition, meaning that after the competition I added a lot of features, namely:

  • Pause
  • Volume Up / Volume Down
  • Displaying the currently playing playlist, album, artist, and song name
  • Playlist change support
  • Toggle individual Red/Green/Blue components of the target color
  • Color Cycling
  • Change the current texture

Color Cycling was probably the most difficult part to implement. In order to effect a smooth transition of target colors, I calculate the HSB (Hue/Saturation/Brightness) of the current target color, increment the hue, and then convert back to an RGB value. The color of each individual rectangle is also a linear interpolation between black and the target color, based on the frequency band’s percentage of maximum power.

Changing the current texture, from a 10×10 white square to something else, also has some very interesting effects on the way that the sound circle looks. Give that a try.

Source and Windows Installer

[HexarVizSource]

[HexarVizInstaller]

Controls

Change Playlist – P
Previous Song – Left Arrow
Next Song – Right Arrow
Pause – Spacebar
Increase Volume – Up Arrow
Decrease Volume – Down Arrow
Toggle Spin – S
Toggle Red – R
Toggle Green – G
Toggle Blue – B
Cycle Colors – C
Change Texture – T
Quit – Escape

HexShooter: An XNA 2D Tutorial Upgrade

XNA Game Studio 3.1

XNA Game Studio, if you haven’t heard of it, is an integrated development environment for the development of Windows and Xbox 360 games using either C# Express 2008 or Visual Studio 2008. It is essentially a Visual Studio Package which includes a set of XNA assemblies, as well as new project types to create Windows and Xbox 360 games. The latest version, 3.1, was released earlier this year and its newest features include video playback, an updated audio API, avatar support, and use of the XBox Live Party system.

In addition, budding game developers with a Premium Creators Club account can submit their game to the XNA Creators Club for peer review; if passed, these games can be sold on Xbox Live Indie Games for $1, $3, or $5. Developers receive 70% of all sales revenue for copies of their game that are purchased via Xbox Live. Not too bad a deal, though creating an independent game with mass market appeal and a decent purchase rate is no small task.

Creators Club Website

The epicenter of all things XNA is located at the XNA Creators Club Website. This is where you obtain a Premium account, submit your game for review, playtest others’ creations, and access a multitude of resources including forums and tutorials.

The 2D Tutorial

The Beginner’s 2D Tutorial uses video to demonstrate how to create a simple 2D shooter starting from a blank Windows Game project, given a couple of pre-created images. The videos walk you through creation of the game project, adding assets, drawing the background, creating cannons, firing cannonballs, adding enemies, and destroying enemies. It’s actually a very handy tutorial, and you end up with something like this (skip to 4:17)

HexShooter

As you can see in the video above, there are three enemy ships moving from right to left at all times, and you can shoot them to earn points. It’s pretty smooth, but there’s something important missing. Because there’s no inherent challenge, no sense of danger, and no real goal, this project is unfortunately little more than a toy, and the fun factor is completely missing. HexShooter is my attempt to take this project and change it in ways that will make it challenging and fun.

So here’s a list of some of the features I added:

  • Explosions and Smoke (from Joshua Foss’ excellent Adding 2D Particles and Explosions videos.
  • The ability to move the cannon from left to right with the left thumstick, aiming now with the right.
  • Enemies now spawn from either the left or right sides of the screen, and they bounce off the edges and come back with the same height and speed.
  • Player cannonballs are now very fast, but you can only have one on screen at once.
  • Enemies now fire green cannons back at you, and if they hit the center circle of your cannon, you lose.
  • For every ten enemies killed, a new enemy is added.

There are several reasons why I think this upgrade is a lot more fun to play than the original. First, there is the very real possibility of losing, and there is a challenge. Namely, kill as many aliens as you can while avoiding enemy fire for as long as possible. Because of the way that enemies are added, the game starts out easy but becomes increasingly challenging the more enemies you kill. Eventually you will find yourself spending most of your attention on dodging enemy fire, which reminds me of the fun and challenge of Galaga.

The choice to change the cannon to only fire one fast cannonball at once was also intentional. In the tutorial version, you can fire three cannonballs at once, but they are very slow. This makes aiming and firing tedious and somewhat pointless. With only one cannonball, you have to make your shots matter, so your aim counts.

For a while I considered creating a complete mesh-based collision detection system for the cannon, including not just the circle but the barrel too. But I realized that not only would that be a lot of extra work, but it would probably detract from the gameplay. Having to worry about your cannon aim in order to dodge enemy cannonballs is silly, and would make evasion nearly impossible in the late game.

Source and Executable

I am offering both the source code and executable for inspection and playtesting. If you want to compile and run the source you must have XNA Game Studio 3.1 installed.

[HexShooter Source]

If you just want to play the game, you need to have the Microsoft XNA Framework Redistributable 3.1 installed, and either:

Or, you could just use the keyboard.

[HexShooter Installer]

Using the keyboard isn’t too bad, but if you’d like to use an Xbox controller, I’d recommend the cheaper USB wired controller, unless you already have some Xbox 360 controllers lying around and you absolutely must have wireless controllers.

Controls

Move – Left thumbstick or A/D keys
Aim – Right thumbstick or Left/Right arrow keys
Shoot – Right trigger or Spacebar
New Game – Start or Enter