This is for a new puzzle game where you navigate a box through a maze. You swipe your finger up/down/left/right to move the box on the screen. The red box will stop it the blue box from moving (hitting a wall).
it works most of the time, but sometimes when swiping , it will mysteriously go the wrong way. I must not be getting x,y touch values properly. any Help will be most welcomed.
- Dav
Code: Select all
'move blue box by swiping finger up/down/left/right.
'red box will stop blue box (wall) and you have to
'navigate around it.
Code by Dav, JAN/2017
graphics
get screen size sw,sh
refresh off
'braw blue box
fill color 0,0,1
fill rect 0,0 to 50,50
sprite "s" scan 0,0,50,50
sprite "s" show
sprite "s" at 300,300
'draw red box
fill color 1,0,0
fill rect 0,0 to 50,200
sprite "r" scan 0,0,50,200
sprite "r" show
sprite "r" at 400,0
graphics clear 0,0,0
refresh on
draw text "move box by swiping finger " at 50,50
draw text "navigate around rex box"   at 50,100
SwipeDistance= sw/4 'how far to swipe
top:
'wait for no fingers down
while touch_x(0)>-1 ! end while
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 
        'poll x & y locations
        movx=touch_x(0) ! newx= movx-tx
        movy=touch_y(0) ! newy= movy-ty
        'move sprite right
        if newx >SwipeDistance then 
           get sprite "s" pos sx,sy
           for x=sx to sw-50
              'if not hotting red box
              if not sprites_collide("s","r") then
                 sprite "s" at x,sy
                 pause .0001
              else 
                 sprite "s" at x-2,sy
                goto top
              end if
           next x
           goto top
        end if
        'left
        if newx <-SwipeDistance then 
           get sprite "s" pos sx,sy
           for x=sx to 0 step -1
              if not sprites_collide("s","r") then
                 sprite "s" at x,sy
                 pause  .0001
              else
                 sprite "s" at x+2,sy
                 goto top
              end if
           next x
           goto top
        end if
        'down
        if newy >SwipeDistance then 
           get sprite "s" pos sx,sy
           for y=sy to sh-50
              if not sprites_collide("s","r") then
                 sprite "s" at sx,y
                 pause .0001
              else
                 sprite "s" at sx,y-2
                 goto top
              end if
           next y
           goto top
        end if
        'up
        if newy <-SwipeDistance then 
           get sprite "s" pos sx,sy
           for y=sy to 0 step -1
              if not sprites_collide("s","r") then
                 sprite "s" at sx,y
                 pause .0001
              else
                 sprite "s" at sx,y+2
                 goto top
              end if
           next y
           goto top
        end if
      end while
  end if
until 0
end


