I have created a basic Line-break game, but very rarely my ball gets stuck on the side. I have added the code, Is there something obvious that I am missing?
// Project: Linebreak
// Created: 2018-01-07
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "Linebreak" )
SetWindowSize( 1024,768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024,768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
speed=15 REM INTITIAL BALL SPEED
total=12 REM Total lines to produce
lives=5 ReM lives to begin with
Setlives=lives
gosub variables
gosub create_sprites
gosub create_text
gosub setup
lines[0,0]=linecount
ClearScreen()
`LoadMusicOGG( 1, "msc.ogg" )
`PlayMusicOGG(1,1)
do
gosub draw
gosub control
gosub texting
if hits=total and ballspeed#=<0
total=total+1
hits=0
gosub newlevel
endif
if ballspeed#=<0 and lives=0
total=12
hits=0
score=0
level=1
if hi=1
gosub save_score
endif
gosub newlevel
endif
Sync()
loop
create_text:
for n=1 to 10
CreateText(n," ")
SetTextSize( n,32 )
next n
SetTextPosition(2,20,20)
SetTextPosition(3,20,40)
SetTextPosition(4,20,60)
SetTextPosition(5,20,80)
return
texting:
if score>hiscore
hiscore=score
hi=1
endif
if score>0
SetTextString(1,str(combo))
endif
SetTextString(2,"Lives-"+str(Lives))
SetTextString(3,"Score-"+str(score))
SetTextString(4,"Level-"+str(level))
SetTextString(5,"Hi-Score-"+str(hiscore))
return
draw:
if gettexty(1)<800 and gettexty(1)>10
SetTextPosition(1,gettextx(1),gettexty(1)+10)
SetTextString(1,str(combo))
endif
hitline=0
for n=2 to linecount
if GetSpriteExists(n)=1
SetSpritePosition(n,lines[n,1],lines[n,2])
endif
next n
if ballspeed#>0
for s=1 to ballspeed#
x#=x#+sin(angle#)
y#=y#+cos(angle#)
SetSpritePositionbyoffset(1,x#,y#)
for n=2 to linecount
if GetSpriteExists(n)=1
hit=GetSpriteCollision(1,n)
endif
if hit>0 and ballspeed#>0
hitline=n
endif
if hitline>0 and lasthit<>hitline
gosub collision
exit
endif
next n
next s
endif
if ballspeed#>0
if oldx#=x#
ballspeed#=0
lasthit=0
score=score+combo*combo
combo=0
endif
oldx#=x#
dec ballspeed#,.1
endif
return
control:
if getpointerpressed()=1 and ballspeed#=<0
dec lives
tx#=GetPointerX()
ty#=GetPointerY()
ballspeed#=speed
angle#=ATanFull(tx#-x#,y#-ty#)
oldang#=angle#
endif
return
collision:
lasthit=hitline
cd#= GetSpriteDistance(1, lasthit)
cx#=GetSpriteDistancePoint1X( )
cy#=GetSpriteDistancePoint1Y( )
getangle#=ATanFull( x#-cx#,cy#-y#)
incidence#=angle#-getangle#
angle#=getangle#-180-incidence#
if angle#>360
angle#=angle#-360
endif
if angle#<0
angle#=angle#+360
endif
if hitline>5
DeleteSprite (hitline)
inc combo
SetTextPosition(1,x#,y#)
inc hits
endif
return
setup:
rx=300
ry=300
for n=1 to total
inc linecount
redo:
length=Random(100,600)
angle#=random(0,360)
if rx-sin(angle#-90)*length>1000
goto redo
endif
if rx-sin(angle#-90)*length<10
goto redo
endif
if ry+cos(angle#-90)*length>700
goto redo
endif
if ry+cos(angle#-90)*length<10
goto redo
endif
drawbox (rx,ry,rx+length,ry+4,white,white,white,white,1)
Render()
GetImage(linecount,rx,ry,length,4)
CreateSprite(linecount,linecount)
SetSpriteOffset( linecount, 0, 0 )
SetSpriteShape(linecount,2)
SetSpriteAngle(linecount,angle#)
SetSpritePosition(linecount,rx,ry)
lines [linecount,1]=rx
lines [linecount,2]=ry
lines [linecount,3]=angle#
rx=rx-sin(angle#-90)*length
ry=ry+cos(angle#-90)*length
if GetSpriteCollision(1,linecount)<>0
DeleteSprite(linecount)
DeleteImage(linecount)
goto redo
endif
ClearScreen()
next n
return
newlevel:
inc level
for n=6 to linecount
if GetImageExists(n)=1
DeleteImage(n)
endif
if GetSpriteExists(n)=1
DeleteSprite(n)
endif
next n
linecount=5
score=score+lives*(level*10)
lives=Setlives
gosub setup
return
variables:
dim lines [50,4]
ballspeed#=0
x#=512
y#=384
rx=0
ry=0
ry2=0
rx2=0
white=MakeColor( 255,255,255 )
red=MakeColor( 255,0,0 )
linecount=2
incidence#=0
reflection#=0
tp=10
lf=10
rt=1014
bt=758
count=0
hits=0
level=1
score=0
hiscore=0
if GetFileExists("hi")=1
OpenToRead( 1, "hi" )
hiscore=readInteger( 1 )
CloseFile(1)
endif
return
create_sprites:
DrawEllipse( x#, y#, 16, 16, red, red, 1)
Render()
GetImage(1,x#-16,y#-16,32,32)
CreateSprite(1,1)
SetSpritePositionByOffset(1,x#,y#)
SetSpriteTransparency(1,2)
SetSpriteShape(1,1)
drawbox (10,10,1014,14,white,white,white,white,1)
Render()
GetImage(linecount,10,10,1004,4)
CreateSprite(linecount,linecount)
lines [linecount,1]=10
lines [linecount,2]=10
lines [linecount,3]=180
inc linecount
DrawBox (10,bt,1014,bt+4,white,white,white,white,1)
Render()
GetImage(linecount,10,bt,1004,4)
CreateSprite(linecount,linecount)
lines [linecount,1]=10
lines [linecount,2]=bt
lines [linecount,3]=180
inc linecount
DrawBox (10,tp,14,bt,white,white,white,white,1)
Render()
GetImage(linecount,10,10,4,748)
CreateSprite(linecount,linecount)
lines [linecount,1]=10
lines [linecount,2]=10
lines [linecount,3]=90
inc linecount
DrawBox (rt,10,rt+4,761,white,white,white,white,1)
Render()
GetImage(linecount,rt,10,4,761)
CreateSprite(linecount,linecount)
lines [linecount,1]=rt
lines [linecount,2]=10
lines [linecount,3]=270
return
save_score:
hi=0
OpenToWrite( 1,"hi", 0 )
WriteInteger(1,hiscore)
CloseFile(1)
return