Android Game Dev - Basic 'Pong' Game AI Help

Associate
Joined
11 May 2010
Posts
29
Evening people, I've been working on my first Android app for a few days now and it has been going pretty well however I've run into some problems when trying to add an AI paddle (bat).

I fully understand the logic behind the functionality (or at least I think I do!) but due to my lack of knowledge when it comes to java I'm unable to somewhat portray it on screen.

So I currently have a bat at the bottom of the screen ( which is moved left and right via buttons located in the bottom two corners, planning to implement alternate means of control in the future) A ball which bounces off the top, left and right sides of screen and of course bounces off the player controlled bat.

My plan:

I'm trying to implement an AI controlled bat along the top of the screen and have plans on how to calculate the chance of it missing etc that's not an issue, collision detection will also be fine as I can simply mirror what I have already done.

My problem is, I cant figure out as to how I am going to get the AI controlled bat to 'follow' the ball in a smooth fashion or even follow it at all..

Any help or pointers would be so helpful,


The link to my project code is just below, do excuse any horrific code :rolleyes:

https://www.dropbox.com/sh/idms12imhdu4rh8/EnqAoxNWsZ

Cheers !

Ben
 
Associate
OP
Joined
11 May 2010
Posts
29
Thanks spike I've given it a good go ! seems to be working great :)

I'm now getting a bit ambitious and trying to implement a 'difficulty' system, my thinking behind it is as follows:

In 'settings' there will be an attribute called with either 1 (Easy),2 (Medium) or 3 (Hard) - each representing a different set of conditions.

Each level of difficulty will generate a random number between the range of 0 - 100 when the ball hits the players bat. Now this is where it differs, in terms of the easy condition IF the number was to fall between 0 - 25 the AI Bat will miss the incoming ball, medium 0 - 20 and so forth.

I can then save these settings to memory to future use relatively easily as I have done the same for sound. I'm not 100% if any of this would work, just looking for a bit of guidance really.

If anyone has any advice, or even any code snippets that I could have a look at I'd be pretty chuffed.

I've updated my game since the last posting the new link is below:

https://www.dropbox.com/sh/krhigysxah2xxpy/92cNkqgx90

note I've AI'ed the player bat as well so I can see the game running and spot any collision bugs.
 
Back
Top Bottom