remstart
   ==============================================================
   =  Title  : Simon Says
   =  Author : Latch
   =  Date   : 20 May 2008
   =  Update :
   =  Version: .01
   ==============================================================
   Comments    Repeat the pattern of lights the computer indicates
   ==============================================================
remend
 
rem =============================================================
rem = SET UP DISPLAY
rem =============================================================
   autocam off
   set display mode 800,600,32
   sync on
   sync rate 60
   randomize timer()
 
rem =============================================================
rem = MAIN
rem =============================================================
_main:
   gosub _init
   count=0
   do
 
      gosub _play_pattern
      contact(pointer)
      sync
   loop
 
   end
 
rem =============================================================
rem = SUBROUTINES - PROCEDURES
rem =============================================================
   _init:
      rem create colored lights
      off=1
      green=2
      red=3
      blue=4
      yellow=5
      pointer=6
      radius=63
      cx=64
      cy=64
 
 
      create bitmap 1,300,300
      cls 0
      rem off
      radial_shade(off,radius,cx,cy,70,70,70,0)
      cls 0
      rem green
      radial_shade(green,radius,cx,cy,0,255,0,10)
      cls 0
      rem red
      radial_shade(red,radius,cx,cy,255,20,20,10)
      cls 0
      rem blue
      radial_shade(blue,radius,cx,cy,0,100,255,10)
      cls 0
      rem yellow
      radial_shade(yellow,radius,cx,cy,255,255,0,10)
      cls 0
      rem pointer contact
      ink rgb(255,255,255),0
      dot 0,0
      get image pointer,0,0,1,1
      sync
      delete bitmap 1
 
      rem load light positions into an array
      dim pos(5,1)
      for lt=2 to 5
         for coord=0 to 1
            read pos(lt,coord)
         next coord
      next lt
 
      rem create array to hold sequence of lights
      dim seq(200)
      gosub _select_pattern
 
      cls RGB(128,128,192)
 
      rem display off lights
      sprite 1,pos(2,0),pos(2,1),off
      sprite 2,pos(3,0),pos(3,1),off
      sprite 3,pos(4,0),pos(4,1),off
      sprite 4,pos(5,0),pos(5,1),off
   return
`----------------------------------------------------------------
   _spin_lights:
      for lt=2 to 5
         sprite lt-1,pos(lt,0),pos(lt,1),lt
         wait 100
         sprite lt-1,pos(lt,0),pos(lt,1),off
         wait 100
      next lt
   return
`----------------------------------------------------------------
   _select_pattern:
      for pattern=0 to 200
         value=rnd(3)+2
         seq(pattern)=value
      next pattern
   return
`----------------------------------------------------------------
   _play_pattern:
      rem wait for enter key to start pattern
      if count > -1
         sel=-1
         cls
         text 0,0,"Watch the order of the lighted orbs carefully."
         text 0,20,"When the computer is done try and match the order"
         text 0,40,"exactly by clicking on the orbs."
         text 0,60,"Press ENTER to let the computer begin"
         text 0,80,"LEVEL :  "+str$(count)
 
         if returnkey()=1
            repeat
               sync
            until returnkey()=0
            rem run through pattern up to count
            for pattern=0 to count
               sprite seq(pattern)-1,pos(seq(pattern),0),pos(seq(pattern),1),seq(pattern)
               wait 200
               sprite seq(pattern)-1,pos(seq(pattern),0),pos(seq(pattern),1),off
               wait 100
            next pattern
 
            wait 100
            cls
            text 0,0,"Now It's your turn."
            text 0,20,"Click on the orbs in the exact"
            text 0,40,"order the computer did."
            text 0,80,"LEVEL :  "+str$(count)
            sync
 
            rem check for the orb clicked on
            while returnkey()=0 and sel < count
               bang=contact(pointer)
               rem light up the orb
               if mouseclick()=1 and bang > 0
                  repeat
                     sprite bang,pos(bang+1,0),pos(bang+1,1),bang+1
                     sync
                  until mouseclick()=0
                  sprite bang,pos(bang+1,0),pos(bang+1,1),off
                  rem check if the orb selected matches the sequence
                  inc sel
                  if bang+1 <> seq(sel)
                     cls 0
                     text 0,0,"YOU LOSE!"
                     text 0,20,"You make it to level "+str$(count)
                     text 0,60,"PLAY AGAIN? (Y/N)"
                     repeat
                        sync
                     until scancode()<>0
                     if inkey$()="y"
                        cls RGB(128,128,192)
                        count=0
                        gosub _select_pattern
                        return
                     else
                        end
                     endif
                  endif
               endif
               sync
            endwhile
            inc count
         endif
      endif
   return
`----------------------------------------------------------------
 
rem =============================================================
rem = FUNCTIONS
rem =============================================================
   function radial_shade(img,radius,cx,cy,rclr,gclr,bclr,shade)
      divr#=(1.0*rclr)/(radius+shade)*1.0
      divg#=(1.0*gclr)/(radius+shade)*1.0
      divb#=(1.0*bclr)/(radius+shade)*1.0
 
      for r=0 to radius-1
         c=rgb(rclr-(r*divr#),gclr-(r*divg#),bclr-(r*divb#))
         ink c,0
         circle cx,cy,r
         circle cx,cy-1,r
      next r
 
      x1=cx-radius
      y1=cy-radius
      x2=x1+(radius*2)+1
      y2=y1+(radius*2)+1
      get image img,x1,y1,x2,y2
      sync
   endfunction
`----------------------------------------------------------------
   function contact(pointer)
      sprite pointer,mousex(),mousey(),pointer
      result=sprite collision(pointer,0)
   endfunction result
rem =============================================================
rem = DATA STATEMENTS
rem =============================================================
   _light_positions:
      data 234,164
      data 410,164
      data 234,340
      data 410,340