Hi,
I've been following the tutorial for a while now and I've been trying to modify it myself. The first thing I wanted to do was change the ball to go a bit more randomly because when it starts out all you have to do is leave it there and it will go strait back and forth. What I did was just modify when it hits either paddle, it will go not 360 degrees but around 345 or some number like that. It seems to work ok.
I also tried to add a You Win! message win you get to 5 points. I tried the code by commando but it was wrong. I decided to just try myself and I tried to add after the scoring code:
if player2score#=5 then print "you lose"
if player1score#=5 then print "you win!"
It works, but the game keeps going. Also, since it keeps going if the player 2 gets to 5 then it says you lose also even if it has already said you've won. I need help on ending the game, I don't know the correct code for that.
The last thing I tried but couldn't do is lengthen the board for more time to prepare to hit the ball. I made object 4 longer to 15 and placed both paddles in the correct position, but I couldn't correct the ball bouncing code to make it hit the paddles correctly once they moved.
Here is the game code of the modified board/paddle:
rem HIDE THE MOUSE AND LIMIT THE SYNC RATE TO 40
hide mouse:sync rate 40
rem MAKE THE PADDLES, BALL AND FLOOR
make object box 1,1,1,3:color object 1,rgb(255,0,0)
make object box 2,1,1,3:color object 2,rgb(0,255,0)
make object sphere 3,1:color object 3,rgb(0,0,50)
make object box 4,15,0.1,10:position object 4,0,-0.55,0:color object 4,rgb(0,0,150)
rem SET THE BALL ANGLE TO 90 DEGREES
balla#=90
rem BACKROUND
COLOR BACKDROP rgb(0,0,0)
rem START THE MAIN LOOP
sync on:do
rem SCORING
if ballx#>6 then player2score#=player2score#+1:ballx#=0:ballz#=0:balla#=270
if ballx#<-6 then player1score#=player1score#+1:ballx#=0:ballz#=0:balla#=90
set cursor 300,50:print player2score#
set cursor 320,50:print "-"
set cursor 340,50:print player1score#
if player2score#=5 then print "you lose"
if player1score#=5 then print "you win!"
rem BALL MOVEMENT
ballx#=newxvalue(ballx#,balla#,0.3):ballz#=newzvalue(ballz#,balla#,0.3)
rem PLAYER 1 PADDLE MOVEMENT
IF upkey()=1 and player1pos#<3.5 then player1pos#=player1pos#+0.5
IF downkey()=1 and player1pos#>-3.5 then player1pos#=player1pos#-0.5
if upkey()=1 and ballx#>4 and ballx#<4.5 then balla#=balla#+8
if downkey()=1 and ballx#>4 and ballx#<4.5 then balla#=balla#-8
rem PLAYER 2 PADDLE MOVEMENT
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
rem BOUNCING
if ballx#>4 and ballx#<4.5 and ABS(player1pos#-ballz#)<1.5 then balla#=348-balla#
if ballx#<-4 and ballx#>-4.5 and ABS(player2pos#-ballz#)<1.5 then balla#=345-balla#
if ballz#>4 or ballz#<-4 then balla#=180-balla#
rem MAKE SURE balla# IS LESS THAN 360 AND MORE THAN 0
balla#=wrapvalue(balla#)
rem POSITION OBJECTS
position object 1,7.5,0,player1pos#:position object 2,-7.5,0,player2pos#
position object 3,ballx#,0,ballz#:yrotate object 3,balla#
position camera 0,10,-10:point camera 0,0,0
sync:loop
I tried adding 2.5 to both sides of ball movement and I got the ball to go the correct distance but it wouldn't make contact with the paddle. It would go through it and count it as a point every single time the ball was played.
Something I have no idea how to do is how to make the ball respawn slower so there's more time in between each round.
Any help is appreciated.
insert cool signature here