home *** CD-ROM | disk | FTP | other *** search
/ Amoszine 4 / Amoszine 4 (Disk 1 of 3).adf / articles_source.LHA / articles_source / walk_around_maze.AMOS / walk_around_maze.amosSourceCode < prev   
Encoding:
AMOS Source Code  |  1992-02-26  |  6.7 KB  |  165 lines

  1. '****************************************************************************
  2. '           Simple ~Walk Around The Maze~ Routine By Steve Bennett   
  3. '                      From an idea by Jason Holborn           
  4. '****************************************************************************
  5. '
  6. ' If you are new to AMOS, you may not have fully understood the routine
  7. ' that Jason explained in  ~Amiga Shopper~.    
  8. ' Below is a small ~Bare Bones~ routine to give you some idea what he meant. 
  9. ' I have kept it as simple as I can. It is up to you to change the code as 
  10. ' you wish. The first thing to do is to add a few lines of code so that the
  11. ' Pacman Bob doesn't move 16 pixels at a time. 
  12. ' Take your time, you can do it. 
  13. '
  14. ' Remove the ~Rems~ and see how small the code really is!
  15. '****************************************************************************
  16. '  
  17. ' I have just written this code and have found that by drawing the maze in 
  18. ' the way I have (Left To Right) means that when you want to check a square
  19. ' on the grid, instead of checking - 
  20. ' X Right    Then    Y Down      
  21. '
  22. ' EXAMPLE: CHECK_VALID_MOVE(X,Y)     
  23. '
  24. ' You must do it the other way around -  
  25. ' Y Down     Then    X Right 
  26. '
  27. ' EXAMPLE: CHECK_VALID_MOVE(Y,X) 
  28. '
  29. ' Its not my mistake, I wrote the code just to draw a maze, Jason saw the
  30. ' true potential of this routine and this method of moving around a maze.  
  31. '
  32. ' It should be no real problem for you to change the code so that the icons  
  33. ' are pasted from (Top To Bottom) it you want, then the check will be the    
  34. ' correct way around!
  35. '
  36. '****************************************************************************
  37.  
  38. PACMANX=2 : Rem              * used to store the pacmans X position on grid *  
  39. PACMANY=2 : Rem              * used to store the pacmans Y position on grid *    
  40.  
  41. Dim CHECK_VALID_MOVE(14,18) : Rem * stores the value of each grid square    *  
  42.  
  43. Hide On : Rem                     * hide the mouse                          *    
  44.  
  45. Screen Open 0,320,256,32,Lowres
  46. Get Icon Palette 
  47. Flash Off : Curs Off 
  48. Cls 0
  49.  
  50. CREATE_MAZE : Rem                  * go and create a maze                   *  
  51.  
  52. Double Buffer : Rem                * use Double Buffer to stop Bob flicker  *    
  53.  
  54. Bob 1,31,35,1 : Rem                * place the pacman Bob on the screen     *  
  55.  
  56. Repeat : Rem                       * start of the main game loop            * 
  57.    
  58.    CHECK_STICK : Rem               * check if the joystick is being moved   *   
  59.    
  60.    Wait 5 : Rem                    * slow the bob movement down a bit       *  
  61.    
  62. Until Mouse Key=1 : Rem     * REPEAT - UNTIL we click the left mouse button *
  63.  
  64. Procedure CHECK_STICK
  65.    
  66.    '****************************************************************************
  67.    ' This bit may look hard, but all it does is test which way the joystick is
  68.    ' held then adds or subracts 1 To/From the values of the Bobs Grid Position -
  69.    ' These are held in the PACMANX & PACMANY variables. 
  70.    '
  71.    ' PACMANX - holds the Bobs X position on the grid. 
  72.    ' PACMANY - holds the Bobs Y position on the grid. 
  73.    '
  74.    ' It then checks if the Grid Square in front of the Bob (This depends which
  75.    ' way the Bob is moving). If the value of that Square is 2 then that means 
  76.    ' the next Grid Square is a wall so we stop the Bob moving onto it.  
  77.    '
  78.    ' If the next Grid Square is not a wall, then we move the Bob onto it. 
  79.    '
  80.    ' READ THE MAZE_CRAZY DOCS FILE ON THE DISK AND I'LL TRY TO EXPLAIN IT A 
  81.    ' BIT BETTER FOR YOU.
  82.    '****************************************************************************
  83.    
  84.    Shared CHECK_VALID_MOVE(),PACMANX,PACMANY
  85.    
  86.    J=Joy(1) : Rem               * test which direction the joystick is held *  
  87.    
  88.    If J=1 : Rem                                                 * is it up? *
  89.       If CHECK_VALID_MOVE(PACMANY-1,PACMANX)<>2
  90.          Dec PACMANY
  91.          Bob 1,,Y Bob(1)-16,12 : Rem         * move the Bob down the screen * 
  92.       End If 
  93.    End If 
  94.    
  95.    If J=2 : Rem                                                * is it down *  
  96.       If CHECK_VALID_MOVE(PACMANY+1,PACMANX)<>2
  97.          Inc PACMANY
  98.          Bob 1,,Y Bob(1)+16,13 : Rem         * move the Bob up the screen   * 
  99.       End If 
  100.    End If 
  101.    
  102.    If J=4 : Rem                                                * is it left *  
  103.       If CHECK_VALID_MOVE(PACMANY,PACMANX-1)<>2
  104.          Dec PACMANX
  105.          Bob 1,X Bob(1)-16,,8 : Rem          * move the Bob left            *    
  106.       End If 
  107.    End If 
  108.    
  109.    If J=8 : Rem                                               * is it right *
  110.       If CHECK_VALID_MOVE(PACMANY,PACMANX+1)<>2
  111.          Inc PACMANX
  112.          Bob 1,X Bob(1)+16,,1 : Rem          * move the Bob right           *    
  113.       End If 
  114.    End If 
  115.    
  116.    '****************************************************************************
  117.    ' You could put your ~Eat Pills~ routine here if you wanted to.
  118.    ' It would best to do this when you move the Bob though, to avoid clearing 
  119.    ' the same area over & over, as the code here does.
  120.    ' These next few lines just use the Cls just to so you the sort of effect. 
  121.    '****************************************************************************
  122.    
  123.    X=X Bob(1) : Y=Y Bob(1)
  124.    Cls 0,X,Y To X+16,Y+16
  125.    
  126. End Proc
  127. Procedure CREATE_MAZE
  128.    
  129.    Shared CHECK_VALID_MOVE()
  130.    
  131.    STORE_DATA=1
  132.    
  133.    Y=20 : Rem          * ~Y~ start position of the first icon to paste down *        
  134.    
  135.    For T=1 To 14 : Rem           * loop to paste the icon across the screen *   
  136.       For X=15 To 294 Step 16 : Rem * how many pixels apart to paste the icons * 
  137.          Read I : Rem                            * read the next data value *  
  138.          CHECK_VALID_MOVE(T,STORE_DATA)=I
  139.          If I<>0 Then Paste Icon X,Y,I : Rem     * paste down icon ~I~      * 
  140.          Inc STORE_DATA
  141.       Next X
  142.       Add Y,16 : Rem * after line is complete across - drop down to the next line * 
  143.       STORE_DATA=1
  144.    Next T
  145.    
  146.    '****************************************************************************
  147.    '       Data for the Maze itself - 2=Wall - 3=Pill - 0=Empty space   
  148.    '****************************************************************************
  149.    
  150.    Data 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2
  151.    Data 2,0,3,3,3,3,3,3,3,3,3,3,3,3,0,0,0,2
  152.    Data 2,2,3,2,3,2,3,2,3,2,3,2,2,3,2,0,0,2
  153.    Data 2,2,3,2,3,2,3,2,3,2,3,2,2,3,2,2,2,2
  154.    Data 2,3,3,3,3,3,3,3,3,2,3,3,3,3,3,3,3,2
  155.    Data 2,2,2,3,2,2,2,2,3,2,3,2,2,2,2,2,3,2
  156.    Data 2,3,3,3,3,3,3,3,3,2,3,3,3,3,2,2,3,2
  157.    Data 2,2,3,2,3,2,2,3,2,2,2,2,2,3,3,3,3,2
  158.    Data 2,3,3,3,3,2,2,3,3,3,3,3,2,3,2,2,3,2
  159.    Data 2,2,3,2,3,2,2,3,2,2,2,3,2,3,3,3,3,2
  160.    Data 2,3,3,2,3,3,3,3,2,3,2,3,3,3,2,3,2,2
  161.    Data 2,3,2,2,3,2,2,3,2,3,2,3,2,3,2,2,3,2
  162.    Data 2,3,3,2,3,2,2,3,3,3,2,3,2,3,3,3,3,2
  163.    Data 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2
  164.    
  165. End Proc