Bouncing ball with 'gravity'.
Gosha 24 May 2007 10:13
Actually, it's done now.
What are your opinions, should i make a tutorial out of this, or just leave it as an example?
'Creator : Gosha
'Email & MSN: gosha.za<at>gmail<dot>com
'Account on GDN: Gosha
'Account on Gabber: GoshaZa
option explicit
dim shared as single ballSpX, ballSpY, _ 'Ball speed variables.
ballPosX, ballPosY, _ 'Ball position variables.
ballRadius, ballClr, _ 'Ball setting variables.
xacc, yacc _ 'Acceleration Variables.
dim shared debugger as integer
screen 18
'Welcome message.
print ""
print " Hi."
print ""
print " Press a key to continue."
while inkey$="": wend
'Variables sub. (Init Game)
sub initVars()
ballSpX = 8
ballSpY = 9
ballPosX = 100
ballPosY = 150
ballRadius = 10
ballClr = 7
xacc = 0
yacc = 0.1
end sub
'Calculation sub.
sub ballMove()
ballSpX += xacc
ballSpY += yacc
ballPosX += ballSpX
ballPosY += ballSpY
end sub
'Input Sub.
sub inputAcc()
locate 5,1
print " (Type '101' to quit.)"
print " (Type '202' to reset the location of the ball, and all vars.)"
print " (Type '303' to switch debuggerging output on and off.)"
locate 2,1
print " Type The x- and y-acceleration in this format: 'x,y'"
input " ____: ",xacc,yacc
if xacc = 101 then
END
elseif xacc = 202 then
initVars()
elseif xacc = 303 then
initVars()
debugger = not debugger
endif
end sub
'debuggerging sub.
sub deDugging()
locate 2,2
print "xacc = "; xacc
locate 3,2
print "yacc = "; yacc
locate 5,2
print "ballSpX = "; ballSpX
locate 6,2
print "ballSpY = "; ballSpY
end sub
'Game loop sub.
sub gameLoop()
while not inkey$="q"
if debugger then deDugging()
print ""
print " Press 'q' to view the 'menu'"
if ballPosX > 640 - ballRadius then ballSpX = -ballSpX': xacc = -xacc
if ballPosY > 480 - ballRadius then ballSpY = -ballSpY': yacc = -yacc
if ballPosX < 1 + ballRadius then ballSpX = -ballSpX': xacc = -xacc
if ballPosY < 1 + ballRadius then ballSpY = -ballSpY': yacc = -yacc
circle (ballPosX,ballPosY),ballRadius,ballClr,,,,F
ballMove()
sleep 10
cls
wend
end sub
'Putting it all together.
initVars()
do
gameLoop()
inputAcc()
loop
END