Latest Tweet:
  • Loading...

I just completed my first XNA project, the very "Hello World" of game programming, a PONG clone! But as Tino Didriksen points out in his post "But Can You Make Pong?", PONG is an excellent project for any incipient game programmer. A simple game like pong touches all the major aspects of any computer game, such as:

  • Game Logic: Managing different game states, such as menu, playing, pause, end screen etc.
  • Graphics: Drawing simple 2D graphics, scores, menus etc.
  • Sound: What is PONG without the *doink* when you hit walls and paddles?
  • Controller Input: Your game should work with different input mechanisms like game pad, keyboard, mouse etc.
  • Physics: Velocity in 2 dimensions, collision detection, calculating reflection angles based on what part of the paddle that hit the ball.
  • User Interface: Any game needs menus, scores, a title screen and a end screen.
  • Computer AI: Well, PONG isn't AI in the traditional meaning of the word, but making the computer fun to play isn't as easy as you might think. It shouldn't be to hard or to easy to beat the computer.
  • Two player gaming: Gaming is always more fun when you play with friends.

Tino dives a little deeper into all the aspects of PONG in his blog, and discusses why PONG an excellent game for beginner, so I won't spend more time on it in this post. I strongly suggest checking out his post.

So as I mentioned in the beginning I just completed my implementation of PONG written using the XNA framework. I wanted my PONG game to be more "complete" than some of the XNA PONG samples available online. There are some nice tutorials you might check out. One of them is a video tutorial over at LearnXNA that walks you through an implementation of Pong. Two other implementations worth checking out are Rob Loachs' XNA Pong and Tiny Tennis up on Coding4Fun.

Some of the things you might learn from my implementation of PONG is:

  • How to do simple 2D graphics in XNA
  • How to handle different game states
  • How to implement a menu system
  • How to manage different controller mechanisms, such as game pad, keyboard and Wiiremote
  • How to do both one and two player gaming

I'm not going to include too much code in this blog post, but the code is well documented and should be a usable sample for XNA beginners. One of the "cooler" things in the sample is how I handle different input mechanisms. I've abstracted away the different controllers by creating an interface that the different classes handling the different controllers implement. So when the game starts I create an instance of the InputPC class, which tries to create an instance of all available controllers, and adds them to a prioritized list. I then iterates over the list and assign the best available controller to player1 and player2.

To handle cross platform support I've simply created a Xbox 360 project and linked in most of the files. There are only three classes that differ between the 360 and the Windows version of the game.

Another funny feature of the game is the "Pong Clock". When in the main menu the computer will play in the background, and the score will show the time. The left side loose once a minute, the right side will loose once an hour.

  

WiiMote
Robs post about his flock of butterflies flying around in XNA controlled with the WiiMote inspired me to pick up a WiiMote and play with it my self. As Rob mentions in the blog the hard part is not programming against the device, but getting it connected to the PC. The remote is quite picky about Bluetooth devices and stacks, and I spent quite a few hours to get this working. I tried using both my internal Bluetooth chip (IBM ThinkPad T43p) and an external Billionton Dongle. I also tried all kinds of Bluetooth stacks, including the Vista default one, the IBM drivers, the latest version of the Widcomm stack. I finally got it working using the Billionton external dongle and the Toshiba Bluetooth stack. Rob also had to use the Toshiba stack, so looks like they have a decent Vista implementation, so if you have problems connecting the WiiMote on Vista they might be worth checking out… For more information about the WiiMote and how to get it connected check out the WiiBrew Wiki.

The actual integration of the WiiMote in the game was fairly simple. To communicate with the WiiMote I used a managed API implemented posted up on Coding4Fun on MSDN. I created a new class that implemented the IPongInput interface, and use the buttons to navigate the game UI. To handle the actual game play I read the value for the Y axis from the accelerometer. The WiiMote spits out values from -1 to 1, and I simply check if the value is more than 0.05 or less than -0.05 to detect if the player is moving the paddle up or down. I also create a "effect" parameter to calculate the Y-speed of the paddle.

So if you hold the WiiMote at a steep angle you'll get more speed on the paddle. After some tweaking it turned out really nice!

