Bowling

My grandkids enjoy ten pin bowling. Anyone have any pointers in how to put a game together? I know, a big ask, but suggestion and ideas are all I need.

J

Bowling seems a bit like Breakout, I was going to do a Breakout version for SB but Bowling version seems a better distraction!

It might be fun watching a ball "pinball" around 10 circles arranged in triangle and see how many are contacted.

My first concern is getting 10 circles arranged in a triangle and scale because bowling like shuffle board needs a long and narrow graphic.

Have you got any code already that does that?


'triangle layout.bas for SmallBASIC 12.8 [B+=MGA] 2017-01-11

xoff = 0
yoff = 20
s = 80
FOR
row = 1 to 4
FOR col = 1 TO row
circle s*col+ xoff, s*row - s/2*col + yoff, 10, 1, 15 filled
NEXT col
NEXT
row
pause


So all the hard work is already done!

Oh! I have an idea, instead of bowling ball how 'bout a boomerang for Oz version of bowling. :-))

Nope. No code. Just a few Ideas. I actually looked up "The Physics of Bowling"... Ouch! Talk about brain strain! Didn't think there was THAT much involved in bowling... If I want realistic "Pin Action", based on the physics data, I will end up breaking my brain...

Circles are looking good.

I figured that I would try to think "modular". Focus on one part of the game/simulation... get the bugs out... move on to the next.

I found plenty of "Scoring" type programs, in various computer languages, but no actual natively running bowling games for Linux... So, I figured, 'why not basic?'.

I also figured I would modify the "shuffleboard" game. After all, the 'ball' part is practically in the bag... lol For starters, the 'ball' can be either moved manually at the 'foul line' or placed at random... The mechanics of sending the 'ball' down the 'lane' is already there... The hard part is going to simulate 'pin action'. I can provide you with the calculations needed for 'pin action'. It's WAY above my head, but perhaps, you would have better luck.

(1/2)m1v1i2 = (1/2)m1v1f2 + (1/2)m2v2f2
m1 = mass of the bowling ball or pin
v1i = velocity of ball or pin before collision
v1f = velocity of ball or pin after collision
m2 = mass of pin that was hit
v2f = velocity of pin that was hit

(the 2's on the end of each part of the calculation is meant to be 'squared' - don't know how to type that... lol)

Got that from the following site... Good luck... lol

http://ffden-2.phys.uaf.edu/211_fall2004.web.dir/craig_stephenson/index....

Anyway. All I have is a few ideas... As soon as I can rescue my computer from the grandkids, I can start putting some ideas 'to paper' and hopefully start putting some code together... fingers crossed... lol

J

A strike!

'bowling sample 1.bas for SmallBASIC 12.8 [B+=MGA] 2017-01-11

pins = 10
pr = 20

dim px(pins), py(pins), pa(pins), pc(pins), ps(pins)

xoff = 0
yoff = 20
spacer = 80
pin = 1
for
row = 1 to 4
for col = 1 TO row
px(pin) = spacer*col + xoff
py(pin) = spacer*row - spacer/2*col + yoff
pin += 1
next
next

'ball = pin
px(0) = xmax
py(0) = 20 + 100 + 90
pa(0) = pi + 3*pi/180 '180 - 1 degrees?
ps(0) = 20

while 1
cls
for i = 0 to pins
for j = 1 to pins
if j <> i and pc(j) <> 1 then
if sqr((px(i)-px(j))^2 + (py(i)-py(j))^2) < 2*pr then
if i <> 0 then pa(i) = atan2(py(i)-py(j), px(i)-px(j))
pa(j) = atan2(py(j)-py(i), px(j)-px(i))
pc(i) = 1 : pc(j) = 1
s = (ps(i) + ps(j))/2
ps(i) = s : ps(j) = s
exit for
fi
fi
next
if ps(i) > 0 then ps(i) -= .003
px(i) = px(i)+cos(pa(i))*ps(i)
py(i) = py(i)+sin(pa(i))*ps(i)
if pa(i) > 2*pi then pa(i) = pa(i)-2*pi
if pa(i) < 0 then pa(i) = pa(i)+2*pi
if i = 0 then
color 9
elif pc(i)
color 12
else
color 15
end if
circle px(i), py(i), pr filled
pc(i) = 0
next
showpage
delay 10
wend



EDIT NOTE: Well this is not going to work for others with different screen size and even then maybe won't process speeds the same???

I've run the example using both small and sdlbasic (had to include an atan2() function) and both performed exactly the same. Speed and all. Both samples concluded and would not terminate... not concerned as it's only a sample. The interaction between the 'ball' and the 'pins' were quite good.

Am I correct in assuming that the graphics will be 'primitives'? - save on file space... lol

Good job.

J

Yes, need a proper exit from while loop but at least we can see a logical end, when things are either off screen or have stopped moving.

I think pins/circles not moved or minimally moved from their start position are redrawn for the spare.

Also need a way to start the ball and its angle to pins.

Added bottom edge for alley called ygutter. Now tests conditions for end of action and resets rack with pins not moved for spare.


'bowling sample 2.bas for SmallBASIC 12.8 [B+=MGA] 2017-01-12

pins = 10
pr = 20

dim px(pins), py(pins), pa(pins), pc(pins), ps(pins)
dim rack(pins,1)
xoff = 0
yoff = 20
spacer = 80
ygutter = 4*spacer+2*yoff
pin = 1
for
row = 1 to 4
for col = 1 TO row
px(pin) = spacer*col + xoff
py(pin) = spacer*row - spacer/2*col + yoff
rack(pin, 0) = px(pin) : rack(pin, 1) = py(pin)
pin += 1
next
next

'ball = pin 'current commented settings leaves 9 down 1 to spare
px(0) = 1000 '<<<< no longer xmax to replicate results
py(0) = 20 + 80 + 75 '20 + 80 + 75
pa(0) = pi - 2*pi/180 'pi - 2*pi/180
ps(0) = 20 '20

notDone = 1
while notDone
cls
notDone = 0
line 0, ygutter, xmax, ygutter, 14
for i = 0 to pins
for j = 1 to pins
if j <> i and pc(j) <> 1 then
if sqr((px(i)-px(j))^2 + (py(i)-py(j))^2) < 2*pr then
if i <> 0 then pa(i) = atan2(py(i)-py(j), px(i)-px(j))
pa(j) = atan2(py(j)-py(i), px(j)-px(i))
pc(i) = 1 : pc(j) = 1
s = (ps(i) + ps(j))/2
ps(i) = s : ps(j) = s
exit for
fi
fi
next
if ps(i) > 0 then ps(i) -= .003
px(i) = px(i)+cos(pa(i))*ps(i)
py(i) = py(i)+sin(pa(i))*ps(i)
if pa(i) > 2*pi then pa(i) = pa(i)-2*pi
if pa(i) < 0 then pa(i) = pa(i)+2*pi
if i = 0 then
color 9
elif pc(i)
color 12
else
color 15
end if
if py(i) < ygutter then circle px(i), py(i), pr filled else ps(i) = 0
if px(i) > spacer*6 and i<>0 then ps(i) = 0
pc(i) = 0
if px(i) > 0 and px(i) < xmax and py(i) > 0 and py(i) < ygutter and ps(i) > 0 then notDone = 1
next
showpage
delay 10
wend
'at 20, ygutter + 20 : ? "done"
'showpage
cls
line 0, ygutter, xmax, ygutter, 14
cnt = 0 'count pins not moved
for i = 1 to pins
if sqr((px(i)-rack(i,0))^2 + (py(i)-rack(i,1))^2) < pr then cnt += 1
next
if cnt = 0 then
at 20, ygutter + 20 :? "Strike!
else
for i = 1 to pins
if sqr((px(i)-rack(i,0))^2 + (py(i)-rack(i,1))^2) < pr then
circle rack(i, 0), rack(i, 1), pr, 1, 15 filled
end if
next
at 20, ygutter + 20 : ? pins - cnt;" pins down, ";cnt;" more for spare."
end
if
showpage
pause


Johnno, I hope you are working on ball start setup and scoring.

The grandkids have gone back home, as as a result, the control of my computer has been restored to me... I can finally start to do stuff.

Time to hit the keys...

J

Gave the 'lane' and 'ball' some thought... Maths is a subject that I do not excel at and opted for a simplistic (spartan) setup. The lane will run he width of the screen with sufficient space for the gutters (not yet implemented). The ball will bounce at the 'foul line' between the gutters. The speed of the bounce will be governed by the difficulty. ie: The lower the difficulty the slower the ball...

As SB is a language I am still learning, there will probably be a lot of inefficiencies, in the listing. But the concept is the main point.

Space to "roll". Escape to exit. When the ball reaches the end, there is a short delay, and the ball resets.

The scoreboard... I know how to score the game because I have bowled league for many years... I apparently do not think as logically as most of you guys and have difficulty transposing thought into code. I will need a little time to research the scoring code. I have looked around and found a few different computer language versions of scoring but nothing for 'basic' except for a REALLY old bowling program, that was written in spaghetti basic, back in '85.

The listing is crude but seems to work. It isn't much and it's not very good, but it's a start... I hope that adding the listing is done right... lol


cls

difficulty = 4
ballx = 15
bally = 150
ballxspeed = 0
ballyspeed = difficulty

roll = 0

exitgame = 0

sub drawlane()
rect 0,20,640,20
rect 0,50,640,50
rect 0,250,640,280
end

sub updateball()
ballx = ballx + ballxspeed
bally = bally + ballyspeed
if bally > 67 then
ballyspeed = ballyspeed - difficulty
fi
if bally < then
ballyspeed = ballyspeed + difficulty
fi
circle ballx, bally, 15
if roll = 1 then
ballyspeed = 0
ballxspeed = difficulty
rem Collision detection here.... ?
if ballx > 655 then
delay 1000
ballx = 15
bally = 150
roll = 0
ballxspeed = 0
ballyspeed = difficulty
fi
fi
end

