This blog was mentioned in XNA Club Communique 46

I know I read this one, but I completely missed my own name in it:
http://blogs.msdn.com/b/xna/archive/2010/03/18/creators-club-communiqu-46.aspx

Pretty amazing, and I only saw it thanks to a pingback. Now I have to get back into XNA… I miss it and I haven’t posted anything here since March. I think that’s when I started playing WoW again.

A coworker recently shared a game called Chain Reaction with me that I think would translate well into XNA. Better yet, the graphics are easy to build from scratch, which tends to be one big reason I abandon projects. I’m not even a shred of an artist or digital music producer (I can lay tracks, but they aren’t good), so there is a lack of content there that makes indie dev difficult for me. I might give this game a go and see how it turns out.

IGameActionManager interface for simplifying input management.

While reading all the latest WP7 buzz, I got to thinking that I am going to need some way of managing input between devices so as not to have a billion #if WINDOWS_PHONE or #if XBOX preprocessor statements all over my game logic. The solution is a pretty simple yet elegant abstracted IGameActionManager interface.

Here is the interface I have defined so far:

    public interface IGameActionManager
    {
        bool IsJumping();
        bool IsMovingRight();
        bool IsMovingLeft();
        bool IsMovingUp();
        bool IsMovingDown();

        bool IsIdle();
        bool IsFiring();

        void GetNewState();
    }

Each function corresponds to a typical game action, and the GetNewState() function gets the state for all input devices associated with the implented class itself. Knowing nothing of the implementation, other than which one you want, your game logic would look something like this:

    IGameActionManager actionManager = new WindowsGameActionManager();

    // somewhere in your update method:
    actionManager.GetNewState();
    if (actionManager.IsJumping())
    {
        // Do your jump logic here
    }
    if (actionManager.IsMovingLeft())
    {
        // Do your move left logic here
    }

That eliminates code like:

    #if !XBOX
    KeyboardState keyboardState = Keyboard.GetState();
    if (keyboardState.IsKeyDown(Keys.Space) && previousKeyboardState.IsKeyUp(Keys.Space))
    #else
    GamePadState gamePadState = GamePad.GetState();
    if (gamePadState.DPad.Up == ButtonState.Pressed)
    #endif
    {
        // Do your jump logic here
    }

The result is less clutter in your game code itself, but more importantly, your code is more game related. You are now worrying about things like “Is the player trying to jump” instead of “is the player pressing the key that I designated to jump?”

I’m still working out exactly how to handle previous state code within the class, but for now you would probably have to declare a previous IGameActionManager object and get a new state at the appropriate time. The code is still cleaner than worrying about actual key presses throughout still, though.

Here is a windows implementation example for the IGameActionManager:

    public class WindowsGameActionManager : IGameActionManager
    {
        KeyboardState keyboardState;
        GamePadState gamepadState;

        public WindowsGameActionManager()
        {
            GetNewState();
        }

        #region IGameActionManager Members

        public bool IsJumping()
        {
            return keyboardState.IsKeyDown(Keys.Space) ||
                gamepadState.DPad.Up == ButtonState.Pressed;
        }

        public bool IsMovingRight()
        {
            return (keyboardState.IsKeyDown(Keys.Right) &&
                keyboardState.IsKeyUp(Keys.Left)) ||
                (gamepadState.DPad.Right == ButtonState.Pressed &&
                gamepadState.DPad.Left == ButtonState.Released);
        }

        public bool IsMovingLeft()
        {
            return (keyboardState.IsKeyDown(Keys.Left) &&
                keyboardState.IsKeyUp(Keys.Right)) ||
                (gamepadState.DPad.Left == ButtonState.Pressed &&
                gamepadState.DPad.Right == ButtonState.Released);
        }

        public bool IsIdle()
        {
            return !IsMovingDown() && !IsMovingLeft() && !IsMovingRight() && !IsMovingUp();
        }

        public bool IsFiring()
        {
            return keyboardState.IsKeyDown(Keys.RightControl) ||
                gamepadState.Triggers.Right > 0.0f;
        }

        public bool IsMovingUp()
        {
            return (keyboardState.IsKeyDown(Keys.Up) && keyboardState.IsKeyUp(Keys.Down)) ||
                (gamepadState.DPad.Up == ButtonState.Pressed && gamepadState.DPad.Down == ButtonState.Released);
        }

        public bool IsMovingDown()
        {
            return (keyboardState.IsKeyDown(Keys.Down) && keyboardState.IsKeyUp(Keys.Up)) ||
                (gamepadState.DPad.Down == ButtonState.Pressed && gamepadState.DPad.Up == ButtonState.Released);
        }

        public void GetNewState()
        {
            keyboardState = Keyboard.GetState();
            gamepadState = GamePad.GetState(PlayerIndex.One);
        }

        #endregion
    }

Please drop a comment if you find this useful, or send me a tweet: @DomenicDatti

XNA and Silverlight coming to Windows Mobile!

I purchased an HTC Ozone (upgradable to WM6.5), and a couple months later the Droid came to Verizon. Needless to say, I was upset, but there was nothing I could do about it.

Enter Microsoft:
http://www.engadget.com/2010/03/04/microsoft-talks-windows-phone-7-series-development-ahead-of-gdc/
http://blogs.msdn.com/ckindel/archive/2010/03/04/different-means-better-with-the-new-windows-phone-developer-experience.aspx

That’s right… XNA and Silverlight are coming to Windows Mobile 7. Before now, I was just counting the days until my current Verizon contract was up so that I could get my hands on a Droid. That would’ve meant learning a whole new set of development tools, and possibly a new language altogether (I’m not too sure what development for the Android OS is all about). Now, though, my current .NET & XNA skills should be transferable!

