The Daily Click ::. Forums ::. Klik Coding Help ::. Phew, what a Pong, computer bat AI
 

Post Reply  Post Oekaki 
 

Posted By Message

Dean Avanti



Registered
  01/11/2006
Points
  130
19th September, 2007 at 17:52:02 -

Im doing a game that is a spin on the pong game, now Im doing the computer controlled bat, what I want is that the computer 'will return the ball much of the time', what I thought I could do that is by having the computer bat when the ball is in the second half of the screen, ie its side to follow the balls position, so it moves up and down to the position of the balls height.

That's what I've come up with, perhaps there are better ways, but its just what I came up with of the top of my head, how can I do this, Im learning as I go along, so I pick easy games to learn by, If one adds interesting extra features and adds some nice graphics, one can still make a nice game and learn MMF2s features as one goes along.

Thanks for any help.

 
http://www.avantivita.com
Video game developers and home of video game development assets.

Joe.H

Evil Faker

Registered
  19/08/2002
Points
  3305
19th September, 2007 at 18:07:41 -

Depending on the difficulty of your computer AI:

Give the opponent a velocity, provided it is less than the overall SPEED (not velocity) of the ball, it has a chance to miss it.

try to keep the opponent velocity to a set value, depending on the level. For example, easy would move by say, 5 pixels at a time, medium by 10, and hard by 15

this only works if you're increasing the speed of the ball after each contact with a bat, and will give you a few rallies before the oponent finally misses.

You then need to move it.

When the ball changes direction, have the oponent change direction as well, but it still stays at a constant velocity (perhaps give different delays for different difficulties)

 
My signature is never too big!!!

Dean Avanti



Registered
  01/11/2006
Points
  130
19th September, 2007 at 20:03:46 -

I was thinking more of the computer bat is set to randomly move up and down, it can miss the ball because it may be too far away to make it to the ball in time, that gives it some skill to aim at places far from the computer bat.

But I still need to know, how do I make the computer move up or down to be inline with the ball. It needs to follow the ball on the virticle, but I dont know how to do that.

Perhaps its like, if ball is in this area, if ball is above the bat move up, if ball is below the bat move down, but Im not sure how it can do a check for if the ball is above or below it.


Image Edited by the Author.

 
http://www.avantivita.com
Video game developers and home of video game development assets.

Assault Andy

Administrator
I make other people create vaporware

Registered
  29/07/2002
Points
  5686

Game of the Week WinnerVIP Member360 OwnerGOTM JUNE - 2009 - WINNER!GOTM FEB - 2010 - WINNER!	I donated an open source project
19th September, 2007 at 21:33:35 -

I'd have code that compared the Y position of the ball to the Y position of the bat. Most pong games just have the AI follow the ball, and for different difficulties you used different bat speeds.

Eg.
If Ball.Y > Bat.Y then Bat.Y = Bat.Y + 2

If Ball.Y < Bat.Y then Bat.Y = Bat.Y - 2

That's all there is to it and to make it easier or harder you just change the 2 to make the bat move faster or slower.

 
Creator of Faerie Solitaire:
http://www.create-games.com/download.asp?id=7792
Also creator of ZDay20 and Dungeon Dash.
http://www.Jigxor.com
http://twitter.com/JigxorAndy

Assault Andy

Administrator
I make other people create vaporware

Registered
  29/07/2002
Points
  5686

Game of the Week WinnerVIP Member360 OwnerGOTM JUNE - 2009 - WINNER!GOTM FEB - 2010 - WINNER!	I donated an open source project
19th September, 2007 at 21:39:56 -

I have too much free time so I decided to make the engine, it doesn't take long.
http://files-upload.com/files/514070/pong%20ai.mfa
In this example the ball is moving relatively fast so the paddle doesn't hit it back very often. Play around with the ball speed to see it return the ball more often.

 
Creator of Faerie Solitaire:
http://www.create-games.com/download.asp?id=7792
Also creator of ZDay20 and Dungeon Dash.
http://www.Jigxor.com
http://twitter.com/JigxorAndy

Dean Avanti



Registered
  01/11/2006
Points
  130
19th September, 2007 at 22:03:39 -

thanks for the help, that will do it for me, thanks for your time, now I can move onto the next part

 
http://www.avantivita.com
Video game developers and home of video game development assets.

Assault Andy

Administrator
I make other people create vaporware

Registered
  29/07/2002
Points
  5686

Game of the Week WinnerVIP Member360 OwnerGOTM JUNE - 2009 - WINNER!GOTM FEB - 2010 - WINNER!	I donated an open source project
19th September, 2007 at 22:35:43 -

No Problem, good luck. Feel free to ask more questions if you have any.

 
Creator of Faerie Solitaire:
http://www.create-games.com/download.asp?id=7792
Also creator of ZDay20 and Dungeon Dash.
http://www.Jigxor.com
http://twitter.com/JigxorAndy

DaVince

This fool just HAD to have a custom rating

Registered
  04/09/2004
Points
  7998

Game of the Week WinnerClickzine StaffHas Donated, Thank You!Cardboard BoxDos Rules!
20th September, 2007 at 04:01:53 -

I remember being really stuck with this way back, while the solution is really simple.

 
Old member (~2004-2007).
   

Post Reply



 



Advertisement

Worth A Click