sub keypress()
k = inkey
if asc(k) = 32 then roll = 1
if asc(k) = 27 then exitgame = 1
end

while exitgame = 0
cls
drawlane()
updateball()
keypress()
showpage
wend

Please feel free to make the necessary changes but please let me know where I have messed up?

J

Note: I assume the 2nd if for bally is <= 67 as a number is missing (and I wonder why no error???) Before a number is filled in the ball drops to bottom of screen, after a number is filled in it bounces between middle of lane to above screen.

I recommend when using SmallBASIC to use the whole screen xmax, ymax because it is other wise wasted unless you want to do adventures with the window command.

These two are lines not rectangles:
rect 0,20,640,20
rect 0,50,640,50

rect 0, 20, xmax, 50 '0, 20 = top left corner, xmax, 50 should give a gutter 30 wide like the bottom rect

To color and fill rect, say to make gutters yellow =QB color 14
rect 0, 20, xmax, 50, 14 filled '< filled keyword is written at the end of rect or circle for filling

or rgb way
rect 0, 20, xmax, 50, rgb(255, 255, 0) filled

or like SdlBasic Color statement is like INK
color rgb(255, 255, 0)
rect 0, 20, xmax, 50 filled

but in SmallBASIC, I prefer to color the objects individually and save color fore, back for whole screen cls

But it would be better just to draw the lane rectangle with black for gutters above and below the lane.

So that is the idea for starting the ball, have it going up and down width of lane and press spacebar to get it rolling towards pins.
For my samples, I need to set an angle as well as the initial ball x, y.

Scoring: is just drawing small boxes around numbers inside a bigger box. Fortunately they are just 1 digit numbers so it is a digit 0 -9 or / or X they are all the same size. SmallBASIC has txtw and txth the will help size a letter of current font setting. Get a box around a digit looking good first. Then the bigger box is 3 of the smaller digit boxes wide minimally and 2 smaller digit boxes high, minimally. One bigger box is a frame, I forget is the 10th frame have an extra digit box in case you get a strike in 10th, you get 2 more balls for max score 30 if all strikes. So yes, it must! Oh, that's why all the frames are 3 digit boxes wide minimally, not just because it looks good. ;-))

Ok. My primary defense is tiredness... That's my story and I'm sticking too it ... lol

Line 25 was supposed to be if bally < 233 then...
Also, you are correct, in regards to rectangles...
They were supposed to be 0,20,640,50 and 0,50,640,250 and 0,250,640,280

I suppose I could have used xmax instead of 640, but at the time, I hadn't printed the value of x and ymax... I figured 640 would be enough.... (that sounds familiar... wow... a Bill Gates moment... lol)

I know scoring may seem to be a bunch of boxes that contain stuff, but it's calculating the correct score so that the right stuff goes in the boxes, that seems to be the biggest headache. I will try to pick apart the c# coding and try to cobble together something that will work in basic... no promises... but it's the closest solution I have come across in all my searching...

Many thanks for the 'mini tut'. Much appreciated.

J


'bowling sample 3.bas for SmallBASIC 12.8 [B+=MGA] 2017-01-13

pins = 10
pr = 20

dim px(pins), py(pins), pa(pins), pc(pins), ps(pins)
dim rack(pins,1)
xoff = 0
yoff = 20
spacer = 80
ygutter = 4*spacer+2*yoff
pin = 1
for
row = 1 to 4
for col = 1 TO row
px(pin) = spacer*col + xoff
py(pin) = spacer*row - spacer/2*col + yoff
rack(pin, 0) = px(pin) : rack(pin, 1) = py(pin)
pin += 1
next
next

pen on
x=-100
while x > xmax - pr or x < xmax - 200 or y < pr or y > ygutter - pr
cls
at 20, ygutter + 20 : ? "Click inside box to position ball."
rect xmax - 200, pr, xmax - pr, ygutter -pr
circle pen(4), pen(5), pr, 1, 9
if pen(3) then x = pen(4) : y = pen(5)
delay 20
showpage
wend
px(0) = x : py(0) = y

x = -10 : y = -10
while x > 500 or x < 0 or y < pr or y > ygutter - pr
cls
at 20, ygutter + 20 : ? "Click around the pins to set ball angle."
for i = 1 to pins
circle rack(i, 0), rack(i, 1), pr, 1, 15 filled
next
circle px(0), py(0), pr,1, 9 filled
line px(0), py(0), pen(4), pen(5), 14
if pen(3) then x = pen(4) : y = pen(5)
delay 20
showpage
wend
pa(0) = atan2(y-py(0), x-px(0))
ps(0) = 20

notDone = 1
while notDone
cls
notDone = 0
line 0, ygutter, xmax, ygutter, 14
for i = 0 to pins
for j = 1 to pins
if j <> i and pc(j) <> 1 then
if sqr((px(i)-px(j))^2 + (py(i)-py(j))^2) < 2*pr then
if i <> 0 then pa(i) = atan2(py(i)-py(j), px(i)-px(j))
pa(j) = atan2(py(j)-py(i), px(j)-px(i))
pc(i) = 1 : pc(j) = 1
s = (ps(i) + ps(j))/2
ps(i) = s : ps(j) = s
exit for
fi
fi
next
if ps(i) > 0 then ps(i) -= .003
px(i) = px(i)+cos(pa(i))*ps(i)
py(i) = py(i)+sin(pa(i))*ps(i)
if pa(i) > 2*pi then pa(i) = pa(i)-2*pi
if pa(i) < 0 then pa(i) = pa(i)+2*pi
if i = 0 then
color 9
elif pc(i)
color 12
else
color 15
end if
if py(i) < ygutter then circle px(i), py(i), pr filled else ps(i) = 0
if px(i) > spacer*6 and i<>0 then ps(i) = 0
pc(i) = 0
if px(i) > 0 and px(i) < xmax and py(i) > 0 and py(i) < ygutter and ps(i) > 0 then notDone = 1
next
showpage
delay 10
wend
'at 20, ygutter + 20 : ? "done"
'showpage
cls
line 0, ygutter, xmax, ygutter, 14
cnt = 0 'count pins not moved
for i = 1 to pins
if sqr((px(i)-rack(i,0))^2 + (py(i)-rack(i,1))^2) < pr then cnt += 1
next
if cnt = 0 then
at 20, ygutter + 20 :? "Strike!
else
for i = 1 to pins
if sqr((px(i)-rack(i,0))^2 + (py(i)-rack(i,1))^2) < pr then
circle rack(i, 0), rack(i, 1), pr, 1, 15 filled
end if
next
at 20, ygutter + 20 : ? pins - cnt;" pins down, ";cnt;" more for spare."
end
if
showpage
pause

Do 10 frames now!

'bowling sample 4.bas for SmallBASIC 12.8 [B+=MGA] 2017-01-13

pins = 10
pr = 20
frame = 1
dim px(pins), py(pins), pa(pins), pc(pins), ps(pins)
dim rack(pins,2)

xoff = 0
yoff = 20
spacer = 80
ygutter = 4*spacer+2*yoff
pin = 1
for
row = 1 to 4
for col = 1 TO row
px(pin) = spacer*col + xoff
py(pin) = spacer*row - spacer/2*col + yoff
rack(pin, 0) = px(pin) : rack(pin, 1) = py(pin)
pin += 1
next
next

gameOver = 0
ball = 1
repeat

if ball = 1 or ball = 3 or ball = 4 or ball = 5 then 'put all the pins in rack
for i = 1 to pins
px(i) = rack(i,0) : py(i) = rack(i, 1) : ps(i) = 0 : pa(i) = 0
next
end if

pen on
x = -100 : y = -100
while x > xmax - pr or x < xmax - 200 or y < pr or y > ygutter- pr
cls
at 20, ygutter + 20 : ? "Click inside box to position ball."
for i = 1 to pins
if px(i) <> -1000 then
circle rack(i,0), rack(i, 1), pr, 1, 15 filled
px(i) = rack(i,0) : py(i) = rack(i, 1)
fi
next
rect xmax - 200, pr, xmax - pr, ygutter -pr
circle pen(4), pen(5), pr, 1, 9
if pen(3) then x = pen(4) : y = pen(5)
delay 20
showpage
wend
px(0) = x : py(0) = y

x = -10 : y = -10
while x > 500 or x < 0 or y < 0 or y > ygutter
cls
at 20, ygutter + 20 : ? "Click around the pins to set ball angle."
for i = 1 to pins
if px(i) <> -1000 then
'circle rack(i,0), rack(i, 1), pr, 1, 15 filled
circle px(i), py(i), pr, 1, 15 filled
fi
next
circle px(0), py(0), pr, 1, 9 filled
line px(0), py(0), pen(4), pen(5), 14
if pen(3) then x = pen(4) : y = pen(5)
delay 20
showpage
wend
pa(0) = atan2(y-py(0), x-px(0))
ps(0) = 25

notDone = 1
while notDone
cls
notDone = 0
line 0, ygutter, xmax, ygutter, 14
for i = 0 to pins
if px(i) <> -1000 then
for j = 1 to pins
if j <> i and pc(j) <> 1 then
if sqr((px(i)-px(j))^2 + (py(i)-py(j))^2) < 2*pr then
if i <> 0 then pa(i) = atan2(py(i)-py(j), px(i)-px(j))
pa(j) = atan2(py(j)-py(i), px(j)-px(i))
pc(i) = 1 : pc(j) = 1
s = (ps(i) + ps(j))/2
ps(i) = s : ps(j) = s
exit for
fi
fi
next
if ps(i) > 0 then ps(i) -= .007 else ps(i) = 0
px(i) = px(i)+cos(pa(i))*ps(i)
py(i) = py(i)+sin(pa(i))*ps(i)
if pa(i) > 2*pi then pa(i) = pa(i)-2*pi
if pa(i) < 0 then pa(i) = pa(i)+2*pi
if i = 0 then
color 9
elif pc(i)
color 12
else
color 15
end if
if py(i) < ygutter then circle px(i), py(i), pr filled else ps(i) = 0
if px(i) > spacer*6 and i<>0 then ps(i) = 0
pc(i) = 0
if px(i) > 0 and px(i) < xmax and py(i) > 0 and py(i) < ygutter and ps(i) > 0 then notDone = 1
fi 'if px(i) <> -100
next
showpage
delay 10
wend

