Mentor has the right idea. What you need to do is have one of the player paddles track the ball, but use the speed variable to introduce some error into the tracking so it is not a perfect player.
You need to add some logic to your player 2 paddle control. Something like this...
rem Somewhere in your initialization code you need to set
rem computerPlayer to a non-zero value to activate the computer
rem player. The traditional value is either 1 or -1 depending
rem on your preference and previous coding experience. In a more
rem advance version, you might want to set computerPlayer a value
rem from 1 to 10 to indicate the relative skill level of the
rem AI opponent.
rem PLAYER 2 PADDLE MOVEMENT
if computerPlayer = 0
rem Human controlled paddle
IF keystate(17)=1 and player2pos#<3.5 then player2pos#=player2pos#+0.5
IF keystate(31)=1 and player2pos#>-3.5 then player2pos#=player2pos#-0.5
if keystate(17)=1 and ballx#<-4 and ballx#>-4.5 then balla#=balla#+8
if keystate(31)=1 and ballx#<-4 and ballx#>-4.5 then balla#=balla#-8
else
rem Computer controlled paddle.
if rnd(10)=0
speed#=0.9
else
speed#=1.0
endif
if player2pos# < ballz#
player2pos# = player2pos# + speed#
endif
if player2pos# > ballz#
player2pos# = player2pos# + speed#
endif
rem Movement limitation
IF player2pos# > 3.5 then player2pos# = 3.5
IF player2pos# < -3.5 then player2pos# = -3.5
endif
DISCLAIMER: You may need to tweak the logic or the constant values to get the results you desire. The purpose of this code fragment is to show you how to organize that logic and what to test for.
--
TAZ
[Yes, I can be a grumpy old man. But, I try to be helpful more than tactless.]
Posting tip 1: You first post here was correct. Anyone can click on the source button and see your code is a seperate window. You second post was redundant and you had the code tags backwards.
( [ c o d e ] and [ / c o d e ] not [ / c o d e ] and [ c o d e ] )
Posting tip 2: The code tags are handy when you want to display formated text where spacing is important. It is good for ASCII art, tables, and other forms of text as well as source code fragments.
History did not begin with PONG. -- Greg Costikyan
Game Beavers