Final Project - Air Hockey


By Marty Chinn (mchinn@cats)

What It Does

This program is a virtual simulation of the popular game Air Hockey. The goal of air hockey is to knock the puck into your opponents goal while preventing it from coming into yours. The game will be played to 7 points, but the winner must win by at least two points. Thus if there is a one point differential, when someone scores 7, the game will continue until there is a two point margin.

This game represents physical calculations based on time based animation. It also incorporates collision detection between the puck with the paddles and the walls.

How to Play

The player can rotate and tilt the camera to whatever view they prefer. There is no need to worry about control orientation as it is screen relative and is adjusted automatically as you rotate the camera. To move your paddle, simply hold down the left mouse button and keep it down for as long as you want to move the paddle with the mouse.

Once you have gotten used to moving with the paddle, simply try to block the puck from entering your goal and try to hit it into your opponents. In real life, air hockey machines have numerous holes in the surface of the table that blows air up. As a result, the puck will glide and move faster. So beware of how fast the puck may come.

For practice, you can try hitting the puck with the AI turned off. You can then turn on the AI whenever you want, as well as reset the position of the puck and restart the game itself.

How it Works

Since air hockey in real life uses air to make the puck glide, to represent the air in this program, there was simply a reduction of the friction on the surface. Calculations were based on 2D physical motion using velocity and acceleration. When the puck collides with the wall, it changes the velocity appropriate to reflect a bounce off the wall.

The AI checks to see if the puck first has crossed on to its half of the playing field. If it has, then it checks the distance between the paddle and the puck. If it is within a given range, it moves towards the puck. If it is not, it moves back to its initial position. The force applied to the puck will always be constant with the AI, and in this case, the AI hits it pretty hard. To make sure the AI wasn't completely unbeatable, I made it a bit weaker on one side. When playing, you can see that playing to the AI's right side will mean there's less of a chance of the AI getting to the puck than its left.

Results

Air Hockey AVI DIVX (250k)