cls
line 0, ygutter, xmax, ygutter, 14
cnt = 0
for i = 1 to pins
if sqr((px(i)-rack(i,0))^2 + (py(i)-rack(i,1))^2)< pr then
circle rack(i, 0), rack(i, 1), pr, 1, 15 filled
else
px(i) = -1000 : py(i) = -1000 : ps(i) = 0 : pa(i) = 0
cnt += 1
fi
next

if cnt = 10 and ball = 1 then
at 20, ygutter + 20 :? "Frame: ";frame;" Strike!"
if frame = 10 then
ball = 3
else
ball = 1 : frame += 1
fi
elif cnt = 10 and ball = 2 then
at 20, ygutter + 20 :? "Frame: ";frame;" Ball 1: ";b1cnt;" Ball 2: Spared!"
if frame = 10 then
ball = 5
else
ball = 1 : frame += 1 : b1cnt = 0
fi
elif cnt = 10 and ball = 3 then
at 20, ygutter + 20 :? "Frame: 10 Strike 2!!"
ball = 4
elif cnt = 10 and ball = 4 then
at 20, ygutter + 20 :? "Frame: 10 Strike 3!!"
gameOver = 1
elif cnt = 10 and ball = 5 then
at 20, ygutter + 20 :? "Frame 10 Spare and 10 = 20"
gameOver = 1
elif cnt = 10 and ball = 6 then
at 20, ygutter + 20 :? "Frame 10 Strike plus spare = 20"
gameOver = 1
elif cnt < 10 and ball = 1 then
b1cnt = cnt
at 20, ygutter + 20 : ? "Frame: ";frame;" Ball 1: ";b1cnt
ball = 2
elif cnt < 10 and ball = 2 then
b2cnt = cnt - b1cnt
at 20, ygutter + 20 : ? "Frame: ";frame;" Ball 1: ";b1cnt;" Ball 2: ";b2cnt
ball = 1 : frame += 1
elif cnt < 10 and ball = 3 then
b3cnt = cnt
at 20, ygutter + 20 :? "Frame: 10 Strike plus ";b3cnt;" plus next ball"
ball = 6
elif cnt < 10 and ball = 4 then
at 20, ygutter + 20 :? "Frame 10 2 Strikes plus ";cnt
gameOver = 1
elif cnt < 10 and ball = 5 then
at 20, ygutter + 20 :? "Frame 10 Spare plus ";cnt
gameOver = 1
elif cnt < 10 and ball = 6 then
at 20, ygutter + 20 :? "Frame 10 Strike plus ";b3cnt;" plus ";cnt - b3cnt
gameOver = 1
fi
showpage
delay 3000

if ball = 1 then b1cnt = 0 : b2cnt = 0
if frame = 11 then gameOver = 1

until
gameOver

Make up a bowling game, then test code for adding up score and drawing a score sheet.


' box scorer.bas SmallBASIC 0.12.8 [B+=MGA] 2017-01-14

const th = txth("Q")
const tw = txtw("W")
const bh = th + 6
const bw = tw + 6
const bbw = 3 * bw
const bbh = 2 * bh

while 1
cls
dim score(10, 3) '=============== make up a bowling game

for
i = 1 to 10
s1 = mid("0123456789X", int(rnd*11)+1, 1)
score(i, 1) = s1
if s1 <> "X" then
s2 = int(rnd * (11 - val(s1)))
if s2 + val(s1) = 10 then
score(i, 2) = "/"
else
score(i, 2) = str(s2)
fi
fi
next
'finish 10th frame
if score(10, 1) = "X" then
s1 = mid("0123456789X", int(rnd*11)+1, 1)
score(10, 2) = s1
if s1 <> "X" then
s2 = int(rnd * (11 - val(s1)))
if s2 + val(s1) = 10 then
score(10, 3) = "/"
else
score(10, 3) = str(s2)
fi
else
score(10,3) = mid("0123456789X", int(rnd*11)+1, 1)
fi
end if
if score(10, 2) = "/" then
s1 = mid("0123456789X", int(rnd*11)+1, 1)
score(10, 3) = s1
fi


'OK now let's take the game data and add up the score
for i = 1 to 9
if score(i,1) = "X" then
if score(i+1,1) = "X" then
if i+1 = 10 then
if score(10,2) ="X" then
score(i,0) = score(i-1, 0) + 30
else
score(i,0) = score(i-1, 0) + 20 + val(score(10,2))
fi
else
if score(i +2, 1) = "X" then
score(i, 0) = score(i-1, 0) + 30
else
score(i, 0) = score(i-1, 0) + 20 + val(score(i+2,1))
fi
fi
else 'not "X"
if score(i+1, 2) = "/" then
score(i, 0) =score(i-1,0) + 20
else
score(i,0) = score(i-1, 0) + 10 + val(score(i+1, 1)) + val(score(i+1, 2))
fi
fi
else
if score(i,2) = "/" then
if score(i+1,1)= "X" then
score(i, 0) = score(i-1, 0) + 20
else
score(i, 0) = score(i-1, 0) + 10 + val(score(i+1, 1))
fi
else
score(i, 0) = score(i-1, 0) + val(score(i, 1)) + val(score(i, 2))
fi
fi
next
'10th frame
if score(10, 1) = "X" then
if score(10, 2) = "X" then
if score(10,3) = "X" then
score(10, 0) = score(9,0) + 30
else
score(10, 0) = score(9,0) + 20 + val(score(10, 3))
fi
else
if score(10, 3) = "/" then
score(10,0) = score(9,0) + 20
else
score(10, 0) = score(9,0) + 10 + val(score(10,2)) + val(score(10,3))
fi
fi
else
if score(10, 2) = "/" then
score(10, 0) = score(9,0) + 10 + val(score(10, 3))
else
score(10, 0) = score(9,0) + val(score(10,1)) + val(score(10, 2))
fi
fi

'display the game
for i = 1 to 9 'check game out
rect (i-1)*bbw, 200, i*bbw, 200+bbh
c1 = score(i,1) : c2 = score(i,2)
boxChar ((i-1)*bbw+bw), 200, c1
boxChar ((i-1)*bbw+2*bw), 200, c2
at (i-1)*bbw + bw, 200 + bh + 3 : ? score(i, 0)
next
rect (10-1)*bbw, 200, 10*bbw, 200+bbh
c1 = score(10,1) : c2 = score(10,2) : c3 = score(10, 3)
boxChar ((10-1)*bbw), 200, c1
boxChar ((10-1)*bbw+bw), 200, c2
boxChar ((10-1)*bbw+2*bw), 200, c3
at (10-1)*bbw + bw, 200 + bh + 3 : ? score(10, 0)
locate 1, 1 : input "OK";t
wend

sub
boxChar(x, y, char)
rect x, y, x + bw, y + bh
at x+3, y+3 : ? char
end


This is REALLY cool. It would have taken me a month of Sundays to come any near as good as this... Please do not take my seemingly lack of results as a sign that I am not interested... Coding doesn't come to me as easily as it seems to you guys. But I am really glad that you guys can produce results sooo quickly. Bit of envy sneaking through there... lol

I thought the ball placement; angle selection and pin action, in the previous listing was brilliant... most impressed...

I would appreciate some tips to be able to learn to code as quickly as you guys. I'm still sorting out ideas and most of the hard work has already been done. I am not complaining by any means. I am grateful that you have done soooo much. I feel as though I've done almost nothing in comparison... I think I need more coffee... *sigh*

J

Thanks Johnno,

It really helps when someone can follow and appreciate what is going on.

This code is not completely tested, already this morning I don't see the case of a spare then strike covered in the 10th frame. Currently I am just trying to get the thing up and running and fixing bugs as they pop up and enter my awareness. But I don't think you are mistaking it for perfection. :-)

What better tip is there to say than practice? Of course finding stuff you can do and is remotely interesting is a bit tricky. For learning SmallBASIC, try translating SdlBasic of some other familiar code you have written to SmallBASIC. But I confess, I am very weak on more advanced features of SmallBASIC like all the stuff possible with window or image commands.

I do keep files on reusable subs and functions and probably cherish that "tool chest" more than any one or two programs. Code like how to make a triangle of objects (used to draw rack of pins) or how to bounce a ball around with mouse (from bonkers) go into "the chest".

More test code for the scoring system, ready to move constants and two main subs to Bowling Sample 5.bas

The scoring will draw in totals up to current frame, if a strike or spare, the frame will update with proper scores later when the new ball amounts are filled in the score array, in a self correcting style.


' current score.bas SmallBASIC 0.12.8 [B+=MGA] 2017-01-14

const th = txth("Q")
const tw = txtw("W")
const bh = th + 6
const bw = tw + 8
const bbw = 3 * bw
const bbh = 2 * bh
const xTopSheet = 50
const ytopSheet = 500

