Pong AI

Get help using Construct 2

Post » Sat Feb 06, 2016 1:34 am

hi,
I'm trying to replicate the classic game Pong.
I thought it should be easy to make a 1 player vs computer game, but I can't make it work.

I've tried something like this:
Computer player = 8 directions, 2 up 2 down
Every tick ----> set computer player Y position to ball.Y

It works but the computer can't be beaten.
Is there a way to add some delay?

Thanks
B
5
S
1
Posts: 42
Reputation: 471

Post » Sat Feb 06, 2016 5:26 am

I once wrote a 1 player pong game to see how few events I could write it in. It's all in 2 events, so it uses some advanced tricks. But you can see the AI paddle moves in the direction of the ball, but at a set speed, so it is possible to get the ball past the computer player. If you set it directly at the ball position, there's no way to sneak it around.

https://dl.dropboxusercontent.com/u/854 ... Pong2.capx

Play it here: https://dl.dropboxusercontent.com/u/854 ... index.html

or here is an image of all the events:
Image
B
242
S
63
G
33
Posts: 903
Reputation: 40,756

Post » Sat Feb 06, 2016 11:23 am

..
Last edited by owlora on Mon Apr 25, 2016 1:49 pm, edited 1 time in total.
B
7
S
3
G
1
Reputation: 1,166

Post » Sat Feb 06, 2016 12:57 pm

The simplest of all is changing "Every tick" to "Every X seconds" (0.05, 0.1, 0.15, etc), that will add a delay to the AI movement. Moreover you can set the seconds to random() that will add a bit of realism. Do a bit of testing and eventually you'll get it right.

Every 0.05 seconds -> Ball.Y < Paddle.Y -> Paddle simulate pressing UP (reverse for DOWN).
Ba-dum Tsss!
B
11
S
2
G
1
Posts: 45
Reputation: 757

Post » Sat Feb 06, 2016 9:23 pm

thanks guys! it's working now
B
5
S
1
Posts: 42
Reputation: 471


Return to How do I....?

Who is online

Users browsing this forum: NN81, Seruza and 10 guests