A quote from the Engadget article:
…[Charlie] Kindel boldly proclaims that “If you are Silverlight or XNA developer today you’re gonna be really happy.”

I sure am.

I can’t wait to see what all the great XNA devs come up with for the gaming side of things, and it should be pretty interesting to see what type of apps are made using Silverlight. The possibilities are endless and exciting.

My only hope is that they build upon the successes of the Xbox Live Indie Games platform and allow independent game developers to distribute their games and make some cash. Every other similar phone has a market place right now, and to not include that capability would be a devastating mistake on Microsoft’s part. Without the ability to buy a phone, search for fun apps & games, buy, and play with them immediately, I don’t believe that anyone could look at all their options (e.g. iPhone and Droid) and choose a “crippled” Windows Mobile 7 phone over them.
Update: http://twitter.com/wp7dev/status/10005356682 there will be a marketplace. WOOT!

All in all, it’s an extremely exciting announcement, and I hope that everyone sees the potential like I do.

I leave you with a demo of the Windows Mobile 7 phone:

http://www.youtube.com/watch?v=7IOTrqlz4jo

Two useful classes from Nick Gravelyn

Nick Gravelyn posted something that I thought people might find useful:

http://nickgravelyn.com/2010/01/using-interpolators-and-timers/

Using this code would nearly trivialize the use of interpolating intro/outro type  effects. I like it!

Crontab script generator

I was making a crontab script for a customer today when I got the inspiration to finally do what I have been wanting to do for a while. I wrote a script to write the script for me. This handy script reads in 4 parameters:

  1. The working directory (where to cd to)
  2. A binary file (or command to run)
  3. A file containing the PID of the process to restart
  4. An output file to save the script to.

This generates a script that can be run from anywhere, like the crontab which will check to make sure the process is running. It will restart the process if not by running the binary file parameter.

The generated script is based on the Unreal3.2 ircdchk script, with some slight modifications. I hope someone finds it useful… if you do, drop a comment here.

BeatPong beat triggered particle systems

No video this time (yet), but I wanted to post to let anyone who is interested know that I have been making some slow progress with BeatPong. I just committed revision 20 which  showcases a single particle system that is triggered on a beat.

The new XML beat element format is:
<Beat effect=”smoke” duration=”00:00:05.0000000″>00:00:12.8150000</Beat>
The new effect attribute specifies a name for the particle system, and the duration specifies how long the particle system will be on for. The inner text still specifies the time of the beat. This particular beat would occur at 12.815 seconds into the song, and the smoke effect would last for 5 seconds.

Right now it’s pretty basic… with every beat, if the beat has an effect attribute,  a function is called to add the DateTime object which specifies when the specified particle system should stop emitting particles. The times are stored in a Dictionary<ParticleSystem, DateTime> object. The UpdateSmokeParticles() function checks the DateTime for the smoke particle system every time the update runs (60 per second by default in XNA), and if the current time is less than or equal to the end time in the dictionary, it emits a particle. Plain and simple right? I forgot that the emitter is also moved along with the ball, and the ball is made invisible, so you get the effect of smoke coming out where the ball should be.

The code can be found here:
http://code.google.com/p/beatpong/source/browse/trunk/Screens/GameplayScreen.cs#210
http://code.google.com/p/beatpong/source/browse/trunk/Screens/GameplayScreen.cs#328

I’m pretty excited about this, as it lays the framework for other beat triggered events, and it will be the foundation for all the particle effects that need to be beat synchronized.

BeatPong gameplay demo

I have been hard at work on BeatPong, recently adding a menu system and a score reading at the top. I took the menu system from an XNA creators club example and adapted it to BeatPong. The example can be found here:http://creators.xna.com/en-US/samples/gamestatemanagement. Obviously, if you download the code as is, you will see that the options menu is completely bogus still, so it’s definitely a work in progress.

I think the coolest thing about how this was integrated is that the menu pause works by pausing the game update method essentially and pausing the music simultaneously. It’s a pretty basic function, but one of those things that just feels great to see in your own project.

Also important to note is that the player 2 paddle (right) is controlled by AI. If the ball is above the paddle, it moves up, and if the ball is below the paddle, it moves down. The speed of the paddle is limited to the same speed as the left side’s paddle, making it possible to score.

Here is the video:
http://www.youtube.com/watch?v=ozl3Xzu7hk8

Domain name registered – geekpowers.com

Well the site is now official! I registered geekpowers.com today, and I’m super stoked that I was able to find what I believe to be a great domain name. The site map is registered with Google, so now I just have to crank out some useful content, and maybe it will attract some readers.

It should work fine… after all, I have geek powers.

BeatPong

I’ve been working on a game that, in concept, would synchronize the horizontal velocity of a pong ball to music. The ultimate goal is of course to do this in real time, but for a proof of concept I have started developing the idea with an XML file which signifies the beats of a song. Here is what I have so far:

First video: http://www.youtube.com/watch?v=yyaUibyrigg

Second video:
http://www.youtube.com/watch?v=FadV-tHOkqU

This video shows the ball with a locked vertical velocity for the sake of the demonstration. Prior to making this video, I used the record mode that I made. The song plays in the background, and I hit the spacebar on every beat. All the beats that I laid out with this method were then stored into an xml file (format shown @ http://xml.pastebin.com/f1e5cbe33). This video shows the playback of that XML file while the song plays in the background. Every time the ball hits a paddle, the horizontal velocity is adjusted so that it will hit the other paddle at the time when the next beat occurs.

Up to date code can be found here: http://code.google.com/p/beatpong/

I think it’s pretty slick… I hope others do too :-) More to come!

My Twitter

Error: Twitter did not respond. Please wait a few minutes and refresh this page.