while 1
cls
dim score(10, 3)
for frame = 1 to 10 '=============== make up a bowling game one frame at time
cls
s1 = mid("0123456789X", int(rnd*11)+1, 1)
score(frame, 1) = s1
if s1 <> "X" then
s2 = int(rnd * (11 - val(s1)))
if s2 + val(s1) = 10 then
score(frame, 2) = "/"
else
score(frame, 2) = str(s2)
fi
fi
score(10,1) = "X" 'for testing 10th frame
'finish 10th frame
if frame = 10 then
if score(10, 1) = "X" then
s1 = mid("0123456789X", int(rnd*11)+1, 1)
score(10, 2) = s1
if s1 <> "X" then
s2 = int(rnd * (11 - val(s1)))
if s2 + val(s1) = 10 then
score(10, 3) = "/"
else
score(10, 3) = str(s2)
fi
else
score(10,3) = mid("0123456789X", int(rnd*11)+1, 1)
fi
end if
if score(10, 2) = "/" then
s1 = mid("0123456789X", int(rnd*11)+1, 1)
score(10, 3) = s1
fi
fi
updateScore(frame) '<<<<<<<<<<<<<<<<<<<<<<<< main sub we are testing
locate 1, 1 : input "OK" ; temp
next 'frame
wend

sub
updateScore(frame)
local i
totalUpScore(frame) 'totals up scores to current frame, yeah it's wrong for strikes and spares
'draw score sheet
line xTopSheet, yTopSheet, xTopSheet + 10 *bbw, yTopSheet
line xTopSheet, yTopSheet+bbh, xTopSheet + 10 *bbw, yTopSheet+bbh
for i = 0 to 10
line xTopSheet + i*bbw, yTopSheet, xTopSheet + i*bbw, yTopSheet+bbh
next
for i = 1 to frame 'check game out
if i = 10 then 'at 10th first box is right at corner
rect xTopSheet + 9*bbw, yTopSheet step bw, bh
at xTopSheet + 9*bbw + 5, yTopSheet + 4 : ? score(10,1)
rect xTopSheet + 9*bbw + bw, yTopSheet step bw, bh
at xTopSheet + 9*bbw + bw + 5, yTopSheet + 4 : ? score(10,2)
else
rect xTopSheet + (i-1)*bbw + bw, yTopSheet step bw, bh
at xTopSheet + (i-1)*bbw + bw + 5, yTopSheet + 4 : ? score(i, 1)
rect xTopSheet + (i-1)*bbw + 2*bw, yTopSheet step bw, bh
at xTopSheet + (i-1)*bbw + 2*bw + 5, yTopSheet + 4: ? score(i, 2)
fi
at xTopSheet + (i-1)*bbw + bw/2 + 3, yTopSheet + bh + 6 : ? score(i,0)
next
if frame = 10 then
rect xTopSheet + 9*bbw + 2*bw, yTopSheet step bw, bh
at xTopSheet + 9*bbw + 2*bw + 5, yTopSheet + 4 : ? score(10,3)
fi
end

sub
totalUpScore(frame)
local i
'OK now let's take the game data and add up the score
for i = 1 to min(9, frame)
if score(i,1) = "X" then
if score(i+1,1) = "X" then
if i+1 = 10 then
if score(10,2) ="X" then
score(i,0) = score(i-1, 0) + 30
else
score(i,0) = score(i-1, 0) + 20 + val(score(10,2))
fi
else
if score(i +2, 1) = "X" then
score(i, 0) = score(i-1, 0) + 30
else
score(i, 0) = score(i-1, 0) + 20 + val(score(i+2,1))
fi
fi
else 'not "X"
if score(i+1, 2) = "/" then
score(i, 0) =score(i-1,0) + 20
else
score(i,0) = score(i-1, 0) + 10 + val(score(i+1, 1)) + val(score(i+1, 2))
fi
fi
else
if score(i,2) = "/" then
if score(i+1,1)= "X" then
score(i, 0) = score(i-1, 0) + 20
else
score(i, 0) = score(i-1, 0) + 10 + val(score(i+1, 1))
fi
else
score(i, 0) = score(i-1, 0) + val(score(i, 1)) + val(score(i, 2))
fi
fi
next
if frame = 10 then
'10th frame
if score(10, 1) = "X" then
if score(10, 2) = "X" then
if score(10,3) = "X" then
score(10, 0) = score(9,0) + 30
else
score(10, 0) = score(9,0) + 20 + val(score(10, 3))
fi
else
if score(10, 3) = "/" then
score(10,0) = score(9,0) + 20
else
score(10, 0) = score(9,0) + 10 + val(score(10,2)) + val(score(10,3))
fi
fi
else
if score(10, 2) = "/" then
score(10, 0) = score(9,0) + 10 + val(score(10, 3))
else
score(10, 0) = score(9,0) + val(score(10,1)) + val(score(10, 2))
fi
fi
fi
end

Here it is with score keeping and some tweaks on ball speed, pin size and drag on action to stop.

I love this game!

'bowling sample 5.bas for SmallBASIC 12.8 [B+=MGA] 2017-01-14

const th = txth("Q")
const tw = txtw("W")
const bh = th + 6
const bw = tw + 8
const bbw = 3 * bw
const bbh = 2 * bh
const xTopSheet = 30
const ytopSheet = 410

pins = 10
pr = 22
frame = 1
dim px(pins), py(pins), pa(pins), pc(pins), ps(pins)
dim rack(pins,2)
dim score(10, 3)

xoff = 0
yoff = 20
spacer = 80
ygutter = 4*spacer+2*yoff
pin = 1
for
row = 1 to 4
for col = 1 TO row
px(pin) = spacer*col + xoff
py(pin) = spacer*row - spacer/2*col + yoff
rack(pin, 0) = px(pin) : rack(pin, 1) = py(pin)
pin += 1
next
next

gameOver = 0
ball = 1
repeat

if ball = 1 or ball = 3 or ball = 4 or ball = 5 then 'put all the pins in rack
for i = 1 to pins
px(i) = rack(i,0) : py(i) = rack(i, 1) : ps(i) = 0 : pa(i) = 0
next
end if

pen on
x = -100 : y = -100
while x > xmax - pr or x < xmax - 200 or y < pr or y > ygutter- pr
cls
at 20, ygutter + 20 : ? "Click inside box to position ball."
for i = 1 to pins
if px(i) <> -1000 then
circle rack(i,0), rack(i, 1), pr, 1, 15 filled
px(i) = rack(i,0) : py(i) = rack(i, 1)
fi
next
rect xmax - 200, pr, xmax - pr, ygutter -pr
circle pen(4), pen(5), pr, 1, 9
if pen(3) then x = pen(4) : y = pen(5)
delay 20
showpage
wend
px(0) = x : py(0) = y

x = -10 : y = -10
while x > 500 or x < 0 or y < 0 or y > ygutter
cls
at 20, ygutter + 20 : ? "Click around the pins to set ball angle."
for i = 1 to pins
if px(i) <> -1000 then
'circle rack(i,0), rack(i, 1), pr, 1, 15 filled
circle px(i), py(i), pr, 1, 15 filled
fi
next
circle px(0), py(0), pr, 1, 9 filled
line px(0), py(0), pen(4), pen(5), 14
if pen(3) then x = pen(4) : y = pen(5)
delay 20
showpage
wend
pa(0) = atan2(y-py(0), x-px(0))
ps(0) = 20

notDone = 1
while notDone
cls
locate 1, 50 : ? frame
notDone = 0
line 0, ygutter, xmax, ygutter, 14
for i = 0 to pins
if px(i) <> -1000 then
for j = 1 to pins
if j <> i and pc(j) <> 1 then
if sqr((px(i)-px(j))^2 + (py(i)-py(j))^2) < 2*pr then
if i <> 0 then pa(i) = atan2(py(i)-py(j), px(i)-px(j))
pa(j) = atan2(py(j)-py(i), px(j)-px(i))
pc(i) = 1 : pc(j) = 1
s = (ps(i) + ps(j))/2
ps(i) = s : ps(j) = s
exit for
fi
fi
next
if ps(i) > 0 then ps(i) -= .005 else ps(i) = 0
px(i) = px(i)+cos(pa(i))*ps(i)
py(i) = py(i)+sin(pa(i))*ps(i)
if pa(i) > 2*pi then pa(i) = pa(i)-2*pi
if pa(i) < 0 then pa(i) = pa(i)+2*pi
if i = 0 then
color 9
elif pc(i)
color 12
else
color 15
end if
if py(i) < ygutter then circle px(i), py(i), pr filled else ps(i) = 0
if px(i) > spacer*6 and i<>0 then ps(i) = 0
pc(i) = 0
if px(i) > 0 and px(i) < xmax and py(i) > 0 and py(i) < ygutter and ps(i) > 0 then notDone = 1
fi 'if px(i) <> -100
next
showpage
delay 10
wend

cls
line 0, ygutter, xmax, ygutter, 14

cnt = 0
for i = 1 to pins
if sqr((px(i)-rack(i,0))^2 + (py(i)-rack(i,1))^2)< .5*pr then
circle rack(i, 0), rack(i, 1), pr, 1, 15 filled
else
px(i) = -1000 : py(i) = -1000 : ps(i) = 0 : pa(i) = 0
cnt += 1
fi
next

if cnt = 10 and ball = 1 then
at 20, ygutter + 20 :? "Frame: ";frame;" Strike!"
score(frame, 1) = "X"
if frame = 10 then
ball = 3
else
ball = 1 : frameUpdate = 1
fi

elif cnt = 10 and ball = 2 then
at 20, ygutter + 20 :? "Frame: ";frame;" Ball 1: ";b1cnt;" Ball 2: Spared!"
score(frame, 2) = "/"
if frame = 10 then
ball = 5
else
ball = 1 : frameUpdate = 1 : b1cnt = 0
fi

