This week I didn’t do nearly as much as I wanted to do on Whirlygig. Since I decided to commit to making a game last November, I’ve worked countless nights until somewhere between 12 and 2am. Eventually, that starts to burn me out a little. There have been a few people responding to my twitter updates, saying that they were excited to play it. That sort of stuff is really encouraging and always gets me excited to get back to work. The other thing that can be motivating is to actually play the game a bit. Mostly because I’m like…hey, this is kinda fun, I made this! I need to get my rear in gear and see if other people like it!

 

Whirlygig
I did get one of the things Whirly failed on fixed. Basically, if your game music uses the MediaPlayer, and the user has music playing already when the game starts, you have to ask their permission to stop their existing music. My audio work is centralized in a static, AudioManager class. I had a PlayMusic method that the menus and game screens would call so I mostly had to rework that to check into user permission. Since I’m trying to get more real-world code on here, I’ll show you very specifically how I did that. I’m sure this could be more elegant so post your critique in the comments.

First I added a couple variables to track whether I’ve asked permission:

private static bool mPlayPermissionRequested;
private static bool mPlayPermissionAllowed;

Then I rewrote the actual method:

public static void PlayMusic(MusicType requestedType)
{
    mLastRequestedType = requestedType;

    if (MediaPlayer.State != MediaState.Playing)
    {
	PlayMusicType(requestedType);
    }
    else
    {
	if (mCurrentMusicType == MusicType.User)
	{
	    if (mPlayPermissionRequested)
	    {
		if (mPlayPermissionAllowed)
		{
		    PlayMusicType(requestedType);
		}
		else
		{
		    // they like their music better...so sad.
		}
	    }
	    else
	    {
		RequestPlayPermission();
	    }
	}
	else
	{
	    if (mCurrentMusicType != requestedType)
	    {
		PlayMusicType(requestedType);
	    }
	}
    }
}

I also had to write a handler for the dialog box to set the variables correctly:

private static void UserPermissionCallback(IAsyncResult r)
{
    int? dialogResult = Guide.EndShowMessageBox(r);
    mPlayPermissionRequested = true;

    if (dialogResult == null || dialogResult == 0)
    {
	mPlayPermissionAllowed = false;
	mCurrentMusicType = MusicType.User;
    }
    else
    {
	mPlayPermissionAllowed = true;

	// since this is async we have to renew the original play request
	if (mLastRequestedType != mCurrentMusicType)
	{
	    PlayMusic(mLastRequestedType);
	}
    }
}

So, I’m sure that code could be improved but it works very nicely. Again, let me know in the comments if you see anything that sucks. I’m sure it’s there :)

 

Rett Syndrome

If you don’t know this already, my almost-four-year-old daughter Nora has Rett Syndrome. Yesterday we went to The Children’s Hospital to get an EEG to test for sub-clinical seizures and also get some x-rays to check for scoliosis. We had to sleep-deprive her, meaning we had to keep her up until midnight on Wednesday night and then wake her up at 4am. It was a crazy day but she doesn’t have any signs of scoliosis. We get the results of the EEG in a week or two.

 

PHP Frameworks:
This week I also have been exploring CodeIgniter, a lightweight, fast PHP framework. So far it’s pretty neat. It has a lower barrier to entry than Cake, Zend or some of the other frameworks I’ve checked out and it’s pretty pure OOP, which I also like.

 

In Other News: