PDA

View Full Version : AirHockey game help



Amax2
March 15th, 2004, 08:23 PM
Well I am creating a air hockey game and I am just brainstorming on what I will need to do in order for the game to work...(getting to the point) I dont know the AS to move the puck accros the screen to hit the paddle and bounce back, also bounce of the walls. I also have no idea how I am going to increase the velocity of the puck when it is hit hard by the paddle. Same goes for the puck when it is hit softly. Please help. Thank You.

bombsledder
March 15th, 2004, 08:56 PM
you will probabaly have to learn some triganometry in flash.

hmm if this is your first time using flash how about starting of

with something easier

Amax2
March 15th, 2004, 10:09 PM
I understand the trig of flash.

Math.sin(angle)
Math.cos(angle)
Math.tan(angle)
------------------------
inverses
------------------------
Math.asin(number)
Math.acos(number)
Math.atan(number)
Math.atan2(y,x)
------------------------
to find projection....
------------------------
len = c or hypotinuse of triangle

for x
x=len*Math.cos(ang);

for y
y=len*Math.sin(ang);
------------------------
also that flash reads only radians except when dealing with (_rotation). To change from degrees to radian you have to multiply the degree by Math.PI/180.
------------------------
I understand vectors (somewhat)
displacement, force, rotation are all vectors.
vectors consist of a magnitude and a angle.
-----------------------
i just need some help with writing the script.

this game will also deal with some kinetic energy for the paddle and puck collision. ke = (1/2)*mass*speed*speed

also

momentum = mass*velocity

Johnny64
March 16th, 2004, 05:45 PM
http://www.amazon.com/exec/obidos/tg/detail/-/0201770210/002-3267973-9857614?v=glance

It explains very thing you just asked.
I have this book too and it great

=)

Amax2
March 16th, 2004, 11:48 PM
Hahaha that is too funny. I have that book right now and I am working through it as we speak. Maybee I just havent gotten there yet. Well I got to the part where i can make the ball move on either the x and y axis with some friction.

for example
ymov = 10;
friction = .95;
_root.onEnterFrame = function() {
ymov *=friction;
ball(or whatever you name the MC)._y+=ymov;
}

I also figured out how to create hitTests using some math instead of us the hitTest(_root.MC) {} meathod. Which will help alot. Frame Independents is what its called. So yea. Im getting there... to the completion of my game. When I am done I will post it for you guys to play.

still I need help with the velocity of puck and paddle detection in order to increase the speed of the puck when hit at a higher or lower velocity.

also to move the ball on the x and y axis.

flash4food
March 17th, 2004, 12:27 AM
great, post a link to it when u finish or to show ur progress

Amax2
March 18th, 2004, 04:45 AM
.

Johnny64
March 19th, 2004, 09:53 AM
Originally posted by Amax2


still I need help with the velocity of puck and paddle detection in order to increase the speed of the puck when hit at a higher or lower velocity.

also to move the ball on the x and y axis.

well puck velocity shouldn't be too hard you can just let the puck stick to the player and then when you click the puck fire's in the dir. of the mouse.
you can get the angle like this.
Math.atan2(puck._y-_ymouse,puck._x-_xmouse);//just exampel
when you know the you can use cos() and sin() the more it in that dir. :)

If you had a different type of game-play in mind. Say so :)

Amax2
March 22nd, 2004, 05:40 PM
Can someone help me make this puck move on the x and y axis. Here is my .fla file. Also how do you make it so when the puck gets hit by the paddle its velocity gains speed?

Johnny64
March 23rd, 2004, 01:29 PM
F5/MX/MX2004?
Mac/Win/Linux?

:P
I can't open your file

Amax2
March 23rd, 2004, 05:31 PM
ill make it a zip file so that it wont get all curropted over the net. I need to do it when i get home though. Its MX on a PC

Amax2
March 24th, 2004, 02:48 AM
flash mx
pc

Amax2
March 27th, 2004, 02:22 AM
here are is my knew fla. Ive gotten pretty far on it.
check it out.

I still have a problem with my hitTests. and tahts all.

Johnny64
March 27th, 2004, 12:51 PM
:thumb:

Amax2
March 30th, 2004, 03:41 AM
almost done with my game guys.

I created the AI for the computer. It works good too.Took me a couple of days and alot of hours. Also with some help by Milkman (A friend in my multimedia class). I fixed some bugs with the hittests. I changed them from being hitTests to using the distance formula. Works way alot better if anyone wants to know. I also set up all the goals and scoring system. I just need some sound, intro page, and anyother things that may make it better. Ill post the game.swf when i am completly done.

Amax2
March 31st, 2004, 03:39 AM
umm its not done, but try it out and give feedback :)

Johnny64
March 31st, 2004, 12:19 PM
the AI is great :thumb:

but its still a bit easy. If I try my best, the computer never gets a chance to score.

good work :)

flash4food
March 31st, 2004, 07:42 PM
cool, i have two observations:

first, when you start if you hit the ball with the maximum speed posible, the ball goes so fast it "goes through" the computer, this could be solved with lesser speeds and higher framerate maybe

second, does the AI solely consists on just easing to the puck's position if it its on the computers side of the field??

Amax2
April 2nd, 2004, 06:51 PM
IF you pay close attention to the puck and the computer you will notices that if the puck is hit to the lower part of the table then the AI will hit it up and if you hit the puck to the top of the table then it will hit it down. I have put easing actionscript on the AI but there are alot of random events occuring. For example. If the puck is greater 175 of the y axis then hit the puck down at a random angle from 1 to 20 and with a random speed of 1 to 10. Same goes for the other way arround. I made the ai pick up the puck once the puck passes the half way point. I am still having trouble with my hittests but i will figure it out eventually.

Amax2
April 6th, 2004, 04:00 AM
check it out. I still need some sound...if anyone knows where i can get some sounds that will fit thes game than let me know. I also need to fix some other little things.

http://airhockey.741.com/index.html

tommythewolfboy
April 6th, 2004, 07:33 AM
Good stuff. All that AI and angles would give me a headache!

My only comment (hopefully constructive!) is that rather than the puck coming to an abrupt stop when it touches the paddle (is that what they are called?!?!), is that it slows the puck speed instead - it seems to 'stick' to the paddle instead at the minute at speeds it would otherwise bounce off.

rajeevrm
May 14th, 2004, 10:10 AM
anybody helps me regarding Ai programming for air hockey...every thing is working fine but i m not getting idea about Ai of computer

dropkick
May 14th, 2004, 05:03 PM
It looks pretty good...a few small things though - like Tommy said, the puck shouldn't stick to the paddle at all(the puck got 'trapped' under the paddle a few times), the paddle should always follow the mouse cursor(if you move the cursor outside of the game, then back in there is an offset between the actual mouse position and the paddle), and the easy, medium, and hard buttons need to be expanded(now you have to click on the letters for them to do anything)

signifer123
May 14th, 2004, 08:19 PM
the ai is impossible either you score or they score

Weazol
May 15th, 2004, 06:04 AM
ok i have to critisicms like they said before the puck shouldnt stop when it hits the paddle... another if you move the mouse fast enough the paddle will fly right over the puck then knock it back into your goal