elif cnt = 10 and ball = 3 then
at 20, ygutter + 20 :? "Frame: 10 Strike 2!!"
ball = 4
score(frame, 2) = "X"
elif cnt = 10 and ball = 4 then
at 20, ygutter + 20 :? "Frame: 10 Strike 3!!"
score(frame, 3) = "X"
gameOver = 1
elif cnt = 10 and ball = 5 then
at 20, ygutter + 20 :? "Frame 10 Spare and 10 = 20"
score(frame, 3) = "X"
gameOver = 1
elif cnt = 10 and ball = 6 then
at 20, ygutter + 20 :? "Frame 10 Strike plus spare = 20"
score(frame, 3) = "/"
gameOver = 1
elif cnt < 10 and ball = 1 then
b1cnt = cnt
at 20, ygutter + 20 : ? "Frame: ";frame;" Ball 1: ";b1cnt
score(frame, 1) = str(b1cnt)
ball = 2
elif cnt < 10 and ball = 2 then
b2cnt = cnt - b1cnt
at 20, ygutter + 20 : ? "Frame: ";frame;" Ball 1: ";b1cnt;" Ball 2: ";b2cnt
score(frame, 2) = str(b2cnt)
ball = 1 : frameUpdate = 1
elif cnt < 10 and ball = 3 then
b3cnt = cnt
at 20, ygutter + 20 :? "Frame: 10 Strike plus ";b3cnt;" plus next ball"
score(10, 2) = str(b3cnt)
ball = 6
elif cnt < 10 and ball = 4 then
at 20, ygutter + 20 :? "Frame 10 2 Strikes plus ";cnt
score(10, 3) = str(cnt)
gameOver = 1
elif cnt < 10 and ball = 5 then
at 20, ygutter + 20 :? "Frame 10 Spare plus ";cnt
score(10, 3)= str(cnt)
gameOver = 1
elif cnt < 10 and ball = 6 then
at 20, ygutter + 20 :? "Frame 10 Strike plus ";b3cnt;" plus ";cnt - b3cnt
score(10, 3) = str(cnt-b3cnt)
gameOver = 1
fi

updateScore(frame)
frame += frameUpdate
frameUpdate = 0
showpage
delay 3000

if ball = 1 then b1cnt = 0 : b2cnt = 0
if frame = 11 then gameOver = 1

until
gameOver
locate 23, 1: ? "Goodbye!"
showpage
delay 5000

sub
updateScore(frame)
local i
totalUpScore(frame) 'totals up scores to current frame, yeah it's wrong for strikes and spares
'draw score sheet
line xTopSheet, yTopSheet, xTopSheet + 10 *bbw, yTopSheet
line xTopSheet, yTopSheet+bbh, xTopSheet + 10 *bbw, yTopSheet+bbh
for i = 0 to 10
line xTopSheet + i*bbw, yTopSheet, xTopSheet + i*bbw, yTopSheet+bbh
next
for i = 1 to frame 'check game out
if i = 10 then 'at 10th first box is right at corner
rect xTopSheet + 9*bbw, yTopSheet step bw, bh
at xTopSheet + 9*bbw + 5, yTopSheet + 4 : ? score(10,1)
rect xTopSheet + 9*bbw + bw, yTopSheet step bw, bh
at xTopSheet + 9*bbw + bw + 5, yTopSheet + 4 : ? score(10,2)
else
rect xTopSheet + (i-1)*bbw + bw, yTopSheet step bw, bh
at xTopSheet + (i-1)*bbw + bw + 5, yTopSheet + 4 : ? score(i, 1)
rect xTopSheet + (i-1)*bbw + 2*bw, yTopSheet step bw, bh
at xTopSheet + (i-1)*bbw + 2*bw + 5, yTopSheet + 4: ? score(i, 2)
fi
at xTopSheet + (i-1)*bbw + bw/2 + 3, yTopSheet + bh + 6 : ? score(i,0)
next
if frame = 10 then
rect xTopSheet + 9*bbw + 2*bw, yTopSheet step bw, bh
at xTopSheet + 9*bbw + 2*bw + 5, yTopSheet + 4 : ? score(10,3)
fi
end

sub
totalUpScore(frame)
local i
'OK now let's take the game data and add up the score
for i = 1 to min(9, frame)
if score(i,1) = "X" then
if score(i+1,1) = "X" then
if i+1 = 10 then
if score(10,2) ="X" then
score(i,0) = score(i-1, 0) + 30
else
score(i,0) = score(i-1, 0) + 20 + val(score(10,2))
fi
else
if score(i +2, 1) = "X" then
score(i, 0) = score(i-1, 0) + 30
else
score(i, 0) = score(i-1, 0) + 20 + val(score(i+2,1))
fi
fi
else 'not "X"
if score(i+1, 2) = "/" then
score(i, 0) =score(i-1,0) + 20
else
score(i,0) = score(i-1, 0) + 10 + val(score(i+1, 1)) + val(score(i+1, 2))
fi
fi
else
if score(i,2) = "/" then
if score(i+1,1)= "X" then
score(i, 0) = score(i-1, 0) + 20
else
score(i, 0) = score(i-1, 0) + 10 + val(score(i+1, 1))
fi
else
score(i, 0) = score(i-1, 0) + val(score(i, 1)) + val(score(i, 2))
fi
fi
next
if frame = 10 then
'10th frame
if score(10, 1) = "X" then
if score(10, 2) = "X" then
if score(10,3) = "X" then
score(10, 0) = score(9,0) + 30
else
score(10, 0) = score(9,0) + 20 + val(score(10, 3))
fi
else
if score(10, 3) = "/" then
score(10,0) = score(9,0) + 20
else
score(10, 0) = score(9,0) + 10 + val(score(10,2)) + val(score(10,3))
fi
fi
else
if score(10, 2) = "/" then ' EDIT 2017-01-16 fix spare then strike in 10th frame
if score(10,3) = "X" then
score(10, 0) = score(9, 0) + 20
else
score(10, 0) = score(9,0) + 10 + val(score(10, 3))
fi
else
score(10, 0) = score(9,0) + val(score(10,1)) + val(score(10, 2))
fi
fi
fi
end



EDIT: 2017-01-16 fixed a scoring problem of spare then strike in 10th frame, noted in code above.

REALLY well done!!! My first game was 135... Not the best I've ever bowled. Unpredictable pin movement makes it a real challenge. Excellent! No problems with scoring. No flickering. Runs really smooth. The only downside is my lack of bowling practice... This little puppy may be addictive....

Great job.

J

With Johnno's help at SdlBasic we've made a few improvements to the game visually and more bugs removed (I think).
It is funny to play this without the sound files!

' Bowling 7.bas for SmallBASIC 12.8 [B+=MGA] 2017-01-20
' cross pollinate work with Johnno at SdlBasic Bowling 6
' modify for SmallBASIC

const th = txth("Q")
const tw = txtw("W")
const bh = th + 6
const bw = tw + 8
const bbw = 3 * bw
const bbh = 2 * bh
const xTopSheet = 40
const ytopSheet = 450

const xoff = 0
const yoff = 20
const pins = 10
const pr = 22
const spacer = 80
const ygutter = 4 * spacer + 2 * yoff

const board1 = rgb(253, 200, 132)
const board2 = rgb(252, 191, 110)
const board3 = rgb(247, 179, 93)
const board4 = rgb(250, 187, 114)
const board5 = rgb(244, 169, 96)

dim px(pins), py(pins), pa(pins), pc(pins), ps(pins), pd(pins), pds(pins)
dim rack(pins,2)

pin = 1
for
row = 1 to 4
for col = 1 TO row
px(pin) = spacer*col + xoff
py(pin) = spacer*row - spacer/2*col + yoff
rack(pin, 0) = px(pin) : rack(pin, 1) = py(pin)
pin += 1
next
next

allDone = 0 : games = 0 : total = 0
while allDone = 0 'next game
rect 0, 0, xmax, ymax, 0 filled
dim score(10, 3) '0 for total, 1 = ball 1, 2 = ball 2, 3 = ball 3 in 10th frame
gameOver = 0 : frameUpdate = 0 : ball = 1 : frame = 1
while gameOver = 0

if ball = 1 or ball = 3 or ball = 4 or ball = 5 then 'put all the pins in rack
for i = 1 to pins
px(i) = rack(i,0) : py(i) = rack(i, 1) : ps(i) = 0 : pa(i) = 0 : pd(i) = 0 : pds(i) = 0
next
end if

x = -100 : y = -100
while x > xmax - pr or x < xmax - 200 or y < pr or y > ygutter- pr
rect 0, 0, xmax, yTopSheet, 0 filled
drawlane
color 15
at xTopSheet, ygutter + 20
? "Frame: ";frame;" Ball: ";sball();" Click behind red foul line to position ball."
for i = 1 to pins
if pd(i) = 0 then
px(i) = rack(i,0) : py(i) = rack(i, 1)
pinUp
fi
next
if pen(4) > xmax - 200 + pr and pen(4) < xmax - pr and pen(5) < ygutter - 18 - pr and pen(5) > pr then
circle pen(4), pen(5), pr, 1, 9
if pen(3) then x = pen(4) : y = pen(5)
end if
delay 10
showpage
wend
px(0) = x : py(0) = y

x = -10 : y = -10
while x > 500 or x < 0 or y < 0 or y > ygutter
rect 0, 0, xmax, yTopSheet, 0 filled
drawlane
color 15
at xTopSheet, ygutter + 20
? "Frame: ";frame;" Ball: ";sball();" Click around the pins to set ball angle."
for i = 1 to pins
if pd(i) = 0 then
'circle rack(i,0), rack(i, 1), pr, 1, 15 filled
pinUp
fi
next
drawball
if pen(4) < xmax - 200 - pr and pen(4) > pr and pen(4) < ygutter - pr then
line px(0), py(0), pen(4), pen(5), 0
if pen(3) then x = pen(4) : y = pen(5)
fi
delay 10
showpage
wend
pa(0) = atan2(y-py(0), x-px(0)) : ps(0) = 25

