Samples Gallery & Reference > Games

QB64 Simon by TerryRitchie

(1/1)

bplus:
QB64 Simon
Author: @TerryRitchie
Source: qb64.org Forum
URL: https://www.qb64.org/forum/index.php?topic=2263
Version: 1.0 written March, 2015
Tags: [Retro] [Sim]

Description:
An exact replica of the Simon game from the 1980's (with added QB64 bee graphic).
Game play can be done with keyboard, mouse, or both. Press F1 for a help screen.

Source:

--- Code: QB64: ---'*'*                                    ------------------'*                                    --- QB64 Simon ---'*                                    ------------------'*'*                                     By Terry Ritchie'*'*                       Written from March 22nd to March 28th, 2015'*                                       Version 1.0'* '--------------------------------'- VARIABLE DECLARATION SECTION -'-------------------------------- CONST FALSE = 0 '        boolean: false indicatorCONST TRUE = NOT FALSE ' boolean: true indicatorCONST MOUSE% = 200 '     call PADPRESS with mouse button DIM Pad&(3, 1) '         color pads: 0,x=BLUE, 1,x=RED, 2,x=GREEN, 3,x=YELLOWDIM PadXY%(3, 1) '       x,y locations of color padsDIM Tone&(4) '           game sounds: 0=BLUE, 1=RED, 2=GREEN, 3=YELLOW, 4=LOSEDIM Simon& '             simon graphics imageDIM SimonHelp& '         simon help screenDIM Keys&(3, 1) '        keyboard key images 0=Q, 1=W, 2=S, 3=ADIM Bslider& '           blue slider switch imageDIM Rslider& '           red slider switch imageDIM OnOff& '             on/off slider switchDIM KeysXY%(3, 1) '      location of keyboard key images on play screenDIM GameOver% '          boolean: true when game has endedDIM Game% '              the position the blue slider switch is in (0-2)DIM Skill% '             the position the red slider switch is in (0-3)DIM GameDir% '           the direction blue slider switch will move (1, -1)DIM SkillDir% '          the direction red slider switch will move (1, -1)DIM Longest$ '           the longest tune correctly played by a playerDIM Last$ '              the last tune played by the playerDIM Count% '             generic counterDIM KeyPress$ '          any keys pressed by the playerDIM Pcolor~&(3) '        color pad base colors: 0=BLUE, 1=RED, 2=GREEN, 3=YELLOW '----------------'- MAIN PROGRAM -'---------------- INITIALIZE '                                                       prepare graphics, sounds and variablesSCREEN _NEWIMAGE(640, 640, 32) '                                   create game screen_TITLE "QB64 SIMON" '                                              give game screen a title_SCREENMOVE _MIDDLE '                                              move game screen to middle of desktop_DELAY .5 '                                                        light delay to move to middle of screenCLS '                                                              remove black transparencyDO '                                                               BEGIN MAIN GAME LOOP    GameOver% = FALSE '                                            reset game over flag    PRESSPAD 0, 0 '                                                reset game board    _DISPLAY    DO '                                                           BEGIN PLAY GAME LOOP        _LIMIT 120 '                                               limit to 120 loops per second        WHILE _MOUSEINPUT: WEND '                                  get to last mouse event        IF _MOUSEBUTTON(1) THEN '                                  did player click left mouse button?            IF POINTER%(232 + Game% * 10, 323, 289 + Game% * 10, 345) THEN ' test blue slider area?                IF Game% = 0 OR Game% = 2 THEN '                   yes, is blue slider at its limit?                    GameDir% = -GameDir% '                         yes, reverse blue slider direction                END IF                Game% = Game% + GameDir% '                         change game level                PRESSPAD 0, .125 '                                 display change on screen                WAIT4RELEASE            ELSEIF POINTER%(319 + Skill% * 10, 323, 375 + Skill% * 10, 345) THEN ' test red slider area?                IF Skill% = 0 OR Skill% = 3 THEN '                 yes, is red slider at its limit?                    SkillDir% = -SkillDir% '                       yes, reverse red slider direction                END IF                Skill% = Skill% + SkillDir% '                      change skill level                PRESSPAD 1, .125 '                                 display change on screen                WAIT4RELEASE            ELSEIF POINTER%(254, 371, 271, 388) THEN '             test last button area?                WAIT4RELEASE                FOR Count% = 1 TO LEN(Last$) '                     cycle through last tune string                    PRESSPAD VAL(MID$(Last$, Count%, 1)), .5 '     play each individual tone                    _DELAY .125 '                                  pause for 1/8 second                NEXT Count%            ELSEIF POINTER%(371, 371, 388, 388) THEN '             test longest button area?                Count% = 0 '                                       yes, reset 1/120 counter                DO '                                               BEGIN MOUSE RELEASE LOOP                    _LIMIT 120 '                                   don't hog CPU while looping                    WHILE _MOUSEINPUT: WEND '                      get to last mouse event                    Count% = Count% + 1 '                          increment 1/120 second counter                    IF Count% > 360 THEN '                         have 3 seconds elapsed?                        FOR Count% = 0 TO 3 '                      yes, cycle through all four color pads                            PRESSPAD Count%, .125 '                light pad and play tone quickly                        NEXT Count%                        Longest$ = "" '                            reset longest tune string                        SIMONFILE 2 '                              delete simon.sav file                    END IF                LOOP UNTIL NOT _MOUSEBUTTON(1) '                   END MOUSE RELEASE LOOP when left button released                FOR Count% = 1 TO LEN(Longest$) '                  cycle through longest tune string                    PRESSPAD VAL(MID$(Longest$, Count%, 1)), .5 '  play each individual tone                    _DELAY .125 '                                  pause 1/8 second                NEXT Count%            ELSEIF POINTER%(314, 371, 331, 388) THEN '             test start button area?                _DELAY .5 '                                        1/2 second delay before game start                PLAYGAME '                                         play game            ELSEIF POINTER%(321, 408, 332, 419) THEN '             test power button slider area?                ENDGAME '                                          yes, end the game            END IF        END IF        KeyPress$ = INKEY$ '                                       get any key player may have pressed        IF KeyPress$ = CHR$(0) + CHR$(59) THEN '                   did player press the F1 key?            DISPLAYHELP '                                          yes, display help screen to player        END IF    LOOP UNTIL GameOver% '                                         END PLAY GAME LOOPLOOP '                                                             MAIN GAME LOOP end '--------------------'- END MAIN PROGRAM -'-------------------- '---------------------------'- SUBROUTINES & FUNCTIONS -'--------------------------- '----------------------------------------------------------------------------------------------------------------------'                                                                                                           DISPLAYHELPSUB DISPLAYHELP ()     '---------------------------------------    '- Display the help screen to the player    '---------------------------------------     SHARED SimonHelp& ' simon help screen     _PUTIMAGE (0, 0), SimonHelp& '                display help screen    _DISPLAY '                                    update screen with change    DO '                                          BEGIN KEY/MOUSE LOOP        _LIMIT 120 '                              don't hog the CPU        WHILE _MOUSEINPUT: WEND '                 get latest mouse events    LOOP UNTIL INKEY$ <> "" OR _MOUSEBUTTON(1) '  END KEY/MOUSE LOOP when left button clicked or key pressed    PRESSPAD 0, 0 '                               restore game screen END SUB '----------------------------------------------------------------------------------------------------------------------'                                                                                                          WAIT4RELEASESUB WAIT4RELEASE ()     '--------------------------------------------    '- Waits for left mouse button to be released    '--------------------------------------------     DO '                             BEGIN MOUSE RELEASE LOOP        _LIMIT 120 '                 don't hog the CPU        WHILE _MOUSEINPUT: WEND '    get to last mouse event    LOOP UNTIL NOT _MOUSEBUTTON(1) ' END MOUSE RELEASE LOOP when left button released END SUB '----------------------------------------------------------------------------------------------------------------------'                                                                                                             SIMONFILESUB SIMONFILE (Task%)     '------------------------------------------    '- Loads, updates, or deletes the save file    '-    '- Task%: 0 - load file    '-        1 - update file    '-        2 - delete file    '------------------------------------------     SHARED Longest$ ' the longest tune correctly played by a player     SELECT CASE Task% '                            load, update, or delete?        CASE 0 '                                   load file            IF _FILEEXISTS("simon.sav") THEN '     does the save file exist?                OPEN "simon.sav" FOR INPUT AS #1 ' yes, open the file for reading                LINE INPUT #1, Longest$ '          get the longest tune ever played                CLOSE #1 '                         close the file            END IF        CASE 1 '                                   update file            OPEN "simon.sav" FOR OUTPUT AS #1 '    open the file for output            PRINT #1, Longest$ '                   write the longest tune ever played            CLOSE #1 '                             close the file        CASE 2 '                                   delete file            IF _FILEEXISTS("simon.sav") THEN '     does the save file exist?                KILL "simon.sav" '                 yes, delete it            END IF    END SELECT END SUB '----------------------------------------------------------------------------------------------------------------------'                                                                                                              POINTER%FUNCTION POINTER% (x1%, y1%, x2%, y2%)     '------------------------------------------------------------------------------    '- Returns TRUE if the mouse pointer falls within x1%,y1% - x2%,y2% coordinates    '-    '- x1%: upper left  hand corner x coordinate of box area    '- y1%: upper left  hand corner y coordinate of box area    '- x2%: lower right hand corner x coordinate of box area    '- y2%: lower right hand corner y coordinate of box area    '------------------------------------------------------------------------------     DIM mx% ' current mouse pointer x coordinate    DIM my% ' current mouse pointer y coordinate     POINTER% = FALSE '                assume pointer does not fall within coordinates    WHILE _MOUSEINPUT: WEND '         get latest mouse event    mx% = _MOUSEX '                   get current mouse pointer x coordinate    my% = _MOUSEY '                   get current mouse pointer y coordinate    IF mx% >= x1% THEN '              could pointer be within x coordinates?        IF mx% <= x2% THEN '          yes, is pointer within x coordinates?            IF my% >= y1% THEN '      yes, could pointer be within y coordinates?                IF my% <= y2% THEN '  yes, is pointer within y coordinates?                    POINTER% = TRUE ' yes, report back that pointer falls within coordinates                END IF            END IF        END IF    END IF END FUNCTION '----------------------------------------------------------------------------------------------------------------------'                                                                                                              PLAYGAMESUB PLAYGAME ()     '-----------------------    '- Plays a game of simon    '-----------------------     SHARED GameOver% ' boolean: true when game has ended    SHARED Game% '     the position the blue slider switch is in (0-2)    SHARED Skill% '    the position the red slider switch is in (0-3)    SHARED Longest$ '  the longest tune correctly played by a player    SHARED Last$ '     the last tune played by the player     DIM Tune$ '        string of random tunes generated during game play    DIM KeyPress& '    contains value of any key pressed    DIM PlaySpeed! '   speed that simon plays notes    DIM Count% '       generic counter    DIM Notes% '       player note counter    DIM PadPress% '    value of colored pad pressed by player    DIM Plongest$ '    current player's longest tune    DIM Win% '         number of correct tones to win     '-------------    '- MAIN CODE -    '-------------     PRESSPAD 0, 0 '                                                 reset game screen    PlaySpeed! = 1 '                                                reset game speed    Win% = 12 + Skill% * 6 '                                        calculate number of tones to win    Tune$ = "" '                                                    reset random tune string    DO '                                                            BEGIN PLAY GAME LOOP        FOR Count% = 1 TO Game% + 1 '                               number of notes to add            Tune$ = Tune$ + LTRIM$(RTRIM$(STR$(INT(RND(1) * 4)))) ' add a random tone            IF LEN(Tune$) MOD 3 = 0 THEN '                          divisible evenly by 3?                PlaySpeed! = PlaySpeed! - .125 '                    yes, increase speed of play                IF PlaySpeed! < .125 THEN PlaySpeed! = .125 '       keep play speed at certain minimum            END IF        NEXT Count%        FOR Count% = 1 TO LEN(Tune$) '                              cycle through the tones            PRESSPAD VAL(MID$(Tune$, Count%, 1)), PlaySpeed! '      play the tone            _DELAY PlaySpeed! / 4 '                                 pause between tones        NEXT Count%        Notes% = 0 '                                                reset player note count        DO '                                                        BEGIN PLAY ROUND LOOP            DO '                                                    BEGIN BUFFER CLEAR LOOP                _LIMIT 120 '                                        don't hog CPU                KeyPress& = _KEYHIT '                               get keypress from keyboard buffer            LOOP WHILE KeyPress& '                                  END BUFFER CLEAR LOOP when buffer clear            Notes% = Notes% + 1 '                                   increment player note count            PadPress% = PLAYERINPUT% '                              get player's next color pad press            IF PadPress% <> VAL(MID$(Tune$, Notes%, 1)) THEN '      did the player press the right color pad?                GameOver% = TRUE '                                  no, set game over flag                PRESSPAD 4, 2 '                                     play loser sound and light up simon            END IF        LOOP UNTIL Notes% = LEN(Tune$) OR GameOver% '               END PLAY ROUND LOOP when player success or game over        IF NOT GameOver% THEN Plongest$ = Tune$ '                   remember last attempt as player's longest        IF Notes% = Win% THEN '                                     did player win?            GameOver% = TRUE '                                      yes, set game over            FOR Win% = 1 TO 6 '                                     cycle 6 times                FOR Count% = 0 TO 3 '                               cycle through all color pads                    PRESSPAD Count%, .125 '                         press color pad                NEXT Count%            NEXT Win%        END IF        _DELAY PlaySpeed! * 2 '                                     slight delay between rounds    LOOP UNTIL GameOver% '                                          END PLAY GAME LOOP when game over    Last$ = Tune$ '                                                 remember the entire last tune played    IF LEN(Plongest$) > LEN(Longest$) THEN '                        did player set a new longest record?        Longest$ = Plongest$ '                                      yes, remember the new longest tune        SIMONFILE 1 '                                               update simon.sav with new longest tune    END IF END SUB '----------------------------------------------------------------------------------------------------------------------'                                                                                                          PLAYERINPUT%FUNCTION PLAYERINPUT% ()     ' -----------------------------------------------------------------------    ' Waits for player input then returns the color pad pressed by the player    ' -----------------------------------------------------------------------     SHARED Pcolor~&() ' color pad base colors: 0=BLUE, 1=RED, 2=GREEN, 3=YELLOW     DIM PadPress% '     the color pad that was pressed    DIM KeyPress& '     a key the player has pressed    DIM mx% '           current mouse pointer x coordinate    DIM my% '           current mouse pointer y coordinate    DIM Clr~& '         color of pixel clicked on     PadPress% = -1 '                                                      reset pad press indicator    DO '                                                                  BEGIN INPUT LOOP        _LIMIT 120 '                                                      don't hog the CPU        KeyPress& = _KEYHIT '                                             get the latest key status        WHILE _MOUSEINPUT: WEND '                                         get the latest mouse status        IF KeyPress& THEN '                                               was a key pressed?            SELECT CASE KeyPress& '                                       yes, which one?                CASE 81, 113 '                                            Q or q key                    PRESSPAD 0, KeyPress& '                               press blue pad on simon                    PadPress% = 0 '                                       remember blue pad pressed                CASE 87, 119 '                                            W or w key                    PRESSPAD 1, KeyPress& '                               press red pad on simon                    PadPress% = 1 '                                       remember red pad pressed                CASE 83, 115 '                                            S or s key                    PRESSPAD 2, KeyPress& '                               press green pad on simon                    PadPress% = 2 '                                       remember green pad pressed                CASE 65, 97 '                                             A or a key                    PRESSPAD 3, KeyPress& '                               press yellow pad on simon                    PadPress% = 3 '                                       remember yellow pad pressed            END SELECT        ELSEIF _MOUSEBUTTON(1) THEN '                                     no, was the left mouse button clicked?            mx% = _MOUSEX '                                               yes, get x location of mouse pointer            my% = _MOUSEY '                                               get y location of mouse pointer            Clr~& = POINT(mx%, my%)            IF mx% < 320 AND my% < 320 AND Clr~& = Pcolor~&(0) THEN '     pointer in blue area?                PRESSPAD 0, MOUSE% '                                      yes, press blue pad on simon                PadPress% = 0 '                                           remember blue pad pressed            ELSEIF mx% > 319 AND my% < 320 AND Clr~& = Pcolor~&(1) THEN ' no, pointer in red area?                PRESSPAD 1, MOUSE% '                                      yes, press red pad on simon                PadPress% = 1 '                                           remember red pad pressed            ELSEIF mx% > 319 AND my% > 319 AND Clr~& = Pcolor~&(2) THEN ' no, pointer in green area?                PRESSPAD 2, MOUSE% '                                      yes, press green pad on simon                PadPress% = 2 '                                           remember green pad pressed            ELSEIF mx% < 320 AND my% > 319 AND Clr~& = Pcolor~&(3) THEN ' no, pointer in yellow area?                PRESSPAD 3, MOUSE% '                                      yes, press yellow pad on simon                PadPress% = 3 '                                           remember yellow pad pressed            END IF        END IF    LOOP UNTIL PadPress% <> -1 '                                          END INPUT LOOP when simon pad pressed    PLAYERINPUT% = PadPress% '                                            return the pad that was pressed END FUNCTION '----------------------------------------------------------------------------------------------------------------------'                                                                                                              PRESSPADSUB PRESSPAD (PadNum%, Behavior!)     ' -----------------------------------------------------------------------------------------    ' Simulates pressing a colored pad by lighting it up and playing its corresponding sound    '    ' PadNum%   - The colored pad to press: 0=BLUE, 1=RED, 2=GREEN, 3=YELLOW, 4=ALL    ' Behavior! - If value is less than 5 then sound plays for this duration    '           - If value is less than 120 then sound plays until scancode of key is released    '           - if value > 120 then sound plays until left mouse button is released    '           - if value is zero then game board is redrawn only    ' -----------------------------------------------------------------------------------------     SHARED Tone&() '   game sounds    SHARED Pad&() '    color pads: 0,x=BLUE, 1,x=RED, 2,x=GREEN, 3,x=YELLOW    SHARED PadXY%() '  x,y locations of color pads    SHARED Simon& '    simon graphics image    SHARED Keys&() '   keyboard key images 0=Q, 1=W, 2=S, 3=A    SHARED KeysXY%() ' location of keyboard key images    SHARED Bslider& '  blue slider switch image    SHARED Rslider& '  red slider switch image    SHARED OnOff& '    on/off slider switch    SHARED Game% '     the position the blue slider switch is in (0-2)    SHARED Skill% '    the position the red slider switch is in (0-3)     DIM KeyPress& '    key press value    DIM KeyStatus% '   0=no key animation, 1=key animation     '-------------    '- MAIN CODE -    '-------------     KeyStatus% = 1 '                                                                           assume key animation    IF Behavior! THEN '                                                                        just a board redraw?        IF Behavior! = MOUSE% OR Behavior! < 5 THEN '                                          turn key animation off?            KeyStatus% = 0 '                                                                   yes, turn animation off        END IF        IF PadNum% <> 4 THEN '                                                                 single color pad selected?            _PUTIMAGE (PadXY%(PadNum%, 0), PadXY%(PadNum%, 1)), Pad&(PadNum%, 1) '             yes, light color pad            _PUTIMAGE (KeysXY%(PadNum%, 0), KeysXY%(PadNum%, 1)), Keys&(PadNum%, KeyStatus%) ' animate key if needed        ELSE '                                                                                 no, all color pads selected            FOR Count% = 0 TO 3 '                                                              cycle through all color pads                _PUTIMAGE (PadXY%(Count%, 0), PadXY%(Count%, 1)), Pad&(Count%, 1) '            light color pad                _PUTIMAGE (KeysXY%(Count%, 0), KeysXY%(Count%, 1)), Keys&(Count%, 0) '         set keys to raised position            NEXT Count%        END IF        _PUTIMAGE (200, 200), Simon& '                                                         place round simon image        _PUTIMAGE (232 + Game% * 10, 323), Bslider& '                                          place blue slider        _PUTIMAGE (319 + Skill% * 10, 323), Rslider& '                                         place red slider        _PUTIMAGE (321, 408), OnOff& '                                                         place power button slider        _DISPLAY '                                                                             update screen with changes        _SNDLOOP Tone&(PadNum%) '                                                              sound into continuous loop        SELECT CASE Behavior! '                                                                how was SUB called?            CASE IS < 5 '                                                                      computer pressing color pad                _DELAY Behavior! '                                                             use value as a delay            CASE IS < 120 '                                                                    player is pressing a key                _DELAY .125 '                                                                  pause for 1/8 second                DO '                                                                           BEGIN KEYBOARD SCAN LOOP                    _LIMIT 120 '                                                               don't hog CPU                    KeyPress% = _KEYHIT '                                                      get value of key pressed                LOOP UNTIL KeyPress% = -Behavior! '                                            END LOOP when key released            CASE ELSE '                                                                        player using mouse button                _DELAY .125 '                                                                  pause for 1/8 second                WAIT4RELEASE '                                                                 wait left button released        END SELECT        _SNDSTOP Tone&(PadNum%) '                                                              stop the sound    END IF    FOR Count% = 0 TO 3 '                                                                      cycle through all color pads        _PUTIMAGE (PadXY%(Count%, 0), PadXY%(Count%, 1)), Pad&(Count%, 0) '                    unlight color pad        _PUTIMAGE (KeysXY%(Count%, 0), KeysXY%(Count%, 1)), Keys&(Count%, 0) '                 set keys to raised position    NEXT Count%    _PUTIMAGE (200, 200), Simon& '                                                             place round simon image    _PUTIMAGE (232 + Game% * 10, 323), Bslider& '                                              place blue slider    _PUTIMAGE (319 + Skill% * 10, 323), Rslider& '                                             place red slider    _PUTIMAGE (321, 408), OnOff& '                                                             place power button slider    _DISPLAY '                                                                                 update screen with changes END SUB '----------------------------------------------------------------------------------------------------------------------'                                                                                                            INITIALIZESUB INITIALIZE ()     ' --------------------------------------------------------------------------------------------    ' Initialize all variables, create color pad images, load sounds and load spritesheet graphics    ' --------------------------------------------------------------------------------------------     SHARED Pad&() '     color pads: 0,x=BLUE, 1,x=RED, 2,x=GREEN, 3,x=YELLOW    SHARED PadXY%() '   x,y locations of color pads    SHARED Tone&() '    game sounds    SHARED Simon& '     simon graphics image    SHARED SimonHelp& ' simon help screen    SHARED Keys&() '    keyboard key images 0=Q, 1=W, 2=S, 3=A    SHARED Bslider& '   blue slider switch image    SHARED Rslider& '   red slider switch image    SHARED OnOff& '     on/off slider switch    SHARED KeysXY%() '  location of keyboard key images    SHARED Game% '      the position the blue slider switch is in (0-2)    SHARED Skill% '     the position the red slider switch is in (0-3)    SHARED GameDir% '   the direction blue slider switch will move (1, -1)    SHARED SkillDir% '  the direction red slider switch will move (1, -1)    SHARED Pcolor~&() ' color pad base colors: 0=BLUE, 1=RED, 2=GREEN, 3=YELLOW     DIM Sheet& '        sprite sheet containing game graphics    DIM Mask& '         color pad mask image    DIM Count% '        increasing color brightness counter    DIM Pcount% '       pad counter    DIM x% '            x location of pad circles    DIM y% '            y location of pad circles    DIM Clr~& '         temporary color pad color holder     '-------------    '- MAIN CODE -    '-------------     RANDOMIZE TIMER '                                            seed random number generator    Tone&(0) = _SNDOPEN("SimonB209.ogg", "VOL,SYNC") '           load blue   sound 209 Hz    Tone&(1) = _SNDOPEN("SimonR310.ogg", "VOL,SYNC") '           load red    sound 310 Hz    Tone&(2) = _SNDOPEN("SimonG415.ogg", "VOL,SYNC") '           load green  sound 415 Hz    Tone&(3) = _SNDOPEN("SimonY252.ogg", "VOL,SYNC") '           load yellow sound 252 Hz    Tone&(4) = _SNDOPEN("SimonL042.ogg", "VOL,SYNC") '           load lose   sound  42 Hz    Simon& = _NEWIMAGE(242, 242, 32) '                           simon image holder    Bslider& = _NEWIMAGE(57, 22, 32) '                           blue slider image holder    Rslider& = _NEWIMAGE(57, 22, 32) '                           red slider image holder    OnOff& = _NEWIMAGE(11, 11, 32) '                             power button slider image holder    Sheet& = _LOADIMAGE("SimonGFX.png", 32) '                    load simon sprite sheet of images    SimonHelp& = _LOADIMAGE("SimonHELP.png", 32) '               load simon help screen    _PUTIMAGE (0, 0), Sheet&, Simon&, (0, 94)-(241, 335) '       extract simon from spritesheet    _PUTIMAGE (0, 0), Sheet&, Bslider&, (200, 0)-(256, 21) '     extract blue slider from spritesheet    _PUTIMAGE (0, 0), Sheet&, Rslider&, (200, 22)-(256, 43) '    extract red slider from spritesheet    _PUTIMAGE (0, 0), Sheet&, OnOff&, (200, 44)-(210, 54) '      extract power button slider from spritesheet    FOR Count% = 0 TO 3 '                                        cycle through 4 color pads        Pad&(Count%, 0) = _NEWIMAGE(320, 320, 32) '              create color pad off image        Pad&(Count%, 1) = _NEWIMAGE(320, 320, 32) '              create color pad on  image        Keys&(Count%, 0) = _NEWIMAGE(50, 47, 32) '               create q,w,s,a raised key image holders        Keys&(Count%, 1) = _NEWIMAGE(50, 47, 32) '               create q,w,s,a pressed key image holders        _PUTIMAGE (0, 0), Sheet&, Keys&(Count%, 0), (Count% * 50, 0)-(Count% * 50 + 49, 46) '  extract key raised images        _PUTIMAGE (0, 0), Sheet&, Keys&(Count%, 1), (Count% * 50, 47)-(Count% * 50 + 49, 93) ' extract key pressed images    NEXT Count%    PadXY%(0, 0) = 0 '                                           color pad locations    PadXY%(0, 1) = 0    PadXY%(1, 0) = 320    PadXY%(1, 1) = 0    PadXY%(2, 0) = 320    PadXY%(2, 1) = 320    PadXY%(3, 0) = 0    PadXY%(3, 1) = 320    KeysXY%(0, 0) = 20 '                                         keyboard key image locations    KeysXY%(0, 1) = 20    KeysXY%(1, 0) = 570    KeysXY%(1, 1) = 20    KeysXY%(2, 0) = 570    KeysXY%(2, 1) = 573    KeysXY%(3, 0) = 20    KeysXY%(3, 1) = 573    Pcolor~&(0) = _RGB32(0, 0, 128) '                            blue color of pad in off condition    Pcolor~&(1) = _RGB32(128, 0, 0) '                            red color of pad in off condition    Pcolor~&(2) = _RGB32(0, 128, 0) '                            green color of pad in off condition    Pcolor~&(3) = _RGB32(128, 128, 0) '                          yellow color of pad in off condition    Game% = 0 '                                                  set initial game level    Skill% = 0 '                                                 set initial skill level    GameDir% = -1 '                                              set intial blue slider direction    SkillDir% = -1 '                                             set initial red slider direction    SIMONFILE 0 '                                                load longest tune ever played if available    '*    '* Create the eight semi-circle color pads, four off, four on    '*    FOR Pcount% = 0 TO 3 '                                       cycle through four color pads        _DEST Pad&(Pcount%, 0) '                                 set color pad off image as destination        CLS '                                                    remove black transparency        SELECT CASE Pcount% '                                    which color pad is being worked on?            CASE 0 '                                             blue color pad                x% = 319: y% = 319 '                             set x,y coordinates of circles            CASE 1 '                                             red color pad                x% = 0: y% = 319 '                               set x,y coordinates of circles            CASE 2 '                                             green color pad                x% = 0: y% = 0 '                                 set x,y coordinates of circles            CASE 3 '                                             yellow color pad                x% = 319: y% = 0 '                               set x,y coordinate of circles        END SELECT        CIRCLE (x%, y%), 319, _RGB32(16, 16, 16) '               draw simon outer circle segment        PAINT (x%, y%), _RGB32(16, 16, 16), _RGB32(16, 16, 16) ' paint simon color        CIRCLE (x%, y%), 300, Pcolor~&(Pcount%) '                draw color pad outer circle segment        CIRCLE (x%, y%), 140, Pcolor~&(Pcount%) '                draw color pad inner circle segment        PAINT (159, 159), Pcolor~&(Pcount%), Pcolor~&(Pcount%) ' paint color pad circle segment interior        LINE (x%, y%)-(ABS(319 - x%), ABS(10 - y%)), _RGB32(16, 16, 16), BF ' separate color pads horizontally        LINE (x%, y%)-(ABS(10 - x%), ABS(319 - y%)), _RGB32(16, 16, 16), BF ' separate color pads vertically        CIRCLE (x%, y%), 319, _RGB32(32, 32, 32) '               highlight edge of simon        Mask& = _COPYIMAGE(Pad&(Pcount%, 0)) '                   create an image mask        _DEST Mask& '                                            set the mask as the destination        _CLEARCOLOR Pcolor~&(Pcount%) '                          set circle segment as transparent        _DEST Pad&(Pcount%, 1) '                                 set color pad on image as destination        CLS '                                                    remove black transparency        Clr~& = Pcolor~&(Pcount%) '                              remember color being worked on        LINE (0, 0)-(319, 319), Clr~&, BF '                      fill entire image with color pad color        FOR Count% = 129 TO 255 '                                cycle 126 times            SELECT CASE Pcount% '                                which color pad is being worked on?                CASE 0 '                                         blue color pad                    Clr~& = Clr~& + 1 '                          increase blue component                CASE 1 '                                         red color pad                    Clr~& = Clr~& + 65536 '                      increase red component                CASE 2 '                                         green color pad                    Clr~& = Clr~& + 256 '                        increase green component                CASE 3 '                                         yellow color pad                    Clr~& = Clr~& + 65792 '                      increase red and green component (yellow)            END SELECT            CIRCLE (159, 159), (255 - Count%) * 2, Clr~& '       draw circle with new color component            PAINT (159, 159), Clr~&, Clr~& '                     paint inside circle new color component        NEXT Count%        _PUTIMAGE (0, 0), Mask& '                                place mask over circles    NEXT Pcount%    _FREEIMAGE Mask& '                                           remove mask image from RAM (no longer needed)    _FREEIMAGE Sheet& '                                          remove spritesheet from RAM (no longer needed) END SUB '----------------------------------------------------------------------------------------------------------------------'                                                                                                               ENDGAMESUB ENDGAME ()     '--------------------------------------------------------------------    '- Removes game's assets from RAM and returns to the operating system    '--------------------------------------------------------------------     SHARED Pad&() '     color pads: 0,x=BLUE, 1,x=RED, 2,x=GREEN, 3,x=YELLOW    SHARED Tone&() '    game sounds    SHARED Simon& '     simon graphics image    SHARED SimonHelp& ' simon help screen    SHARED Keys&() '    keyboard key images 0=Q, 1=W, 2=S, 3=A    SHARED Bslider& '   blue slider switch image    SHARED Rslider& '   red slider switch image    SHARED OnOff& '     on/off slider switch     DIM Count% '        generic counter     LINE (321, 408)-(331, 418), _RGB32(0, 0, 0), BF ' clear power button    _PUTIMAGE (313, 408), OnOff& '                    place power button in new position    _DISPLAY '                                        update screen with changes    FOR Count% = 0 TO 3 '                             cycle through assets        _SNDCLOSE Tone&(Count%) '                     close sound files        _FREEIMAGE Keys&(Count%, 0) '                 remove key raised images        _FREEIMAGE Keys&(Count%, 1) '                 remove key pressed images        _FREEIMAGE Pad&(Count%, 0) '                  remove color pad unlit images        _FREEIMAGE Pad&(Count%, 1) '                  remove color pad lit images    NEXT Count%    _SNDCLOSE Tone&(4) '                              close last sound file    _FREEIMAGE Simon& '                               remove simon image    _FREEIMAGE SimonHelp& '                           remove simon help screen image    _FREEIMAGE Bslider& '                             remove blue slider switch image    _FREEIMAGE Rslider& '                             remove red slider switch image    _FREEIMAGE OnOff& '                               remove on/off power switch image    _DELAY 1 '                                        pause for 1 second    SYSTEM '                                          return control to the operating system END SUB 
 



Navigation

[0] Message Index

Go to full version