Maze+Ball game v1.0 (iPad only)

Post Reply
User avatar
Dav
Posts: 279
Joined: Tue Dec 30, 2014 5:12 pm
My devices: iPad Mini, iPod Touch.
Location: North Carolina, USA
Contact:

Maze+Ball game v1.0 (iPad only)

Post by Dav »

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. :D

- 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

Last edited by Dav on Sun Jan 08, 2017 7:57 pm, edited 1 time in total.

Joel
Posts: 57
Joined: Fri Jan 15, 2016 1:36 pm
My devices: miniipad
Flag: Germany

Re: Maze+Ball game v1.0 (iPad only)

Post by Joel »

what a great little game!!! Tough, but I eventually made it. Thanks a lot for this valuable contribution...
nice tune at the end btw, hehehe
joel
N.B. the only emoji I saw was that "happyface" at the very end...
Last edited by Joel on Sun Jan 08, 2017 1:41 am, edited 1 time in total.

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: Maze+Ball game v1.0 (iPad only)

Post by rbytes »

I may never hear that tune. Will one of you please hum it for me?

Fun game, but I am not going to be a champion player! ;)
The only thing that gets me down is gravity...

User avatar
sarossell
Posts: 195
Joined: Sat Nov 05, 2016 6:31 pm
My devices: iPad Mini 2, iPhone 5, MacBook Air, MacBook Pro
Flag: United States of America
Contact:

Re: Maze+Ball game v1.0 (iPad only)

Post by sarossell »

Ha! That was a blast! A whole game with such a relatively small amount of code. Well done. :D
smart BASIC Rocks!

- Scott : San Diego, California

User avatar
Dav
Posts: 279
Joined: Tue Dec 30, 2014 5:12 pm
My devices: iPad Mini, iPod Touch.
Location: North Carolina, USA
Contact:

Re: Maze+Ball game v1.0 (iPad only)

Post by Dav »

Thanks for the comments everyone, glad you like the game. Here are solutions to the levels in case you need them. I also updated to code with them.

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

- Dav

Operator
Posts: 138
Joined: Mon May 06, 2013 5:52 am

Re: Maze+Ball game v1.0 (iPad only)

Post by Operator »

Very nice game :) got stuck in level 9...
Had some difficulties at first, since all the more than one
blank spaces of the maze got merged/lost in the copy and paste
process of the code... (iPhone4 / iOS6.1)
resulting in a debug screen [..] a$=MID$(puz$,m,1) due of
the missing chars...

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: Maze+Ball game v1.0 (iPad only)

Post by rbytes »

I got to level 8 with some help from your cheat sheet. But after memorizing various cheat lines, I can not get these song lyrics out of my head:

LURULULDLDRDRURULURDLDR

:)
The only thing that gets me down is gravity...

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Maze+Ball game v1.1 (all devices)

Post by rbytes »

Dav, MazeBall really is a great game. I have tweaked It to work on all all iOS devices.

Code: Select all

'mazeball.txt v1.1 (all devices)
'
'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
'All-devices by rbytes, 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

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
rw=sw/768   ' calculate ratio of screen width to iPad screen width
rh=sh/980    ' calculate ratio of screen height to iPad screen height
' these ratios are used as multipliers to resize the game graphics

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*rw)/(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*rw
DRAW COLOR 1,1,0
DRAW TEXT "YOU DID IT!" AT 200*rw,125*rh
DRAW TEXT "Congratulations!" AT 125*rw,700*rh

'draw happyface
sw=SCREEN_WIDTH()
sh=SCREEN_HEIGHT()-100*rh
FILL COLOR 1,1,0
FILL CIRCLE sw/2,sh/2 SIZE 200*rw
FILL COLOR 0,0,0
FILL CIRCLE sw/2-75*rw,sh/2-75*rh SIZE 50*rw
FILL CIRCLE sw/2+75*rw,sh/2-75*rh SIZE 50*rw
FILL COLOR 1,1,1
FILL CIRCLE sw/2-75*rw,sh/2-75*rh SIZE 15*rw
FILL CIRCLE sw/2+75*rw,sh/2-75*rh SIZE 15*rw
FILL COLOR 0,0,0
FILL CIRCLE sw/2,sh/2+20*rh SIZE 20*rw
DRAW SIZE 25*rw
DRAW COLOR 0,0,0
DRAW ARC sw/2,sh/2,125*rw,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*rw,12*rh
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*rw,10*rh
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
if rw<1 then adj2=5
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+adj2
     IF a$="y" THEN SPRITE "y" AT y*bs,x*bs+adj2
     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*rw
  DRAW TEXT "Swipe finger Left, right, up, down." AT 40*rw,sh-200*rh
  DRAW TEXT "Move the ball and reach the star mark." AT 40*rw,sh-150*rh
END IF

'draw current level, restart button
if re<1 then adj=10
DRAW COLOR .5,.5,.5
DRAW FONT SIZE 56*rw
DRAW TEXT "Level "&STR$(puzzle)&" of "&puzzlemax AT 20*rw,sh-80*rh
SET BUTTONS CUSTOM
SET BUTTONS FONT SIZE 56*rw
BUTTON "restart" TEXT "Restart" AT 550*rw-adj,sh-100*rh

'=== update config file
FILE "mazeball.dat" DELETE
FILE "mazeball.dat" WRITE puzzle

RETURN

DEF blocked()
     NOTES SET "112:tc8"
     NOTES PLAY
END DEF
The only thing that gets me down is gravity...

User avatar
Dav
Posts: 279
Joined: Tue Dec 30, 2014 5:12 pm
My devices: iPad Mini, iPod Touch.
Location: North Carolina, USA
Contact:

Re: Maze+Ball game v1.0 (iPad only)

Post by Dav »

Thanks rbytes! I tried to make it all device compatible last night, but just couldn't get the happy face to display correctly. Thanks for your update!

- Dav

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: Maze+Ball game v1.0 (iPad only)

Post by rbytes »

I haven't seen the happy face yet, but I'm pleased to hear that it displays ok.

Keep the great games coming!

R.
The only thing that gets me down is gravity...

Post Reply