notDone = 1
while notDone
notDone = 0
rect 0, 0, xmax, yTopSheet, 0 filled
color 15
at xTopSheet, ygutter + 20
? "Frame: ";frame;" Ball: ";sball()
drawlane
for i = 0 to pins
if px(i) <> -1000 then
for j = 0 to pins
if j <> i and pc(j) <> 1 then
if sqr((px(i)-px(j))^2 + (py(i)-py(j))^2) < 2*pr then
if i <> 0 then pa(i) = atan2(py(i)-py(j), px(i)-px(j)) : pc(i) = 1
if j <> 0 then pa(j) = atan2(py(j)-py(i), px(j)-px(i)) : pc(j) = 1:
s = (ps(i) + ps(j))/2 : ps(i) = s : ps(j) = s
exit for
fi
fi
next

if ps(i) > 0 then ps(i) -= .007 else ps(i) = 0
px(i) = px(i)+cos(pa(i))*ps(i)
py(i) = py(i)+sin(pa(i))*ps(i)
if pa(i) > 2*pi then pa(i) = pa(i)-2*pi
if pa(i) < 0 then pa(i) = pa(i)+2*pi
if py(i) < ygutter and i <> 0 then
if pd(i) = 0 and sqr((px(i) - rack(i,0))^2 + (py(i) - rack(i,1))^2) > .5*pr then
pd(i) = 1 : pds(i) = rnd * 2 * pi
end if
if pd(i) = 0 then
pinUp
else
pinDown
fi
elseif py(i) >= ygutter and i <> 0 then
pd(i) = 1
end if
if i = 0 then drawball
if px(i) > spacer*6 and i<>0 then ps(i) = 0
pc(i) = 0
if px(i) > 0 and px(i) < xmax and py(i) > 0 and py(i) < ygutter and ps(i) > 0 then notDone = 1
fi 'if px(i) <> -100
next
showpage
delay 10
wend

rect 0, 0, xmax, ymax, 0 filled
cnt = 0
color 15
for i = 1 to pins
if pd(i) then px(i) = -1000 : py(i) = -1000 : ps(i) = 0 : pa(i) = 0 : cnt += 1
next

if cnt = 10 and ball = 1 then
at xTopSheet, ygutter + 20 :? "Frame: ";frame;" Strike!"
score(frame, 1) = "X"
if frame = 10 then
ball = 3
else
ball = 1 : frameUpdate = 1
fi
elif cnt = 10 and ball = 2 then
at xTopSheet, ygutter + 20 :? "Frame: ";frame;" Ball 1: ";b1cnt;" Ball 2: Spared!"
score(frame, 2) = "/"
if frame = 10 then
ball = 5
else
ball = 1 : frameUpdate = 1 : b1cnt = 0
fi
elif cnt = 10 and ball = 3 then
at xTopSheet, ygutter + 20 :? "Frame: 10 Strike 2!!"
ball = 4
score(frame, 2) = "X"
elif cnt = 10 and ball = 4 then
at xTopSheet, ygutter + 20 :? "Frame: 10 Strike 3!!"
score(frame, 3) = "X"
gameOver = 1
elif cnt = 10 and ball = 5 then
at xTopSheet, ygutter + 20 :? "Frame 10 Spare and 10 = 20"
score(frame, 3) = "X"
gameOver = 1
elif cnt = 10 and ball = 6 then
at xTopSheet, ygutter + 20 :? "Frame 10 Strike plus spare = 20"
score(frame, 3) = "/"
gameOver = 1
elif cnt < 10 and ball = 1 then
b1cnt = cnt
at xTopSheet, ygutter + 20 : ? "Frame: ";frame;" Ball 1: ";b1cnt
score(frame, 1) = str(b1cnt)
ball = 2
elif cnt < 10 and ball = 2 then
b2cnt = cnt - b1cnt
at xTopSheet, ygutter + 20 : ? "Frame: ";frame;" Ball 1: ";b1cnt;" Ball 2: ";b2cnt
score(frame, 2) = str(b2cnt)
ball = 1 : frameUpdate = 1
elif cnt < 10 and ball = 3 then
b3cnt = cnt
at xTopSheet, ygutter + 20 :? "Frame: 10 Strike plus ";b3cnt;" plus next ball"
score(10, 2) = str(b3cnt)
ball = 6
elif cnt < 10 and ball = 4 then
at xTopSheet, ygutter + 20 :? "Frame 10 2 Strikes plus ";cnt
score(10, 3) = str(cnt)
gameOver = 1
elif cnt < 10 and ball = 5 then
at xTopSheet, ygutter + 20 :? "Frame 10 Spare plus ";cnt
score(10, 3)= str(cnt)
gameOver = 1
elif cnt < 10 and ball = 6 then
at xTopSheet, ygutter + 20 :? "Frame 10 Strike plus ";b3cnt;" plus ";cnt - b3cnt
score(10, 3) = str(cnt-b3cnt)
gameOver = 1
fi

updateScore(frame)
frame += frameUpdate
frameUpdate = 0
showpage
delay 3000

if ball = 1 then b1cnt = 0 : b2cnt = 0
if frame = 11 then gameOver = 1

wend '======================================================= gameOver
total = total + score(10, 0) : games += 1
color 15
at xTopSheet, yTopSheet + 80
? "Games = ";games;" Average = ";total\games
at xTopsheet, yTopSheet + 105
input "Play Again? Enter y for yes (any other quits) ";again
if
again <> "y" then allDone = 1
wend '================================================================== All Done

sub
drawball()
local r
circle px(0)-15, py(0), pr, 1, 0 filled
for r = pr+5 to 1 step -1
circle px(0), py(0), r, 1, rgb(0, 0, 255 - 100 * r/pr) filled
next
end

sub
pinUp()
circle px(i), py(i), pr, 1, 15 filled
p7 = int(.7*pr)
circle px(i), py(i), p7, 1, 12
circle px(i), py(i), p7+1, 1, 12
circle px(i), py(i), .6*pr, 1, 12
end


sub
pinDown()
local j
circle px(i)-6, py(i), pr, 1, 0 filled
circle px(i)+1.5*pr*cos(pds(i))-5, py(i)+1.5*pr*sin(pds(i)), .7*pr, 1, 0 filled
circle px(i), py(i), pr, 1, 15 filled
for j = 1 to 1.5*pr
if (j - .9*pr < 3 and j -.9*pr > 0) then
circle px(i)+j*cos(pds(i)), py(i)+j*sin(pds(i)), .75*pr, 1, 12 filled
elseif (j - 1.1*pr < 3 and j -1.1*pr > 0) then
circle px(i)+j*cos(pds(i)), py(i)+j*sin(pds(i)), .7*pr, 1, 12 filled
else
circle px(i)+j*cos(pds(i)), py(i)+j*sin(pds(i)), .7*pr, 1, 15 filled
end if
next
end

sub
drawlane()
local b, y
b = 0
for y = 22 to 332 step 10
select case (b mod 5)
case 0 : color board1
case 1 : color board3
case 2 : color board2
case 3 : color board5
case 4 : color board4
end select
rect pr, y, xmax - pr, y + 10 filled
b += 1
next
color 12
rect xmax - 200, pr, xmax - pr, ygutter - 18
rect xmax - 201, pr-1, xmax - pr+1, ygutter - 19
end

sub
updateScore(frame)
local i
totalUpScore(frame) 'totals up scores to current frame, yeah it's wrong for strikes and spares
'draw score sheet
line xTopSheet, yTopSheet, xTopSheet + 10 *bbw, yTopSheet
line xTopSheet, yTopSheet+bbh, xTopSheet + 10 *bbw, yTopSheet+bbh
for i = 0 to 10
line xTopSheet + i*bbw, yTopSheet, xTopSheet + i*bbw, yTopSheet+bbh
next
for i = 1 to frame 'check game out
if i = 10 then 'at 10th first box is right at corner
rect xTopSheet + 9*bbw, yTopSheet step bw, bh
at xTopSheet + 9*bbw + 5, yTopSheet + 4 : ? score(10,1)
rect xTopSheet + 9*bbw + bw, yTopSheet step bw, bh
at xTopSheet + 9*bbw + bw + 5, yTopSheet + 4 : ? score(10,2)
else
rect xTopSheet + (i-1)*bbw + bw, yTopSheet step bw, bh
at xTopSheet + (i-1)*bbw + bw + 5, yTopSheet + 4 : ? score(i, 1)
rect xTopSheet + (i-1)*bbw + 2*bw, yTopSheet step bw, bh
at xTopSheet + (i-1)*bbw + 2*bw + 5, yTopSheet + 4: ? score(i, 2)
fi
at xTopSheet + (i-1)*bbw + bw/2 + 3, yTopSheet + bh + 6 : ? score(i,0)
next
if frame = 10 then
rect xTopSheet + 9*bbw + 2*bw, yTopSheet step bw, bh
at xTopSheet + 9*bbw + 2*bw + 5, yTopSheet + 4 : ? score(10,3)
fi
end

sub
totalUpScore(frame)
local i
'OK now let's take the game data and add up the score
for i = 1 to min(9, frame)
if score(i,1) = "X" then
if score(i+1,1) = "X" then
if i+1 = 10 then
if score(10,2) ="X" then
score(i,0) = score(i-1, 0) + 30
else
score(i,0) = score(i-1, 0) + 20 + val(score(10,2))
fi
else
if score(i +2, 1) = "X" then
score(i, 0) = score(i-1, 0) + 30
else
score(i, 0) = score(i-1, 0) + 20 + val(score(i+2,1))
fi
fi
else 'not "X"
if score(i+1, 2) = "/" then
score(i, 0) =score(i-1,0) + 20
else
score(i,0) = score(i-1, 0) + 10 + val(score(i+1, 1)) + val(score(i+1, 2))
fi
fi
else
if score(i,2) = "/" then
if score(i+1,1)= "X" then
score(i, 0) = score(i-1, 0) + 20
else
score(i, 0) = score(i-1, 0) + 10 + val(score(i+1, 1))
fi
else
score(i, 0) = score(i-1, 0) + val(score(i, 1)) + val(score(i, 2))
fi
fi
next
if frame = 10 then
'10th frame
if score(10, 1) = "X" then
if score(10, 2) = "X" then
if score(10,3) = "X" then
score(10, 0) = score(9,0) + 30
else
score(10, 0) = score(9,0) + 20 + val(score(10, 3))
fi
else
if score(10, 3) = "/" then
score(10,0) = score(9,0) + 20
else
score(10, 0) = score(9,0) + 10 + val(score(10,2)) + val(score(10,3))
fi
fi
else
if score(10, 2) = "/" then ' EDIT 2017-01-16 fix spare then strike in 10th frame
if score(10,3) = "X" then
score(10, 0) = score(9, 0) + 20
else
score(10, 0) = score(9,0) + 10 + val(score(10, 3))
fi
else
score(10, 0) = score(9,0) + val(score(10,1)) + val(score(10, 2))
fi
fi
fi
end