Downloading and playing the game
I've included the compiled Windows version of the game, a XNA Creators Club compiled package of the 360 version, and the full source code of both versions. To play the game on your Windows computer you need the XNA runtime. The game is written using the recently released XNA refresh, so if you haven't downloaded it you need to do that first. To play the 360 version of the game you need a "XNA Creators Club Subscription" and XNA installed on your computer. To deploy the game to the 360 simply double click the "package" to start the deployment process.

The game is licensed under the BSD license, so you're free to do what ever you want with the code. Have fun go mad!

Tuesday, May 01, 2007 2:01:20 AM (W. Europe Daylight Time, UTC+02:00)
Nice one!! Welcome to the world of XNA! :) :)
Tuesday, May 01, 2007 2:26:44 AM (W. Europe Daylight Time, UTC+02:00)
Thanks Rob!

Just finished watching the MIX07 keynote.. And I'm blown away... My brain is melting! :P

Have an amazing time over there!
Tuesday, May 01, 2007 6:10:26 PM (W. Europe Daylight Time, UTC+02:00)
Very cool! This is one of the first sites I've seen sharing a XNA Creators Club Game package, very awesome!
Tuesday, May 01, 2007 6:21:37 PM (W. Europe Daylight Time, UTC+02:00)
Thanks Michael. Did you download the package? The day Microsofts creates an XNA-blade in the dashboard where you can download, comment and rate packages is going to be just awsome!
Wednesday, May 02, 2007 1:19:40 AM (W. Europe Daylight Time, UTC+02:00)
Unable to compile them :( comes up with "The referenced component WiimoteLib" could not be found.

Silmar
Wednesday, May 02, 2007 10:29:16 AM (W. Europe Daylight Time, UTC+02:00)
Bah. The "Clean Solution" item deleted referenced assemblies from the BIN folder... Anyhow, I've updated the XPongSource.zip file, so the WiimoteLib.dll is now included.

Just re-download the code and give it a go.

Thanks for letting me know!
Wednesday, May 02, 2007 11:59:17 PM (W. Europe Daylight Time, UTC+02:00)
Morro for oingan(: Selv om du ble litt pwn'a av Hege, så ut som den var litt trass å få til å bevege seg. Men tøft uansett. På nippet til å kalle det en killer ap. (hvis det er en "ap", hehe)
Espen
Thursday, May 03, 2007 8:44:09 AM (W. Europe Daylight Time, UTC+02:00)
Haha. Du får prøve deg neste gang du er innom. Jeg er blitt ganske god med den + at på videoen så sitter jeg litt rumpe til pga. kamera, så har ikke helt "feelen" ;)

Du er en killer-ape
Friday, May 04, 2007 7:21:29 PM (W. Europe Daylight Time, UTC+02:00)
Yep! I sure did and it worked great. I had one question, is there a reason you zipped the .ccgame file? Did you web server not understand it?
Saturday, May 05, 2007 5:26:11 PM (W. Europe Daylight Time, UTC+02:00)
I didn't try.. Old habbit i guess. I assume I could add some mime-type to IIS to tell it how to handle .ccgame files? What should i accociate it with? application/g-zip..?

Cool to hear that you deployed the game to your Xbox! :)
Wednesday, August 01, 2007 12:48:20 PM (W. Europe Daylight Time, UTC+02:00)
xvlkzmegp uqgaloci hkns jpqvb ltjzwcs iuzbvfygh zgdxnja
Wednesday, August 01, 2007 12:49:00 PM (W. Europe Daylight Time, UTC+02:00)
xvlkzmegp uqgaloci hkns jpqvb ltjzwcs iuzbvfygh zgdxnja
Wednesday, August 01, 2007 12:49:28 PM (W. Europe Daylight Time, UTC+02:00)
xvlkzmegp uqgaloci hkns jpqvb ltjzwcs iuzbvfygh zgdxnja
Name
E-mail
(will show your gravatar icon)
Home page

Comment (Some html is allowed: a@href@title, strike) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Enter the code shown (prevents robots):

Live Comment Preview
<March 2010>
SunMonTueWedThuFriSat
28123456
78910111213
14151617181920
21222324252627
28293031123
45678910