Programmer of Power heres Sven B's buttons implemented into your pong program, i think...
This is sloppy and poorly written of me, but I'm new to this code, used it for a month or so a long time ago, but cudn't figure out how to do anything, and I just restarted using it. The exit button may or may not work, but that all i found wrong with it, Sven B's buttons are really helpful ,and I think I may just snatch that code to use in my programs
Good luck, i hope i helped, yet somehow i doubt it...
rem hide the mouse and set sync
hide mouse:sync rate 20
hide light 0
set ambient light 10
make light 1
position light 1,20,10,10
sync on
autocam off
position camera 0,10,-10:point camera 0,0,0
level#=1
player2movespeed#=.5
`um, randomize... the timer.... i thnk...
randomize timer()
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,30,30:color object 3,rgb(0,0,50)
set object specular 3,rgb(200,50,50)
make object box 4,15,0.1,10:position object 4,0,-0.55,0
make object box 5,15,4,2: position object 5,0,0,6
make object box 6,15,2,2: position object 6,0,0,-6
rem SET THE BALL ANGLE
balla#=rnd(45)+45
goto menu1
menu1:
hide object 1
hide object 2
hide object 3
hide object 4
hide object 5
hide object 6
show mouse
`if this button is pressed, go to the main game loop!
if button3(100,10,"Start Game!") > 0
show object 1
show object 2
show object 3
show object 4
show object 5
show object 6
goto mainloop
endif
`if this button is pressed, exit the program!
if button3(100,115,"EXIT") > 0
exit
endif
sync
goto menu1
rem START THE MAIN LOOP
`tag for main loop
mainloop:
do
gosub movement
gosub scoring
gosub bouncing
gosub positioning
`check to see if boss lvl
for x=1 to 4
if level#=5*x
bosslvl#=1
endif
next x
rem MAKE SURE balla# IS LESS THAN 360 AND MORE THAN 0
balla#=wrapvalue(balla#)
sync
loop
levelup:
bossspeed#=player2movespeed#*1.5
level#=level#+1
inc player2movespeed#, .2
for x=1 to 6
color object x, rgb(rnd(255), rnd(255), rnd(255))
next x
ink 0,rgb(rnd(255), rnd(255), rnd(255))
player1score#=0
player2score#=0
return
movement:
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 ai to find ball
if playerpos2#>object position z(3) and object position z(2)>-3.5
player2pos#=player2pos#-player2movespeed#
position object 2,-5,0,player2pos#
endif
if playerpos2#<object position z(3) and object position z(2)<3.5
player2pos#=player2pos#+player2movespeed#
position object 2,-5,0,player2pos#
endif
rem BALL MOVEMENT
ballx#=newxvalue(ballx#,balla#,0.3):ballz#=newzvalue(ballz#,balla#,0.3)
return
scoring:
rem SCORING
if ballx#>9 then player2score#=player2score#+1:ballx#=0:ballz#=0:balla#=rnd(45)+45
if ballx#<-9 then player1score#=player1score#+1:ballx#=0:ballz#=0:balla#=-(rnd(45)+45)
set cursor 300,50:print player2score#
set cursor 320,50:print "-"
set cursor 340,50:print player1score#
if player1score#>=10 and player1score#-2>=player2score#
gosub levelup
endif
return
bouncing:
rem BOUNCING
if ballx#>6.5 and ballx#<7 and ABS(player1pos#-ballz#)<1.5 then balla#=360-balla#
if bosslvl#=0
if ballx#<-6.5 and ballx#>-7 and ABS(player2pos#-ballz#)<1.5 then balla#=360-balla#
endif
if bosslvl#=1
if ballx#<-6.5 and ballx#>-7 and abs(player2pos#-ballz#)<2.25 then balla#=360-balla#
scale object 2,1,1,1.5
bossspeed#=player2movespeed#
endif
if ballz#>4 or ballz#<-4 then balla#=180-balla#
return
positioning:
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#
return
```````````````````````````````````````````````
` `
` THESE ARE THE BUTTON FUNCTIONS `
` `
```````````````````````````````````````````````
`makes button 1 (in big grey box)
function button1(x,y,xsize,ysize,content$)
colortheme = rgb(200,200,200)
pressed = 0
if mousex() > x and mousex() < x + xsize
if mousey() > y and mousey() < y + ysize
if mouseclick() > 0 then pressed = mouseclick()
endif
endif
if pressed = 1
ink rgb(rgbr(colortheme)/2,rgbg(colortheme)/2,rgbb(colortheme)/2),0
box x,y,x+xsize-1,y+ysize-1
ink rgb(255,255,255),0
box x+1,y+1,x+xsize,y+ysize
else
ink rgb(rgbr(colortheme)/2,rgbg(colortheme)/2,rgbb(colortheme)/2),0
box x+1,y+1,x+xsize,y+ysize
ink rgb(255,255,255),0
box x,y,x+xsize-1,y+ysize-1
endif
ink colortheme,0
box x+1,y+1,x+xsize-1,y+ysize-1
ink 0,0
center text x+(xsize/2),y + (ysize/2) - (text height(content$)/2),content$
endfunction pressed
` to make a button like button 2 (changes color when moused over)
function button2(x,y,content$)
colortheme = rgb(255,0,0)
pressed = 0
tx = text width(content$) / 2
ty = text height(content$) / 2
if mousex() > x - tx and mousex() < x + tx
if mousey() > y - ty and mousey() < y + ty
pressed = 1
endif
endif
if pressed = 1 then ink colortheme,0 else ink rgb(255,255,255),0
center text x,y - ty, content$
if pressed > 0
pressed = mouseclick()
endif
endfunction pressed
`makes a button like button 3 (dissapears when moused over)
function button3(x,y,content$)
colortheme = rgb(255,255,0)
if rgbr(colortheme) > 0
if redval = 0 then redi = 1
if redval = rgbr(colortheme) then redi = -1
inc redval,redi
endif
if rgbg(colortheme) > 0
if greenval = 0 then greeni = 1
if greenval = rgbg(colortheme) then greeni = -1
inc greenval,greeni
endif
if rgbb(colortheme) > 0
if blueval = 0 then bluei = 1
if blueval = rgbb(colortheme) then bluei = -1
inc blueval,bluei
endif
pressed = 0
tx = text width(content$) / 2
ty = text height(content$) / 2
if mousex() > x - tx and mousex() < x + tx
if mousey() > y - ty and mousey() < y + ty
pressed = 1
endif
endif
if pressed = 1 then ink rgb(redval,greenval,blueval),0 else ink rgb(255,255,255),0
center text x,y - ty,content$
if pressed > 0
pressed = mouseclick()
endif
endfunction pressed
EDIT:
Oh, and you could probably sidestep having to hide, and then show all objects with a different command, like uh, CLS? lol here, this works:
rem hide the mouse and set sync
hide mouse:sync rate 20
hide light 0
set ambient light 10
make light 1
position light 1,20,10,10
sync on
autocam off
position camera 0,10,-10:point camera 0,0,0
level#=1
player2movespeed#=.5
`um, randomize... the timer.... i thnk...
randomize timer()
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,30,30:color object 3,rgb(0,0,50)
set object specular 3,rgb(200,50,50)
make object box 4,15,0.1,10:position object 4,0,-0.55,0
make object box 5,15,4,2: position object 5,0,0,6
make object box 6,15,2,2: position object 6,0,0,-6
rem SET THE BALL ANGLE
balla#=rnd(45)+45
goto menu1
menu1:
cls
show mouse
`if this button is pressed, go to the main game loop!
if button3(100,10,"Start Game!") > 0
goto start
endif
`if this button is pressed, exit the program!
if button3(100,115,"EXIT") > 0
exit
endif
sync
goto menu1
rem START THE MAIN LOOP
`tag for main loop
start:
do
gosub movement
gosub scoring
gosub bouncing
gosub positioning
`check to see if boss lvl
for x=1 to 4
if level#=5*x
bosslvl#=1
endif
next x
rem MAKE SURE balla# IS LESS THAN 360 AND MORE THAN 0
balla#=wrapvalue(balla#)
sync
loop
levelup:
bossspeed#=player2movespeed#*1.5
level#=level#+1
inc player2movespeed#, .2
for x=1 to 6
color object x, rgb(rnd(255), rnd(255), rnd(255))
next x
ink 0,rgb(rnd(255), rnd(255), rnd(255))
player1score#=0
player2score#=0
return
movement:
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 ai to find ball
if playerpos2#>object position z(3) and object position z(2)>-3.5
player2pos#=player2pos#-player2movespeed#
position object 2,-5,0,player2pos#
endif
if playerpos2#<object position z(3) and object position z(2)<3.5
player2pos#=player2pos#+player2movespeed#
position object 2,-5,0,player2pos#
endif
rem BALL MOVEMENT
ballx#=newxvalue(ballx#,balla#,0.3):ballz#=newzvalue(ballz#,balla#,0.3)
return
scoring:
rem SCORING
if ballx#>9 then player2score#=player2score#+1:ballx#=0:ballz#=0:balla#=rnd(45)+45
if ballx#<-9 then player1score#=player1score#+1:ballx#=0:ballz#=0:balla#=-(rnd(45)+45)
set cursor 300,50:print player2score#
set cursor 320,50:print "-"
set cursor 340,50:print player1score#
if player1score#>=10 and player1score#-2>=player2score#
gosub levelup
endif
return
bouncing:
rem BOUNCING
if ballx#>6.5 and ballx#<7 and ABS(player1pos#-ballz#)<1.5 then balla#=360-balla#
if bosslvl#=0
if ballx#<-6.5 and ballx#>-7 and ABS(player2pos#-ballz#)<1.5 then balla#=360-balla#
endif
if bosslvl#=1
if ballx#<-6.5 and ballx#>-7 and abs(player2pos#-ballz#)<2.25 then balla#=360-balla#
scale object 2,1,1,1.5
bossspeed#=player2movespeed#
endif
if ballz#>4 or ballz#<-4 then balla#=180-balla#
return
positioning:
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#
return
```````````````````````````````````````````````
` `
` THESE ARE THE BUTTON FUNCTIONS `
` `
```````````````````````````````````````````````
`makes button 1 (in big grey box)
function button1(x,y,xsize,ysize,content$)
colortheme = rgb(200,200,200)
pressed = 0
if mousex() > x and mousex() < x + xsize
if mousey() > y and mousey() < y + ysize
if mouseclick() > 0 then pressed = mouseclick()
endif
endif
if pressed = 1
ink rgb(rgbr(colortheme)/2,rgbg(colortheme)/2,rgbb(colortheme)/2),0
box x,y,x+xsize-1,y+ysize-1
ink rgb(255,255,255),0
box x+1,y+1,x+xsize,y+ysize
else
ink rgb(rgbr(colortheme)/2,rgbg(colortheme)/2,rgbb(colortheme)/2),0
box x+1,y+1,x+xsize,y+ysize
ink rgb(255,255,255),0
box x,y,x+xsize-1,y+ysize-1
endif
ink colortheme,0
box x+1,y+1,x+xsize-1,y+ysize-1
ink 0,0
center text x+(xsize/2),y + (ysize/2) - (text height(content$)/2),content$
endfunction pressed
` to make a button like button 2 (changes color when moused over)
function button2(x,y,content$)
colortheme = rgb(255,0,0)
pressed = 0
tx = text width(content$) / 2
ty = text height(content$) / 2
if mousex() > x - tx and mousex() < x + tx
if mousey() > y - ty and mousey() < y + ty
pressed = 1
endif
endif
if pressed = 1 then ink colortheme,0 else ink rgb(255,255,255),0
center text x,y - ty, content$
if pressed > 0
pressed = mouseclick()
endif
endfunction pressed
`makes a button like button 3 (dissapears when moused over)
function button3(x,y,content$)
colortheme = rgb(255,255,0)
if rgbr(colortheme) > 0
if redval = 0 then redi = 1
if redval = rgbr(colortheme) then redi = -1
inc redval,redi
endif
if rgbg(colortheme) > 0
if greenval = 0 then greeni = 1
if greenval = rgbg(colortheme) then greeni = -1
inc greenval,greeni
endif
if rgbb(colortheme) > 0
if blueval = 0 then bluei = 1
if blueval = rgbb(colortheme) then bluei = -1
inc blueval,bluei
endif
pressed = 0
tx = text width(content$) / 2
ty = text height(content$) / 2
if mousex() > x - tx and mousex() < x + tx
if mousey() > y - ty and mousey() < y + ty
pressed = 1
endif
endif
if pressed = 1 then ink rgb(redval,greenval,blueval),0 else ink rgb(255,255,255),0
center text x,y - ty,content$
if pressed > 0
pressed = mouseclick()
endif
endfunction pressed
oh, and by the way, if anyone could explain how to make it go back to the menu if you press escape during gameplay, that might be beneficial to many of us
EDIT... AGAIN!!! :
Oh, good job on this by the way, and a suggestion or two I have:
1. for the AI, perhaps if you want to, you could make the enemy move up and down if the ball is above him or below him, as opposed to being above the halfway point between the walls in the game...
but to make it not so hard, you could say sumthing like:
if ball is above player2 + 1
player2pos = player2 pos + player2speed
endif
if ball is below player 2 - 1
player2pos = player2 pos - player2speed
endif
that way, it will wait till the ball is a little above it before making an attempt to reach it, as opposed to just going up and down with the ball... you could try it if you want...
A C.P.U is not smart at all, all it is, is a colleciton of millions of switches (albeit an extremely fast, exceptionally sophisticated collection of switches)/