func
sball() 'what ball number to show with frame
if ball = 1 or ball = 2 then
sball = ball
elseif ball = 3 then
sball = 2
else
sball = 3
end if
end


> It is funny to play this without the sound files!

Nice work! It would be fun to add sound using the PLAY command. Do you have a link to the original sound files?

The sound files were posted at SdlBasic Forum by Johnno56 in .wav format.

The link is

http://sdlbasic.epizy.com/showthread.php?tid=352

reply #9, Bowl.zip and pickup.zip, you have to be a member to download the attached files.

I would be very (pleasantly) surprised to learn if these could be played in SB! (So would johnno56, I think!)

I added these lines at line 101:

if ball = 1 then
PLAY("file://bowl.wav")
else
PLAY("file://pickup.wav")
end if

For this to work the .wav files need to be in the same folder as the .bas file (tested in ubuntu, but no reason is shouldn't work in windows).

Also, you could consider refactoring some of the code in the long while loop (while gameOver = 0...) into separate SUB or FUNCS for readability.

The SB code that handles PLAY is not very efficient, since it needs to reload the entire .wav file each time it's played. I'll make some changes to address that in the next update (good to have an example now to see what needs improving).

Working for Windows 10 laptop. Specially when you turn the audio ON at the right mouse click menu! ;-))

line 101 for me put me inside the pin action code block, line 96, for me, works just before that code block.

All pins are reracked for ball numbers 1, 3, 4, 5 so the bowl sound works best then

if ball = 1 or ball = 3 or ball = 4 or ball = 5 then
PLAY("file://bowl.wav")
else
PLAY("file://pickup.wav")
end if


Chris this is a very pleasant surprise! I guess I missed an update announcement, or it didn't register because I don't mess around with sound files, that might change!

Yeah, it's probably time to break the code up into more manageable procedures.

I could have just posted the wav files. You don't have to be a member... what am I saying?!?!... We need all the members we can get... lol

Looking forward to seeing (and hearing) the game run... :)

J

OK, re-fractured the code ;-))


' Bowling 7 rf.bas for SmallBASIC 12.8 [B+=MGA] 2017-01-21
' cross pollinate work with Johnno at SdlBasic Bowling 6
' modify for SmallBASIC, now with sound!

const th = txth("Q")
const tw = txtw("W")
const bh = th + 6
const bw = tw + 8
const bbw = 3 * bw
const bbh = 2 * bh
const xTopSheet = 40
const ytopSheet = 450

const xoff = 0
const yoff = 20
const pins = 10
const pr = 22
const spacer = 80
const ygutter = 4 * spacer + 2 * yoff

const board1 = rgb(253, 200, 132)
const board2 = rgb(252, 191, 110)
const board3 = rgb(247, 179, 93)
const board4 = rgb(250, 187, 114)
const board5 = rgb(244, 169, 96)

dim px(pins), py(pins), pa(pins), pc(pins), ps(pins), pd(pins), pds(pins)
dim rack(pins,2)

initRack

allDone = 0 : games = 0 : total = 0
while allDone = 0 '====================================== loop for whole session
rect 0, 0, xmax, ymax, 0 filled
dim score(10, 3) '0 for total, 1 = ball 1, 2 = ball 2, 3 = ball 3 in 10th frame
gameOver = 0 : ball = 1 : frame = 1
while gameOver = 0 '======================================== game loop
if ball = 1 or ball = 3 or ball = 4 or ball = 5 then 'put all the pins in rack
for i = 1 to pins
px(i) = rack(i,0) : py(i) = rack(i, 1)
ps(i) = 0 : pa(i) = 0 : pd(i) = 0 : pds(i) = 0
next
end if
ballStart
ballAim
pinAction
ballReport
wend '======================================================= game end loop

total = total + score(10, 0) : games += 1
color 15
at xTopSheet, yTopSheet + 80
? "Games = ";games;" Average = ";total\games
at xTopsheet, yTopSheet + 105
input "Play Again? Enter y for yes (any other quits) ";again
if again <> "y" then allDone = 1
wend '================================================================ All Done

sub
initRack()
local pin, row, col
pin = 1
for row = 1 to 4
for col = 1 TO row
rack(pin, 0) = spacer * col + xoff
rack(pin, 1) = spacer * row - col * spacer / 2 + yoff
pin += 1
next
next
end

sub
ballStart()
local x, y, i
x = -100 : y = -100
while x > xmax - pr or x < xmax - 200 or y < pr or y > ygutter- pr
rect 0, 0, xmax, yTopSheet, 0 filled
drawlane
color 15
at xTopSheet, ygutter + 20
? "Frame: ";frame;" Ball: ";sball();" Click behind red foul line to position ball."
for i = 1 to pins
if pd(i) = 0 then px(i) = rack(i,0) : py(i) = rack(i, 1) : pinUp i
next
if pen(4) > xmax - 200 + pr and pen(4) < xmax - pr and pen(5) < ygutter - 18 - pr and pen(5) > pr then
circle pen(4), pen(5), pr, 1, 9
if pen(3) then x = pen(4) : y = pen(5)
end if
showpage
delay 10
wend
px(0) = x : py(0) = y
end

sub
ballAim()
local x, y, i
x = -10 : y = -10
while x > 500 or x < 0 or y < 0 or y > ygutter
rect 0, 0, xmax, yTopSheet, 0 filled
drawlane
color 15
at xTopSheet, ygutter + 20
? "Frame: ";frame;" Ball: ";sball();" Click around the pins to set ball angle."
for i = 1 to pins
if pd(i) = 0 then pinUp i
next
drawball
if pen(4) < xmax - 200 - pr and pen(5) > pr and pen(5) < ygutter - pr then
line px(0), py(0), pen(4), pen(5), 0
if pen(3) then x = pen(4) : y = pen(5)
fi
showpage
delay(10)
wend
pa(0) = atan2(y - py(0), x - px(0)) : ps(0) = 25
if ball = 1 or ball = 3 or ball = 4 or ball = 5 then
PLAY("file://bowl.wav")
else
PLAY("file://pickup.wav")
end if
end

sub
pinAction()
local notDone, i, j, s
notDone = 1
while notDone
notDone = 0
rect 0, 0, xmax, yTopSheet, 0 filled
color 15
at xTopSheet, ygutter + 20
? "Frame: ";frame;" Ball: ";sball()
drawlane
for i = 0 to pins
for j = 0 to pins
if j <> i and pc(j) <> 1 then
if sqr((px(i)-px(j))^2 + (py(i)-py(j))^2) < 2*pr then
if i <> 0 then pa(i) = atan2(py(i)-py(j), px(i)-px(j)) : pc(i) = 1
if j <> 0 then pa(j) = atan2(py(j)-py(i), px(j)-px(i)) : pc(j) = 1
s = (ps(i) + ps(j))/2 : ps(i) = s : ps(j) = s
exit for
fi
fi
next
if ps(i) > 0 then ps(i) -= .007 else ps(i) = 0
px(i) = px(i) + cos(pa(i)) * ps(i)
py(i) = py(i) + sin(pa(i)) * ps(i)
if pa(i) > 2 * pi then pa(i) = pa(i) - 2 * pi
if pa(i) < 0 then pa(i) = pa(i) + 2 * pi
if py(i) < ygutter and i <> 0 then
if pd(i) = 0 and sqr((px(i) - rack(i,0))^2 + (py(i) - rack(i,1))^2) > .5*pr then
pd(i) = 1 : pds(i) = rnd * 2 * pi
end if
if pd(i) = 0 then pinUp i else pinDown i
elseif py(i) >= ygutter and i <> 0 then
pd(i) = 1
end if
if i = 0 then drawball
if px(i) > spacer * 6 and i <> 0 then ps(i) = 0
pc(i) = 0
if px(i) > 0 and px(i) < xmax and py(i) > 0 and py(i) < ygutter and ps(i) > 0 then notDone = 1
next
showpage
delay 10
wend
end

