Maze+Ball game v1.0 (iPad only)
Posted: Sat Jan 07, 2017 7:48 pm
With the finger swipe routine working, I was able to make this little puzzle game. You move the ball through the maze by swing finger in a direction to go. The object is the reach the golden star. There are ten levels and they get increasingly harder.
Every level is solvable, I can post cheat codes if you need for a level. You can design your own levels if you want, the code isn't too hard to understand. I didn't design every level.
I'm using some emoji for the playing pieces, so I'd like to know if they show up the same on everyone's device, or just mine. I'll try and post a screen shot.
Have fun. "A little nonsense now and then is cherished by the wisest men." - Willy Wonka movie.
- Dav
Every level is solvable, I can post cheat codes if you need for a level. You can design your own levels if you want, the code isn't too hard to understand. I didn't design every level.
I'm using some emoji for the playing pieces, so I'd like to know if they show up the same on everyone's device, or just mine. I'll try and post a screen shot.
Have fun. "A little nonsense now and then is cherished by the wisest men." - Willy Wonka movie.
- Dav
Code: Select all
'mazeball.txt v1.0 (ipad only)
'Move ball by swiping finger up/down/left/right.
'Walls will stop the ball moving. Navigate around
'them. Goal is to reach star with ball. There are
'10 levels to complete, they get harder & harder.
'Game progress saved to file called mazeball.dat.
'Coded by Dav, JAN/2017
'Solutions below, for those who get stuck...
'#1) LURDR
'#2) LURULDRUL
'#3) DRULDRDLULUR
'#4) DRURULURULDR
'#5) URDLULDLURDLU
'#6) RDRULDRULDRD
'#7) DRULDLURDRULDRD
'#8) RDLDLULDLURURULDRD
'#9) LURULULDLDRDRURULURDLDR
'#10)DRULDLDRURULULURDLURDRULDRURD
if capstr$(device_type$()) <> "IPAD" then
print "Sorry, this game is only for iPad."
end
end if
puzzle=1 'start on puzzle 1
puzzlemax=10 'there are 10 puzzles total
'=== read data file, make new if not there
if file_exists("mazeball.dat") then
file "mazeball.dat" read lev
if lev < 1 or lev > puzzlemax then goto makenew
puzzle=lev
else
makenew:
file "mazeball.dat" write puzzle
end if
'puzzle=10 'level override for testing
graphics
option base 1
set orientation top
get screen size sw,sh
gosub drawpuzzle
SwipeDistance= sw/6 'how far to swipe (adjust)
do
'if first touch..
get touch 0 as tx,ty
'if screen touched
if tx>-1 then
'while finger down...
while touch_x(0)>-1
'keep polling x & y locations
get touch 0 as movx,movy
newx= movx-tx ! newy= movy-ty
'move right
if newx >SwipeDistance and movx>0 then
'current sprite location in x,y
get sprite "b" pos sx,sy
cx=sx/bs+1!cy=sy/bs+1 'current x,y
for x = cx+1 to px
if pdata$(cy,x)="y" then
gosub win
gosub drawpuzzle
end if
if pdata$(cy,x)="x" then
blocked ! goto moved
else
'move it smoothly
for x2=((x-1-cx)*bs) to ((x-cx)*bs)
sprite "b" at sx+x2,sy
pause .0001
next x2
end if
next x
end if
'left
if newx <-SwipeDistance and movx >0 then
'current sprite location in x,y
get sprite "b" pos sx,sy
cx=sx/bs+1!cy=sy/bs+1 'current x,y
for x=cx-1 to 1 step -1
if pdata$(cy,x)="y" then
gosub win
gosub drawpuzzle
end if
if pdata$(cy,x)="x" then
blocked ! goto moved
else
for x2=(x+1-cx)*bs to (x-cx)*bs step -1
sprite "b" at sx+x2,sy
pause .0001
next x2
end if
next x
end if
'down
if newy >SwipeDistance and movy > 0 then
'current sprite location in x,y
get sprite "b" pos sx,sy
cx=sx/bs+1!cy=sy/bs+1 'current x,y
for y=cy+1 to py
if pdata$(y,cx)="y" then
gosub win
gosub drawpuzzle
end if
if pdata$(y,cx)="x" then
blocked ! goto moved
else
for y2=(y-1-cy)*bs to (y-cy)*bs
sprite "b" at sx,sy+y2
pause .0001
next y2
end if
next y
end if
'up
if newy <-SwipeDistance and movy > 0 then
'current sprite location in x,y
get sprite "b" pos sx,sy
cx=sx/bs+1!cy=sy/bs+1 'current x,y
for y=cy-1 to 1 step -1
if pdata$(y,cx)="y" then
gosub win
gosub drawpuzzle
end if
if pdata$(y,cx)="x" then
blocked ! goto moved
else
for y2 = (y+1-cy)*bs to (y-cy)*bs step -1
sprite "b" at sx,sy+y2
pause .0001
next y2
end if
next y
end if
end while
moved:
'wait for finger up
while touch_x(0)>-1 ! end while
end if
if button_pressed("restart") then gosub drawpuzzle
until 0
end
'===
win:
'===
get sprite "y" pos _x,_y
notes set "9:tc6e6f6g6" ! notes play
a=255
for g= 1 to 500 step 10
sprite "y" alpha a/255!a=a-5
sprite "y" at _x,_y scale g/(50-puzzle) angle g/100
pause .02
next g
sprite "y" delete
puzzle=puzzle+1
if puzzle>puzzlemax then goto wingame
return
'======
wingame:
'======
graphics clear .2,.2,.2
button "restart" delete
sprites delete
draw font size 56
draw color 1,1,0
draw text "YOU DID IT!" at 200,125
draw text "Congratulations!" at 125,700
'draw happyface
sw=screen_width()
sh=screen_height()-100
fill color 1,1,0
fill circle sw/2,sh/2 size 200
fill color 0,0,0
fill circle sw/2-75,sh/2-75 size 50
fill circle sw/2+75,sh/2-75 size 50
fill color 1,1,1
fill circle sw/2-75,sh/2-75 size 15
fill circle sw/2+75,sh/2-75 size 15
fill color 0,0,0
fill circle sw/2,sh/2+20 size 20
draw size 25
draw color 0,0,0
draw arc sw/2,sh/2,125,3.14,0,1
'happy music
c$="46:i(c4aff3c5)(ff4a)(ca5ff4)(c7a6)(a6f)(c5c4af)"
c$=c$&"i(c4aff3c5)(ff4a)(ca5ff4)(c7a6)(a6f)(c5c4af)"
c$=c$&"i(a#gecc5)(ege4)q(a#5gc5e4)(a#5d6g4e)"
c$=c$&"i(ega#5d6)(c6a6f5)q(caf)s(c6a5)(a#g)(af)(ge)"
c$=c$&"i(c4aff3c5)(ff4a)(ca5ff4)(c7a6)(a6f)(c5c4af)"
c$=c$&"i(c4aff3c5)(ff4a)(ca5ff4)(c7a6)(a6f)(c5c4af)"
c$=c$&"i(a#gecc5)(ege4)q(a#5gc5e4)(e5ca#4gc)h(f5ca3f)"
'play song
notes set c$ ! notes play
'loop until music stops playing
do! until notes_time() => notes_length()
text
print "Thanks for playing!"
end
return
'==========
drawpuzzle:
'==========
'x is the wall, b is ball. y is the star
if puzzle =1 then
bs=int(sw/8) 'boxsize, divided by screen width
puz$="" !px=8!py=8
puz$=puz$&"xxxxxxxx"
puz$=puz$&"x xb x"
puz$=puz$&"x yx x"
puz$=puz$&"x xx x"
puz$=puz$&"x x"
puz$=puz$&"x x"
puz$=puz$&"x b x"
puz$=puz$&"xxxxxxxx"
end if
if puzzle =2 then
bs=int(sw/10) 'boxsize
puz$="" !px=10!py=10
puz$=puz$&"xxxxxxxxxx"
puz$=puz$&"xx x x"
puz$=puz$&"x xx x"
puz$=puz$&"x y x"
puz$=puz$&"x xx x"
puz$=puz$&"x b x"
puz$=puz$&"x x"
puz$=puz$&"x xx x"
puz$=puz$&"x x x"
puz$=puz$&"xxxxxxxxxx"
end if
if puzzle =3 then
bs=int(sw/11) 'boxsize
puz$="" !px=11!py=11
puz$=puz$&"xxxxxxxxxxx"
puz$=puz$&"xbx x x"
puz$=puz$&"x x x"
puz$=puz$&"xx x x"
puz$=puz$&"x y x x"
puz$=puz$&"x x x"
puz$=puz$&"x x"
puz$=puz$&"x x x x"
puz$=puz$&"x x x"
puz$=puz$&"x x xx"
puz$=puz$&"xxxxxxxxxxx"
end if
if puzzle =4 then
bs=int(sw/11) 'boxsize
puz$="" !px=11!py=11
puz$=puz$&"xxxxxxxxxxx"
puz$=puz$&"xbx x x"
puz$=puz$&"x xx x"
puz$=puz$&"x x"
puz$=puz$&"x xxx"
puz$=puz$&"x x x"
puz$=puz$&"x x xx x"
puz$=puz$&"x x"
puz$=puz$&"x xx x xxx"
puz$=puz$&"x x yx"
puz$=puz$&"xxxxxxxxxxx"
end if
if puzzle =5 then
bs=int(sw/12) 'boxsize
puz$="" !px=12!py=12
puz$=puz$&"xxxxxxxxxxxx"
puz$=puz$&"x x x x"
puz$=puz$&"x x xxx x x"
puz$=puz$&"x x"
puz$=puz$&"x x x x xx x"
puz$=puz$&"x x xbx x"
puz$=puz$&"x xxxxx xx"
puz$=puz$&"x xyx x"
puz$=puz$&"xx x"
puz$=puz$&"x xx"
puz$=puz$&"x x x x"
puz$=puz$&"xxxxxxxxxxxx"
end if
if puzzle =6 then
bs=int(sw/13) 'boxsize
puz$="" !px=13!py=13
puz$=puz$&"xxxxxxxxxxxxx"
puz$=puz$&"x x x"
puz$=puz$&"x xxx xxx"
puz$=puz$&"x x"
puz$=puz$&"xxx xxx x x"
puz$=puz$&"x xyx"
puz$=puz$&"xb x xxx"
puz$=puz$&"x x x x"
puz$=puz$&"xxx xx x"
puz$=puz$&"x x"
puz$=puz$&"x x x x x"
puz$=puz$&"x x x x x"
puz$=puz$&"xxxxxxxxxxxxx"
end if
if puzzle =7 then
bs=int(sw/15) 'boxsize
puz$="" !px=15!py=15
puz$=puz$&"xxxxxxxxxxxxxxx"
puz$=puz$&"xbx x x x"
puz$=puz$&"x xx x"
puz$=puz$&"x x x"
puz$=puz$&"xx xx x"
puz$=puz$&"x x"
puz$=puz$&"x xx xx x"
puz$=puz$&"x x x x"
puz$=puz$&"xx x"
puz$=puz$&"x x x"
puz$=puz$&"x xx xx"
puz$=puz$&"x x x"
puz$=puz$&"x xxx x"
puz$=puz$&"x x xyx"
puz$=puz$&"xxxxxxxxxxxxxxx"
end if
if puzzle =8 then
bs=int(sw/15) 'boxsize
puz$="" !px=15!py=15
puz$=puz$&"xxxxxxxxxxxxxxx"
puz$=puz$&"x x x x"
puz$=puz$&"x x xx"
puz$=puz$&"x b x"
puz$=puz$&"x x x x"
puz$=puz$&"x x x"
puz$=puz$&"x x x x"
puz$=puz$&"x xx xx"
puz$=puz$&"x x"
puz$=puz$&"xx x x"
puz$=puz$&"x x x x"
puz$=puz$&"x xyx x"
puz$=puz$&"x xxx x"
puz$=puz$&"x x x x"
puz$=puz$&"xxxxxxxxxxxxxxx"
end if
if puzzle =9 then
bs=int(sw/19) 'boxsize
puz$="" !px=19!py=19
puz$=puz$&"xxxxxxxxxxxxxxxxxxx"
puz$=puz$&"x x x x x"
puz$=puz$&"x x xxx x x xxx"
puz$=puz$&"x x x"
puz$=puz$&"x xxx xxxxx xxx x x"
puz$=puz$&"x x x x x"
puz$=puz$&"xxx x x x x x"
puz$=puz$&"x x x"
puz$=puz$&"x xxx x xxx xxx x"
puz$=puz$&"x x x x"
puz$=puz$&"xxx x xxx x x"
puz$=puz$&"x x x x"
puz$=puz$&"x x x x xxx xxx"
puz$=puz$&"x x x x"
puz$=puz$&"x x x xxx x x x"
puz$=puz$&"x x x x"
puz$=puz$&"x xxx x x xxx x"
puz$=puz$&"x bx x yx x"
puz$=puz$&"xxxxxxxxxxxxxxxxxxx"
end if
if puzzle =10 then
bs=int(sw/21) 'boxsize
puz$="" !px=21!py=21
puz$=puz$&"xxxxxxxxxxxxxxxxxxxxx"
puz$=puz$&"xbx x x x x"
puz$=puz$&"x x x x xxx x"
puz$=puz$&"x x x"
puz$=puz$&"x x xxx x x x x"
puz$=puz$&"x x x x x"
puz$=puz$&"x x x x x xxx"
puz$=puz$&"x x x"
puz$=puz$&"x x x xxx x x"
puz$=puz$&"x x x x"
puz$=puz$&"xxx xxx xxxxx xxx xxx"
puz$=puz$&"x x x"
puz$=puz$&"x xxx x x xxx x x"
puz$=puz$&"x x x x"
puz$=puz$&"xxx xxx x xxx x x"
puz$=puz$&"x x x x x x"
puz$=puz$&"x x x xxx x x x x x"
puz$=puz$&"x x x x"
puz$=puz$&"x x x x x x x x"
puz$=puz$&"x x x x xyx"
puz$=puz$&"xxxxxxxxxxxxxxxxxxxxx"
end if
refresh off
shadow on
sprites delete
'draw ball
fill color .2,.2,.2
fill rect 0,0 to bs-1,bs-1
draw color 0,0,1
draw font size bs-10
draw text chr$(9898) at 6,12
sprite "b" scan 0,0,bs-1,bs-1
'draw star
draw color 1,1,0
fill color .5,.5,0
fill rect 0,0 to bs-1,bs-1
draw text chr$(9733) at 5,10
sprite "y" scan 0,0,bs-1,bs-1
graphics clear .2,.2,.2
refresh on
'generate and draw board
fill color .2,.2,.2
draw font size bs
dim pdata$(px,py)
m=1
for x=0 to px-1
for y=0 to py-1
a$=mid$(puz$,m,1)
pdata$(x+1,y+1)= a$
if a$="x" then
draw text chr$(11035) at y*bs,x*bs+8
end if
if a$="b" then sprite "b" at y*bs,x*bs
if a$="y" then sprite "y" at y*bs,x*bs
m=m+1
next y
next x
'turn on sprites
sprite "b" show
sprite "y" show
'show instructions on first puzzle
if puzzle=1 then
draw color 1,1,0
draw font size 32
draw text "Swipe finger Left, right, up, down." at 40,sh-200
draw text "Move the ball and reach the star mark." at 40,sh-150
end if
'draw current level, restart button
draw color .5,.5,.5
draw font size 56
draw text "Level "&str$(puzzle)&" of "&puzzlemax at 20,sh-80
set buttons custom
set buttons font size 56
button "restart" text "Restart" at 550,sh-100
'=== update config file
file "mazeball.dat" delete
file "mazeball.dat" write puzzle
return
def blocked()
notes set "112:tc8"
notes play
end def