7 April 2012

Ninja Air Hockey

Today, I'll be sharing a fun little game I'd made some time back - Ninja Air Hockey. It's your regular air hockey with a twist - You control your bat not with the mouse or keyboard, but with some colored object! Sounds weird? Check out its video in action:

I've decided to make it open source. Ninja Air Hockey was designed using openFrameworks and OpenCV. openFrameworks is an opensource C++ toolkit for creative coding. 

According to its authors, openFrameworks was developed:
(for) folks using computers for creative, artistic expression, and who would like low level access to the data inside of media in order manipulate, analyze or explore. That audience we felt was significantly underserved by the current crop of C++ libraries.

oF is designed to be used on Windows, Mac OS X and Linux and supports XCode, Code::Blocks, Visual Studio and EclipseI had used an older version of openFrameworks - v0062 on Visual Studio. This version is archived here. Here's how you can set it up on Visual Studio:

  • Download the Visual Studio 2010 FAT(v0062), and unzip it. 
  • You need to have OpenCV set up as well. For instructions on how to install OpenCV on Windows, check out the earlier post. Make sure you've Quicktime installed too.
  • Download the source code from google code here.
  • Copy AirHockey folder into apps/addonsExamples.
  • Open AirHockey.sln, wait for the project to load. Press F5 to run. When running for the first time, it can take upto 2-3 mins to start since Visual Studio will build the openFrameworks libraries first.

The all important source files are present in the AirHockey/src folder. And data files are present in the AirHockey/bin/data folder. Using them, you can build this project on the platform and IDE of your choice. Please refer to openFrameworks wiki for instructions on how to set it up on your platform and IDE.

Screenshot
The code is well commented and should be fairly easy to understand. For any questions, feel free to comment. :)

Cheers!

6 comments:

  1. I am a beginner and having problems with understanding the logic of your code..could you please provide me with a source which can help me develop logic from the scratch? like what you referred when you started all this to start getting a feel of the things? As of now,I am getting the meaning of several commands from the directory but not able to understand the logic as a whole. Thanks and would appreciate some help!

    ReplyDelete
    Replies
    1. I'm afraid the source code is the only thing I've on the project. I'd suggest reading a bit about openFrameworks and what programming logic openFrameowrks projects use.

      The program flow is: First, the game is initialized, and then in a continuous loop, elements get drawn to the screen, and then elements are updated. During the update phase, camera data is processed to obtain position of object being tracked. It's then mapped onto co-ordinates on the game board and then finally elements are drawn with new values.

      This is not very precise but what you're asking is difficult to explain through a comment.

      Delete
  2. This comment has been removed by the author.

    ReplyDelete
  3. I just got everything working with OF 007, OpenCV 2.3.1, and Microsoft Visual C++ 2010 Express. Thanks for the code. It is great to have a program to start from that works! Thanks - Dave

    ReplyDelete
  4. I really really like studying and following your publish as I discover them incredibly useful and exciting. This publish is similarly useful as well as exciting . Thank you for details you been placing on creating your website such an exciting. I provided something for my details. Airline Codes

    ReplyDelete