sub
ballReport()
local i, cnt
rect 0, 0, xmax, ymax, 0 filled
cnt = 0 : frameUpdate = 0
color 15
for i = 1 to pins
if pd(i) then px(i) = -1000 : py(i) = -1000 : ps(i) = 0 : pa(i) = 0 : cnt += 1
next
if cnt = 10 and ball = 1 then
at xTopSheet, ygutter + 20 :? "Frame: ";frame;" Strike!"
score(frame, 1) = "X"
if frame = 10 then ball = 3 else ball = 1 : frameUpdate = 1
elif cnt = 10 and ball = 2 then
at xTopSheet, ygutter + 20 :? "Frame: ";frame;" Ball 1: ";b1cnt;" Ball 2: Spared!"
score(frame, 2) = "/"
if frame = 10 then ball = 5 else ball = 1 : frameUpdate = 1 : b1cnt = 0
elif cnt = 10 and ball = 3 then
at xTopSheet, ygutter + 20 :? "Frame: 10 Strike 2!!"
ball = 4 : score(frame, 2) = "X"
elif cnt = 10 and ball = 4 then
at xTopSheet, ygutter + 20 :? "Frame: 10 Strike 3!!"
score(frame, 3) = "X" : gameOver = 1
elif cnt = 10 and ball = 5 then
at xTopSheet, ygutter + 20 :? "Frame 10 Spare and 10 = 20"
score(frame, 3) = "X" : gameOver = 1
elif cnt = 10 and ball = 6 then
at xTopSheet, ygutter + 20 :? "Frame 10 Strike plus spare = 20"
score(frame, 3) = "/" : gameOver = 1
elif cnt < 10 and ball = 1 then
b1cnt = cnt
at xTopSheet, ygutter + 20 : ? "Frame: ";frame;" Ball 1: ";b1cnt
score(frame, 1) = str(b1cnt) : ball = 2
elif cnt < 10 and ball = 2 then
b2cnt = cnt - b1cnt
at xTopSheet, ygutter + 20 : ? "Frame: ";frame;" Ball 1: ";b1cnt;" Ball 2: ";b2cnt
score(frame, 2) = str(b2cnt) : ball = 1 : frameUpdate = 1
elif cnt < 10 and ball = 3 then
b3cnt = cnt
at xTopSheet, ygutter + 20 :? "Frame: 10 Strike plus ";b3cnt;" plus next ball"
score(10, 2) = str(b3cnt) : ball = 6
elif cnt < 10 and ball = 4 then
at xTopSheet, ygutter + 20 :? "Frame 10 2 Strikes plus ";cnt
score(10, 3) = str(cnt) : gameOver = 1
elif cnt < 10 and ball = 5 then
at xTopSheet, ygutter + 20 :? "Frame 10 Spare plus ";cnt
score(10, 3)= str(cnt) : gameOver = 1
elif cnt < 10 and ball = 6 then
at xTopSheet, ygutter + 20 :? "Frame 10 Strike plus ";b3cnt;" plus ";cnt - b3cnt
score(10, 3) = str(cnt-b3cnt) : gameOver = 1
fi
updateScore
frame += frameUpdate
showpage
delay 3000
if ball = 1 then b1cnt = 0 : b2cnt = 0
if frame = 11 then gameOver = 1
end

sub
drawball()
local r
circle px(0) - 6, py(0), pr + 5, 1, 0 filled
for r = pr + 5 to 1 step -1
circle px(0), py(0), r, 1, rgb(0, 0, 255 - 100 * r / pr) filled
next
end

sub
pinUp(i)
local p7
circle px(i) - 6, py(i), pr, 1, 0 filled
circle px(i), py(i), pr, 1, 15 filled
p7 = int(.7 * pr)
circle px(i), py(i), p7, 1, 12
circle px(i), py(i), p7 + 1, 1, 12
circle px(i), py(i), .6 * pr, 1, 12
end


sub
pinDown(i)
local j
circle px(i) - 6, py(i), pr, 1, 0 filled
circle px(i) + 1.5*pr*cos(pds(i)) - 5, py(i) + 1.5*pr*sin(pds(i)), .7*pr, 1, 0 filled
circle px(i), py(i), pr, 1, 15 filled
for j = 1 to 1.5*pr
if (j - .9*pr < 3 and j -.9*pr > 0) then
circle px(i) + j*cos(pds(i)), py(i) + j*sin(pds(i)), .75*pr, 1, 12 filled
elseif (j - 1.1*pr < 3 and j -1.1*pr > 0) then
circle px(i) + j*cos(pds(i)), py(i) + j*sin(pds(i)), .7*pr, 1, 12 filled
else
circle px(i) + j*cos(pds(i)), py(i) + j*sin(pds(i)), .7*pr, 1, 15 filled
end if
next
end

sub
drawlane()
local b, y
b = 0
for y = 22 to 332 step 10
select case (b mod 5)
case 0 : color board1
case 1 : color board3
case 2 : color board2
case 3 : color board5
case 4 : color board4
end select
rect pr, y, xmax - pr, y + 10 filled
b += 1
next
color 12
rect xmax - 200, pr, xmax - pr, ygutter - 18
rect xmax - 201, pr - 1, xmax - pr + 1, ygutter - 19
end

sub
updateScore()
local i
totalUpScore() 'totals up scores to current frame, yeah it's wrong for strikes and spares
'draw score sheet
line xTopSheet, yTopSheet, xTopSheet + 10 *bbw, yTopSheet
line xTopSheet, yTopSheet+bbh, xTopSheet + 10 *bbw, yTopSheet+bbh
for i = 0 to 10
line xTopSheet + i*bbw, yTopSheet, xTopSheet + i*bbw, yTopSheet+bbh
next
for i = 1 to frame 'check game out
if i = 10 then 'at 10th first box is right at corner
rect xTopSheet + 9*bbw, yTopSheet step bw, bh
at xTopSheet + 9*bbw + 5, yTopSheet + 4 : ? score(10, 1)
rect xTopSheet + 9*bbw + bw, yTopSheet step bw, bh
at xTopSheet + 9*bbw + bw + 5, yTopSheet + 4 : ? score(10, 2)
else
rect xTopSheet + (i-1)*bbw + bw, yTopSheet step bw, bh
at xTopSheet + (i-1)*bbw + bw + 5, yTopSheet + 4 : ? score(i, 1)
rect xTopSheet + (i-1)*bbw + 2*bw, yTopSheet step bw, bh
at xTopSheet + (i-1)*bbw + 2*bw + 5, yTopSheet + 4: ? score(i, 2)
fi
at xTopSheet + (i-1)*bbw + bw/2 + 3, yTopSheet + bh + 6 : ? score(i, 0)
next
if frame = 10 then
rect xTopSheet + 9*bbw + 2*bw, yTopSheet step bw, bh
at xTopSheet + 9*bbw + 2*bw + 5, yTopSheet + 4 : ? score(10, 3)
fi
end

sub
totalUpScore()
local i
for i = 1 to min(9, frame)
if score(i, 1) = "X" then
if score(i + 1, 1) = "X" then
if i + 1 = 10 then
if score(10, 2) ="X" then
score(i, 0) = score(i - 1, 0) + 30
else
score(i, 0) = score(i - 1, 0) + 20 + val(score(10, 2))
fi
else
if score(i + 2, 1) = "X" then
score(i, 0) = score(i - 1, 0) + 30
else
score(i, 0) = score(i - 1, 0) + 20 + val(score(i + 2, 1))
fi
fi
else 'not "X"
if score(i + 1, 2) = "/" then
score(i, 0) =score(i - 1, 0) + 20
else
score(i,0)=score(i-1,0)+10+val(score(i+1,1))+val(score(i+1,2))
fi
fi
else
if score(i,2) = "/" then
if score(i+1, 1)= "X" then
score(i, 0) = score(i-1, 0) + 20
else
score(i, 0) = score(i-1, 0) + 10 + val(score(i+1, 1))
fi
else
score(i, 0) = score(i-1, 0) + val(score(i, 1)) + val(score(i, 2))
fi
fi
next
if frame = 10 then
if score(10, 1) = "X" then
if score(10, 2) = "X" then
if score(10, 3) = "X" then
score(10, 0) = score(9, 0) + 30
else
score(10, 0) = score(9, 0) + 20 + val(score(10, 3))
fi
else
if score(10, 3) = "/" then
score(10, 0) = score(9, 0) + 20
else
score(10, 0) = score(9, 0) + 10 + val(score(10,2)) + val(score(10,3))
fi
fi
else
if score(10, 2) = "/" then
if score(10, 3) = "X" then
score(10, 0) = score(9, 0) + 20
else
score(10, 0) = score(9, 0) + 10 + val(score(10, 3))
fi
else
score(10, 0) = score(9, 0) + val(score(10, 1)) + val(score(10, 2))
fi
fi
fi
end


func
sball() 'what ball number to show with frame
if ball = 1 or ball = 2 then
sball = ball
elseif ball = 3 then
sball = 2
else
sball = 3
end if
end


Johnno, you could still post post the wav for those who might want to try out the bowling game.
Wait, we could use more members at SdlBasic ;-))


Just had a thought... I tested the SB version, and apart from the exceedingly short lane, it looks normal...
My point is: The sdlbasic version uses a 1280x720 display. Correct me if I am wrong... xmax = 640 and ymax = 480 for SB? Yes?
Perhaps if all graphics (not the one's need for the scoreboard) were reduced in size by 50% so as to fit within a 640x480 screen. What do you think?

Just a thought...

J

For SB, xmax, ymax depend on the screen dimensions of your device. Why would it be exceeding short lane??? It should be longer than 1280!!! Have you maximized your SB screen, (before you run a program)?

My device (laptop) is around 1280 x720 once you deduct the tool bar I have on the left side of my screen, so my sdlbasic screen fits inside the frame of my screen so I can view maximum screen area when I set display to 1280 x 720 screen in sdlbasic.

BTW, if you are using ipad or phone that handles landscape and portrait views xmax, ymax will adapt to 90 degree angle changes. This makes it very tricky writing graphics code that could work universally.

The bowling game will probably not be successful with portrait view screens where xmax < ymax!

That loud noise you will probably hear, would be the palm of my hand, hitting my forehead.... Did not even think about resizing the screen... Well... Look at THAT a full lane.... so much for my 640 pixel lane idea.... lol

Yeah. I think that versions for ipad's and phones are going to take a few more brain cells than I've got... lol I would have no idea as towhat to do or where to start.... I need coffee... My brain hurts...

J

This (link to wav files for bowling game) will be handy for SB followers.

In case you copied the latest re-fracture, I made a tiny edit of old code that was no longer needed in pinAction sub. It won't make much of difference in speed just an un-needed if then block...