If a mod would change the 'of' to 'off' which is in the title, that'd be appreciated. Thanks.
In this program, Pong, I want to know what I am doing wrong, that causes it not to be able to bounce off the bottom. Or the top.
`-------------------------------------
`Pong by Irojo
`-------------------------------------
hide mouse
`Intro:
center text 320,240,"Loading Music..."
wait 400
load sound "hitball.wav",1
load sound "ping.wav",2
cls
center text 320,240,"Loading Sprites..."
wait 400
sync rate 0
direct=0
p1y#=240
bx#=320
by#=240
cy#=240
direct=1
Generate_Pong_Image
Create_Main_Paddles(2,3)
Ball_Generate(1,3)
r=rnd(1)+1
sync rate 0
do:cls rgb(15,25,15)
sprite 4,280,0,4
if p1y#>=420 then disable=1 else disable=0
if p1y#<=0 then disable_2=1 else disable_2=0
sprite 2,40,p1y#,2
sprite 1,bx#,by#,1
sprite 3,600,cy#,3
`--Reset if Ball passes Player's side---
if bx#>=638 then bx#=320:r=2:by#=240:t=0:wait 1000
if bx#<=1 then bx#=320:r=1:y#=240:t=0:wait 1000
`--|Reset if Ball passes Player's side|---
`Change Directions for ball maintenance
bx#=bx#*direct
`--------
`Sprite collision to check sides
if sprite collision(3,1) then r=2
if sprite collision(2,1) then r=1
if upkey()=1 and disable_2=0 then dec p1y#,.5
if downkey()=1 and disable=0 then inc p1y#,.5
if returnkey()=1 then inc cy#,1
if r=1 then inc bx#,1
if r=2 then dec bx#,1
` Determine Sprite Collision and flip "Pong" symbol. + play sound
if sprite collision(2,1) then oldp#=p1y#:start=1:inc pscore#:flip sprite 4:play sound 1
if sprite collision(3,1) then oldp#=cy#:start=1:inc cpuscore#:flip sprite 4:play sound 1
if start=1
if oldp#<by# then dec by#,.05
if oldp#+1<by# then mega_curve=1:`play sound 2
if oldp#>by# then inc by#,.05
if by#<oldp# then inc by#,.09
if oldp#=by# then start=0
endif
`--Making Mega_curve
If mega_curve=1
if by#<478 then inc by#,curve#
if curve#<1 then inc curve#,.01
endif
`--|Making Mega_curve|--
if by#>=479 then t=1
if by#<=2 then t=2
print t
if t=1 then dec by#,1
if t=2 then inc by#,1
`--Handle CPU--
perfection=rnd(1)
if by#>cy# and perfection=1 then inc cy#,.8
if by#<cy# and perfection=1 then dec cy#,.8
`--|Handle CPU|--
ink rgb(255,10,0),0
set text size 20
center text 140,0,"P1 Score:"+str$(pscore#)
ink rgb(10,255,10),0
set text size 20
center text 500,0,"CPU Score:"+str$(cpuscore#)
ink rgb(255,255,255),0
text 280,100," Score to win: 30"
if pscore#=30 then gosub pwin
if cpuscore#=30 then gosub cpuwin
sync
loop
`----------FUNCTIONS---------
function Create_Main_Paddles(image1,image2)
ink rgb(255,10,0),0
box 10,10,20,80
get image image1,10,10,20,70
cls
ink rgb(10,255,0),0
box 10,10,20,80
get image image2,10,10,20,70
cls
endfunction
function Ball_generate(image3,radius)
ink rgb(10,0,255),0
sync on:sync rate 0
radius#=radius
oldradius#=radius
while radius#>0
dec radius#,1
circle 320,240,radius#
sync
endwhile
get image image3,300,200,340,280
cls
endfunction
function Generate_Pong_Image
sync on:sync rate 0
y=0
sync
for row=0 to 8
inc y,8
x=0
for col=0 to 16
sync
ink rgb(0,255,0),0
inc x,6
read somedata
if somedata=1
box x,y,x+4,y+4
endif
sync
next col
sync
next row
data 0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0
data 0,0,1,0,0,1,0,1,0,1,0,1,0,1,0,1,0
data 0,0,1,0,0,1,1,1,0,1,0,1,0,1,1,1,0
data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0
data 0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,0
data 0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,0
get image 4,0,0,200,70
cls
sync rate 30
ink rgb(255,255,255),0
endfunction
`GAME ENDING VARIABLES
pwin:
play sound 2
hide sprite 4:hide sprite 1:hide sprite 2:hide sprite 3
repeat
cls rgb(0,255,0):ink rgb(0,255,0),0:wait 100
center text 320,240,"You beat the CPU!"
cls rgb(0,0,0):ink rgb(0,0,0),0:wait 100
center text 320,240,"You beat the CPU!"
ten=ten+1
play sound 2
sync
until ten=10
ink rgb(255,255,255),0
center text 320,240,"You beat the CPU!"
suspend for key
stop sound 2
end
cpuwin:
hide sprite 4:hide sprite 1:hide sprite 2:hide sprite 3
cls
center text 320,240,"Failure."
suspend for key
end
After I dozen tries, I've removed the code that makes it bounce. If someone could make it possible for it to bounce of the top and the bottom, using anything, It'd be much appreciated. Thanks, Irojo
I urge you to watch the film "Who killed the electric car". Support electric cars! Did you know their used to be more electric cars then gassoline cars?