Share Your Code

Air Hockey 2 Player Game

Posted by carlos m. icaza, Posted on April 20, 2011, Last updated October 18, 2011

GitHub URL:

Air Hockey is a two player game designed to show off some of the physics engine properties of Corona SDK and how with a few lines of code you can write a very addictive game. First one to score five points wins. Works seamlessly across iOS and Android devices.

Open sourced MIT Licensed. Feel free to use the code as you wish. If you decide you want to make changes or additions, feel free to do so and let us know to share with our community.


User offline. Last seen 1 week 5 days ago. Offline
Joined: 11 Oct 2010

How is it that the puck can pass through the center line and the paddles can't? Is is due to the collision filter?

User offline. Last seen 3 years 4 weeks ago. Offline
Joined: 14 Dec 2010

how do you set play against Computer mode? im not a programmer... only language I know is HTML and Somewhat PHP

User offline. Last seen 13 hours 53 min ago. Offline
Joined: 9 Apr 2011

It's supposed to be like that. Play any air hockey game and those are the rules. You can't cross the centre line with your paddle :)

iPanda Lab
User offline. Last seen 1 year 42 weeks ago. Offline
Joined: 19 Sep 2011

I tried this sample source. It works very well when i drag first time.
But it show some of error when i touch again to drag.

-- error message.
gameUI.lua:81: attempt to call method 'removeSelf' (a nil value)
stack traceback:

i didn't' change any code. Can anyone help me!

iPanda Lab
User offline. Last seen 1 year 42 weeks ago. Offline
Joined: 19 Sep 2011

It is version problem. It works on Version 2011.632 very well.


User offline. Last seen 4 weeks 4 days ago. Offline
Joined: 16 Sep 2011


Congratulations for the game. It is very nice.

One suggestion: how about AI for a new Player vs Computer version!?


Leonardo Opitz

User offline. Last seen 2 years 28 weeks ago. Offline
Joined: 29 Jan 2012

Hey, I was working on the modified version of the game as suggested by Leonardo,, can someone please help me with the AI part?
How to get the computer to compute the best path to get to the ball?
PS- Plz try to answer ASAP

User offline. Last seen 10 hours 6 min ago. Offline
Joined: 4 Feb 2012


User offline. Last seen 4 weeks 6 days ago. Offline
Joined: 7 Apr 2012

The computer AI would be quite fun to code. In theory, you would need the computer to follow the y position of the puck, but with a randomness factor otherwise you would never win! The computer could return the puck and then remain stationary until the player returns in. That could trigger the computer to move its paddle.

I'd start off just making it follow the puck exactly (y pos) and then try and add "intelligence" (or lack of) to make it miss a few times. May have a go myself if other people want to share some code / ideas?

User offline. Last seen 2 years 15 weeks ago. Offline
Joined: 18 May 2012

I'm new to programming and have a very basic question. Nod I just coy the entire code file into the text editor? I'm using text wrangler? Or do I need to store the images and sound son where else? Any help would be greatly appreciated.

User offline. Last seen 2 years 7 weeks ago. Offline
Joined: 12 Jul 2012

i love this game, so simple but can keep you busy for hours!
it's even more fun than to play checkers
i wish i had it om my knew cell

User offline. Last seen 1 year 49 weeks ago. Offline
Joined: 22 Sep 2012

I possibly could try this sample source. It's effective once i drag it the first time.
Nevertheless it show numerous error once i touch again to drag.
my blog