home *** CD-ROM | disk | FTP | other *** search
/ AMOS PD CD / amospdcd.iso / sourcecode / demos / sonicscramble.amos / sonicscramble.amosSourceCode
AMOS Source Code  |  1978-01-13  |  17KB  |  614 lines

  1. Screen Open 0,640,256,16,Hires
  2. Flash Off 
  3. Load Iff "Sonic-Screen",1
  4. '
  5. '                       First Reserve some Zones for Buttons & Pad 
  6. Reserve Zone 10
  7. Dim NTS(8),SND(4),SZONE(4),SEQ(20)
  8. '
  9. '                       Here are the Pad Zones 
  10. '
  11. Set Zone 1,88,43 To 188,93
  12. Set Zone 2,210,43 To 310,93
  13. Set Zone 3,88,105 To 188,155
  14. Set Zone 4,210,105 To 310,155
  15. '
  16. '                       Here are the Button Zones
  17. '
  18. Set Zone 5,460,91 To 620,103
  19. Set Zone 6,460,105 To 620,117
  20. Set Zone 7,460,119 To 620,131
  21. Set Zone 8,460,133 To 620,145
  22. Set Zone 9,460,147 To 620,159
  23. Set Zone 10,460,161 To 620,173
  24. '
  25. '                       Now we create our 8 possible Notes 
  26. For I=1 To 8
  27.    Read NTS(I)
  28. Next I
  29. Data 1,13,25,37,49,61,73,85
  30. '
  31. '                       Lets setup our menus 
  32. MAKEMENU
  33. On Menu Proc MENU1
  34. '                       GAME2 is made our default game 
  35. Gosub GAME2
  36. '                       Set two areas for our scores 
  37. Paper 3
  38. Pen 12
  39. Locate 10,27
  40. Print "CORRECT"
  41. Pen 6
  42. Locate 34,27
  43. Print " WRONG "
  44. '
  45. '                       We Wait for a Mouse Click in a Button Zone 
  46. Z=0
  47. While(Z=0)
  48.    MKEY=0
  49.    While(MKEY=0)
  50.       MKEY=Mouse Key
  51.       On Menu On 
  52.    Wend 
  53.    If MKEY=1 Then Z=Mouse Zone
  54.    '
  55.    '                    Check if Zone is a Button 
  56.    If Z>4
  57.       '                 Animate the Selected Button  
  58.       Z=Z+1
  59.       Ink 2
  60.       Draw 461,Z*14+18 To 461,Z*14+7
  61.       Polyline 460,Z*14+18 To 460,Z*14+7 To 618,Z*14+7
  62.       Ink 1
  63.       Draw 619,Z*14+8 To 619,Z*14+19
  64.       Polyline 620,Z*14+8 To 620,Z*14+19 To 462,Z*14+19
  65.       For I=1 To 5
  66.          Bell I
  67.       Next I
  68.       '                 Wait for Mouse Button to be released 
  69.       While Mouse Key<>0
  70.          MKEY=Mouse Key
  71.       Wend 
  72.       '                 Then redraw original Button
  73.       Ink 1
  74.       Draw 461,Z*14+18 To 461,Z*14+7
  75.       Polyline 460,Z*14+18 To 460,Z*14+7 To 618,Z*14+7
  76.       Ink 2
  77.       Draw 619,Z*14+8 To 619,Z*14+19
  78.       Polyline 620,Z*14+8 To 620,Z*14+19 To 462,Z*14+19
  79.       '
  80.       '                 Now we Do something based on that Button 
  81.       '
  82.       On(Z-5) Gosub GAME1,GAME2,GAME3,GAME,TRYOUT,QUIT
  83.    End If 
  84.    Z=0
  85. Wend 
  86. '
  87. '
  88. GAME:
  89. '                       Clear out any old Scores 
  90. WON=0
  91. LOST=0
  92. Pen 0
  93. Locate 10,28
  94. Print "       "
  95. Locate 34,28
  96. Print "       "
  97. Wait 100
  98. '                       Create Sequence  
  99. SEQUENCE=BEGIN_NOTES
  100. SPEED=BEGIN_TIME
  101. Do 
  102.    '                    Do we need to Speed up the game?
  103.    '
  104.    If SEQUENCE>MOST_NOTES
  105.       If SPEED_UP<>0
  106.          SPEED=SPEED-SPEED_UP
  107.       Else 
  108.          SEQUENCE=MOST_NOTES
  109.       End If 
  110.    End If 
  111.    '
  112.    For J=1 To ROUND_SIZE
  113.       '                 Clear old sequence 
  114.       '
  115.       For I=1 To SEQUENCE
  116.          SEQ(I)=0
  117.       Next I
  118.       '                 Get a new random sequence
  119.       '
  120.       For I=1 To SEQUENCE
  121.          S=Rnd(3)+1
  122.          SEQ(I)=SND(S)
  123.       Next I
  124.       '
  125.       If LIGHT_UP=1
  126.          '              Play Sequence and Lightup Pad 
  127.          '
  128.          For I=1 To SEQUENCE
  129.             If SEQ(I)=SND(1)
  130.                OLDCOL=Colour(5)
  131.                Colour 5,$F00
  132.             End If 
  133.             If SEQ(I)=SND(2)
  134.                OLDCOL=Colour(8)
  135.                Colour 8,$FF0
  136.             End If 
  137.             If SEQ(I)=SND(3)
  138.                OLDCOL=Colour(11)
  139.                Colour 11,$F0
  140.             End If 
  141.             If SEQ(I)=SND(4)
  142.                OLDCOL=Colour(14)
  143.                Colour 14,$F
  144.             End If 
  145.             Play 3,SEQ(I),SPEED
  146.             If SEQ(I)=SND(1)
  147.                Colour 5,OLDCOL
  148.             End If 
  149.             If SEQ(I)=SND(2)
  150.                Colour 8,OLDCOL
  151.             End If 
  152.             If SEQ(I)=SND(3)
  153.                Colour 11,OLDCOL
  154.             End If 
  155.             If SEQ(I)=SND(4)
  156.                Colour 14,OLDCOL
  157.             End If 
  158.          Next I
  159.       Else 
  160.          '              Or Play Sequence Only 
  161.          Volume ,63
  162.          For I=1 To SEQUENCE
  163.             Play 3,SEQ(I),SPEED
  164.          Next I
  165.       End If 
  166.       '
  167.       '
  168.       '                 Use Pad to Guess each Note   
  169.       NOGOOD=0
  170.       For I=1 To SEQUENCE
  171.          '              
  172.          '              Wait for Mouse Click in Zone
  173.          MZONE=0
  174.          MKEY=0
  175.          While(MZONE=0) or(MKEY<>1)
  176.             MKEY=Mouse Key
  177.             If MKEY=1
  178.                MZONE=Mouse Zone
  179.             End If 
  180.          Wend 
  181.          If MZONE=10
  182.             '           You've Pushed The QUIT Button    
  183.             Z=11
  184.             Ink 2
  185.             Draw 461,Z*14+18 To 461,Z*14+7
  186.             Polyline 460,Z*14+18 To 460,Z*14+7 To 618,Z*14+7
  187.             Ink 1
  188.             Draw 619,Z*14+8 To 619,Z*14+19
  189.             Polyline 620,Z*14+8 To 620,Z*14+19 To 462,Z*14+19
  190.             For I=1 To 5
  191.                Bell I
  192.             Next I
  193.             While Mouse Key<>0
  194.                MKEY=Mouse Key
  195.             Wend 
  196.             Ink 1
  197.             Draw 461,Z*14+18 To 461,Z*14+7
  198.             Polyline 460,Z*14+18 To 460,Z*14+7 To 618,Z*14+7
  199.             Ink 2
  200.             Draw 619,Z*14+8 To 619,Z*14+19
  201.             Polyline 620,Z*14+8 To 620,Z*14+19 To 462,Z*14+19
  202.             '
  203.             '           Let's Exit the For-Next Loop nicely  
  204.             I=SEQUENCE
  205.             Goto LEAVE1
  206.          End If 
  207.          '              You've Clicked in a Pad Zone  
  208.          '              Let's Light it up and Play it 
  209.          If MZONE=1
  210.             OLDCOL=Colour(5)
  211.             Colour 5,$F00
  212.          End If 
  213.          If MZONE=2
  214.             OLDCOL=Colour(8)
  215.             Colour 8,$FF0
  216.          End If 
  217.          If MZONE=3
  218.             OLDCOL=Colour(11)
  219.             Colour 11,$F0
  220.          End If 
  221.          If MZONE=4
  222.             OLDCOL=Colour(14)
  223.             Colour 14,$F
  224.          End If 
  225.          Play 3,SND(SZONE(MZONE)),20
  226.          If MZONE=1
  227.             Colour 5,OLDCOL
  228.          End If 
  229.          If MZONE=2
  230.             Colour 8,OLDCOL
  231.          End If 
  232.          If MZONE=3
  233.             Colour 11,OLDCOL
  234.          End If 
  235.          If MZONE=4
  236.             Colour 14,OLDCOL
  237.          End If 
  238.          '              But was it the Wrong Note?
  239.          '
  240.          If SEQ(I)<>SND(SZONE(MZONE))
  241.             NOGOOD=1
  242.          End If 
  243.          '              Go back for the next Note?    
  244.          LEAVE1:
  245.       Next I
  246.       '
  247.       '                 If you pressed Quit earlier we will
  248.       '                 continue leaving the For-Next Loop nicely
  249.       If MZONE=10
  250.          J=ROUND_SIZE
  251.          Goto LEAVE2
  252.       End If 
  253.       '                 Or we will Add one to the Correct Score  
  254.       If NOGOOD=0
  255.          Inc WON
  256.          Pen 12
  257.          S$=Str$(WON)
  258.          Locate 14-(Len(S$)-1),28
  259.          Print WON
  260.          Locate 22,27
  261.          Print "CORRECT"
  262.       Else 
  263.          '              Or we will Add one to the Wrong Score 
  264.          Inc LOST
  265.          Pen 6
  266.          S$=Str$(LOST)
  267.          Locate 38-(Len(S$)-1),28
  268.          Print LOST
  269.          Locate 22,27
  270.          Print " WRONG "
  271.       End If 
  272.       '
  273.       Wait 50
  274.       Locate 21,27
  275.       Print "         "
  276.       '                 Clear out any stored mouse clicks
  277.       LEAVE2:
  278.       While MKEY=1
  279.          MKEY=Mouse Key
  280.       Wend 
  281.    '                    Go back for another sequence? 
  282.    Next J
  283.    '                    If QUIT was pressed earlier we will 
  284.    '                    now Exit the Do-Loop Loop   
  285.    If MZONE=10
  286.       Exit 
  287.    End If 
  288.    '                    Add another note to the sequence
  289.    Inc SEQUENCE
  290.    '                    NOW let's go back for another sequence
  291. Loop 
  292. '                       Or we can start from the beginning again 
  293. '                       and maybe change some things 
  294. Return 
  295. '
  296. '                       --- SUBROUTINES START HERE --- 
  297. '
  298. '                       Setup the Game you want to play
  299. GAME1:
  300. BEGIN_NOTES=3
  301. MOST_NOTES=3
  302. ROUND_SIZE=500
  303. BEGIN_TIME=50
  304. SPEED_UP=0
  305. LIGHT_UP=1
  306. STD_TONES=1
  307. STD_PAD=1
  308. Gosub SETUP
  309. Return 
  310. '  
  311. GAME2:
  312. BEGIN_NOTES=3
  313. MOST_NOTES=7
  314. ROUND_SIZE=4
  315. BEGIN_TIME=50
  316. SPEED_UP=0
  317. LIGHT_UP=1
  318. STD_TONES=1
  319. STD_PAD=1
  320. Gosub SETUP
  321. Return 
  322. '
  323. GAME3:
  324. BEGIN_NOTES=3
  325. MOST_NOTES=7
  326. ROUND_SIZE=4
  327. BEGIN_TIME=50
  328. SPEED_UP=2
  329. LIGHT_UP=0
  330. STD_TONES=0
  331. STD_PAD=0
  332. Gosub SETUP
  333. Return 
  334. '
  335. '                       Sample the Game Pad before playing 
  336. TRYOUT:
  337. LEAVE=0
  338. Repeat 
  339.    '                    Wait for Mouse Click in Pad Zone  
  340.    MZONE=0
  341.    MKEY=0
  342.    While(MZONE=0) or(MKEY<>1)
  343.       MKEY=Mouse Key
  344.       If MKEY=1
  345.          MZONE=Mouse Zone
  346.       End If 
  347.       On Menu On 
  348.    Wend 
  349.    '                    Check if Zone is Pad  
  350.    If MZONE<5
  351.       '                 Light up the Pad 
  352.       If MZONE=1
  353.          OLDCOL=Colour(5)
  354.          Colour 5,$F00
  355.       End If 
  356.       If MZONE=2
  357.          OLDCOL=Colour(8)
  358.          Colour 8,$FF0
  359.       End If 
  360.       If MZONE=3
  361.          OLDCOL=Colour(11)
  362.          Colour 11,$F0
  363.       End If 
  364.       If MZONE=4
  365.          OLDCOL=Colour(14)
  366.          Colour 14,$F
  367.       End If 
  368.       '
  369.       '                 Play the Note for this Pad 
  370.       '
  371.       Play 3,SND(SZONE(MZONE)),20
  372.       '
  373.       '                 Return Pad to original Colour
  374.       If MZONE=1
  375.          Colour 5,OLDCOL
  376.       End If 
  377.       If MZONE=2
  378.          Colour 8,OLDCOL
  379.       End If 
  380.       If MZONE=3
  381.          Colour 11,OLDCOL
  382.       End If 
  383.       If MZONE=4
  384.          Colour 14,OLDCOL
  385.       End If 
  386.    End If 
  387.    '                    If Zone wasn't Pad check for QUIT 
  388.    If MZONE=10
  389.       LEAVE=1
  390.       '                 You Pushed The QUIT Button   
  391.       Z=11
  392.       Ink 2
  393.       Draw 461,Z*14+18 To 461,Z*14+7
  394.       Polyline 460,Z*14+18 To 460,Z*14+7 To 618,Z*14+7
  395.       Ink 1
  396.       Draw 619,Z*14+8 To 619,Z*14+19
  397.       Polyline 620,Z*14+8 To 620,Z*14+19 To 462,Z*14+19
  398.       For I=1 To 5
  399.          Bell I
  400.       Next I
  401.       While Mouse Key<>0
  402.          MKEY=Mouse Key
  403.       Wend 
  404.       Ink 1
  405.       Draw 461,Z*14+18 To 461,Z*14+7
  406.       Polyline 460,Z*14+18 To 460,Z*14+7 To 618,Z*14+7
  407.       Ink 2
  408.       Draw 619,Z*14+8 To 619,Z*14+19
  409.       Polyline 620,Z*14+8 To 620,Z*14+19 To 462,Z*14+19
  410.    End If 
  411. Until LEAVE=1
  412. '                       We have finished Sampling the Pad
  413. Return 
  414. '                       We are leaving the program 
  415. QUIT:
  416. End 
  417. Return 
  418. '
  419. '  
  420. SETUP:
  421. For I=1 To 4
  422.    SZONE(I)=0
  423. Next I
  424. '
  425. If STD_TONES=1
  426.    '                    Get Standard Notes  
  427.    SND(1)=NTS(1)
  428.    SND(2)=NTS(3)
  429.    SND(3)=NTS(5)
  430.    SND(4)=NTS(7)
  431. Else 
  432.    '                    Get Random Notes      
  433.    For I=1 To 4
  434.       SND(I)=0
  435.    Next I
  436.    For I=1 To 4
  437.       Repeat 
  438.          NOGOOD=0
  439.          PICK=Rnd(7)+1
  440.          If I=1
  441.             SND(I)=NTS(PICK)
  442.          Else 
  443.             For J=1 To I-1
  444.                If SND(J)=NTS(PICK)
  445.                   NOGOOD=1
  446.                End If 
  447.             Next J
  448.          End If 
  449.       Until NOGOOD=0
  450.       SND(I)=NTS(PICK)
  451.    Next I
  452. End If 
  453. '                       Now sort the random notes
  454. Repeat 
  455.    NOGOOD=0
  456.    For I=1 To 3
  457.       If SND(I)>SND(I+1)
  458.          Swap SND(I),SND(I+1)
  459.          NOGOOD=1
  460.       End If 
  461.    Next I
  462. Until NOGOOD=0
  463. '
  464. '  
  465. If STD_PAD=1
  466.    '                    Assign Standard Pad 
  467.    For I=1 To 4
  468.       SZONE(I)=I
  469.    Next I
  470. Else 
  471.    '                    Assign Random Pad 
  472.    CYCLE=1
  473.    While CYCLE<5
  474.       S=Rnd(3)+1
  475.       If SZONE(S)=0
  476.          SZONE(S)=CYCLE
  477.          Inc CYCLE
  478.       End If 
  479.    Wend 
  480. End If 
  481. Return 
  482. '                       --- PROCEDURES ARE HERE ---
  483. Procedure MAKEMENU
  484.    Paper 0
  485.    Pen 0
  486.    Print At(0,0);" ";
  487.    Paper 7
  488.    Pen 2
  489.    Menu$(1)="  Game  "
  490.    Menu$(1,1)=" About  "
  491.    Menu$(1,2)=" Help   "
  492.    Menu$(1,3)=" Quit   "
  493.    Menu$(1,1,1)="   Sonic-   " : Menu Inactive(1,1,1)
  494.    Menu$(1,1,2)="  Scramble  " : Menu Inactive(1,1,2)
  495.    Menu$(1,1,3)="    v1.0    " : Menu Inactive(1,1,3)
  496.    Menu$(1,1,4)="            " : Menu Inactive(1,1,4)
  497.    Menu$(1,1,5)=" Written by " : Menu Inactive(1,1,5)
  498.    Menu$(1,1,6)=" Garry Dan  " : Menu Inactive(1,1,6)
  499.    Menu$(1,1,7)="    1993    " : Menu Inactive(1,1,7)
  500.    
  501.    Menu On 
  502. End Proc
  503. Procedure MENU1
  504.    Bell 
  505.    If Choice(2)=2
  506.       Screen To Front 0
  507.       Screen 0
  508.       Get Palette 1
  509.       Paper 3
  510.       Pen 15
  511.       Restore 
  512.       Cls 
  513.       Data "GENERAL OPERATION."
  514.       Data " "
  515.       Data "The game is fairly straight foreward. Four notes are assigned to the game pad,"
  516.       Data "then a sequence of notes is played and by clicking on the pad with the mouse"
  517.       Data "you try to duplicate that sequence. Simple eh?"
  518.       Data " "
  519.       Data "The buttons GAME1, GAME2 & GAME3 allow you to select one of three variations"
  520.       Data "which you pre-define in the code (more later). PLAY starts your selected game"
  521.       Data "and after a slight pause the first sequence will be played. SAMPLE allows you"
  522.       Data "to click on the pad and listen to the different notes before playing a game."
  523.       Data "This is needed if either Random Notes or Random Pad are active (more later)."
  524.       Data "QUIT is used to exit from SAMPLE, to exit from the current GAME or leave the"
  525.       Data "PROGRAM. The QUIT option from the pull down menu will always quit the program."
  526.       Data " "
  527.       Data "So, the usual sequence of events will be:"
  528.       Data " "
  529.       Data " 1 - Select the GAME to play"
  530.       Data " 2 - If necessary SAMPLE to learn what notes are assigned to the pad."
  531.       Data " 3 - If necessary QUIT after sampling the new pad."
  532.       Data " 4 - PLAY the game."
  533.       Data " 5 - QUIT when finished."
  534.       Data " 6 - Select another GAME or QUIT to leave program."
  535.       Data " "
  536.       Data " "
  537.       Data " "
  538.       Data " "
  539.       Data " "
  540.       Data "CHANGING CODE FOR GAMES"
  541.       Data " "
  542.       Data "The program contains three subroutines GAME1, GAME2 & GAME3 which contain the"
  543.       Data "settings for the three games. The program will use GAME2 as it's default game"
  544.       Data "when it first loads up. Line 35 - Gosub GAME2"
  545.       Data " "
  546.       Data "You can alter any of the following variables to design the games that best"
  547.       Data "suit your needs. The subroutines begin at line 299."
  548.       Data " "
  549.       Data " BEGIN_NOTES = The number of notes in the first sequence."
  550.       Data " MOST_NOTES  = The maximum number of notes possible in a sequence."
  551.       Data " ROUND_SIZE  = The number of turns before any change in notes or time."
  552.       Data " BEGIN_TIME  = The length of time between notes in the first sequence."
  553.       Data " SPEED_UP    = The amount of time deducted at each time change."
  554.       Data " LIGHT_UP    = Does the pad light up when playing the sequence."
  555.       Data " STD_TONES   = Use the 4 standard tones (or a random set from a possible 8)."
  556.       Data " STD_PAD     = Assign notes from lowest to highest (or random layout on pad)."
  557.       Data " "
  558.       Data "With the last three settings a 0 = NO and a 1 = YES."
  559.       Data " "
  560.       Data "You could also alter the IFF screen (a file called Sonic-Screen) so instead of"
  561.       Data "having GAME1 etc. on each button, there could be personal names or difficulty"
  562.       Data "ratings."
  563.       Data " "
  564.       Data " "
  565.       Data " "
  566.       Data " "
  567.       Data "POSSIBLE VARIATIONS"
  568.       Data " "
  569.       Data "At present the game simply keeps track of the number of correct and incorrect"
  570.       Data "guesses, and continues playing until you quit. So, the first thing you could"
  571.       Data "consider is a scoring system with a difficulty factor and some predefined end"
  572.       Data "to the game. Another option would be a multi-player game where ROUND_SIZE will"
  573.       Data "decrement with each wrong guess and the incorrect player drops out, thus a"
  574.       Data "round of 4 players would decrease to 3 at the first wrong guess, and so on."
  575.       Data "You could also then allow the players to enter their names at the beginning of"
  576.       Data "the game and the program could keep track of who's turn it is. People with an"
  577.       Data "interest in music may find the 8 note range too easy and would rather a 16"
  578.       Data "note range, or more."
  579.       Data " "
  580.       Data "The trouble with this sort of game is in fact the large number of possible"
  581.       Data "variations, but what is challenging for an adult is impossible for a 5 year"
  582.       Data "old and what a 5 year old will play all day, no one else would play twice. So"
  583.       Data "I decided that the best thing would be to provide a basic game with routines"
  584.       Data "that could be altered to suit anybody. I have tried to keep the code as plain"
  585.       Data "as possible with lots of REMs. The game screen is loaded from disk, rather"
  586.       Data "than being unpacked from a bank, so that it can be modified. The button code"
  587.       Data "is in 'long hand' so that the routine for each button can be followed (see my"
  588.       Data "program MATRIX MANIA for the same routine done as a procedure). As already"
  589.       Data "mentioned, the subroutines for the 3 games settings can be easily altered for"
  590.       Data "different styles of game without the need to understand any of the main code."
  591.       Data "The worst that can happen if you enter a strange value is a sulking program,"
  592.       Data "but then failure can also be a learning experience. If you turn this program"
  593.       Data "into something sensible don't forget to send it to the AMOS PD Library."
  594.       
  595.       For J=1 To 3
  596.          For I=1 To 27
  597.             Locate 1,I
  598.             Read A$
  599.             Print A$
  600.          Next I
  601.          MKEY=0
  602.          While MKEY=0
  603.             MKEY=Mouse Key
  604.          Wend 
  605.          Cls 
  606.       Next J
  607.       Screen To Front 1
  608.       Screen 1
  609.    End If 
  610.    If Choice(2)=3
  611.       End 
  612.    End If 
  613.    Menu On 
  614. End Proc