Computer-controlled movements, or the so-called Artificial Intelligence (AI) , are sometimes very hard to create. But for a start, we will keep it very simple. And simple will be the key here. Our computer-controlled movement will look like this. One paddle will move with a speed of 10 pixels up and down, the other with a speed of 5 pixels in the opposite direction.
ControlEnemies
.Method ControlEnemies:Int()
FOR
loop for this, so we don't have to repeat the code. Remember that arrays in Monkey are zero-based.For Local ep:Int = 0 to 1 eY[ep] += edY[ep] 'Update the paddles Y position
If eY[ep] < 25.0 Then 'Check if paddles reaches top wall eY[ep] = 25.0 edY[ep] *= -1 'Revers its Y speed Endif
If eY[ep] > 455.0 Then 'Check if paddles reaches bottom wall eY[ep] = 455.0 edY[ep] *= -1 'Revers its Y speed Endif
FOR
loop and the method.Next Return True End
UpdateGame
method.ControlPlayer()
ControlEnemies() 'Control the enemy
Return True
Pongo_06.Monkey
.Cool! All paddles are moving. Now only the ball is missing. Let's get rollin'!