Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
QB64 Simon by Terry Ritchie
#1
Quote:I was going through some of my old code and came across the Simon game I created back in 2015. I don't believe I ever posted it here. It's an exact replica of the Simon game from the 1980's (well, I added the QB64 bee graphic).

Game play can be done with keyboard, mouse, or both. Press F1 for a help screen.

The .ZIP file below contains the source code and asset files needed to compile and play the game.

   

Required files (plus BAS source):
.zip   Simon.zip (Size: 236.77 KB / Downloads: 20)

Code: (Select All)
'*
'* ------------------
'* --- QB64 Simon ---
'* ------------------
'*
'* By Terry Ritchie
'*
'* Written from March 22nd to March 28th, 2015
'* Version 1.0
'*

'--------------------------------
'- VARIABLE DECLARATION SECTION -
'--------------------------------

Const FALSE = 0 ' boolean: false indicator
Const TRUE = Not FALSE ' boolean: true indicator
Const MOUSE% = 200 ' call PADPRESS with mouse button

Dim Pad&(3, 1) ' color pads: 0,x=BLUE, 1,x=RED, 2,x=GREEN, 3,x=YELLOW
Dim PadXY%(3, 1) ' x,y locations of color pads
Dim Tone&(4) ' game sounds: 0=BLUE, 1=RED, 2=GREEN, 3=YELLOW, 4=LOSE
Dim Simon& ' simon graphics image
Dim SimonHelp& ' simon help screen
Dim Keys&(3, 1) ' keyboard key images 0=Q, 1=W, 2=S, 3=A
Dim Bslider& ' blue slider switch image
Dim Rslider& ' red slider switch image
Dim OnOff& ' on/off slider switch
Dim KeysXY%(3, 1) ' location of keyboard key images on play screen
Dim GameOver% ' boolean: true when game has ended
Dim 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 player
Dim Last$ ' the last tune played by the player
Dim Count% ' generic counter
Dim KeyPress$ ' any keys pressed by the player
Dim Pcolor~&(3) ' color pad base colors: 0=BLUE, 1=RED, 2=GREEN, 3=YELLOW

'----------------
'- MAIN PROGRAM -
'----------------

INITIALIZE ' prepare graphics, sounds and variables
Screen _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 screen
Cls ' remove black transparency
Do ' 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 LOOP
Loop ' MAIN GAME LOOP end

'--------------------
'- END MAIN PROGRAM -
'--------------------

'---------------------------
'- SUBROUTINES & FUNCTIONS -
'---------------------------

'----------------------------------------------------------------------------------------------------------------------
' DISPLAYHELP
Sub 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

'----------------------------------------------------------------------------------------------------------------------
' WAIT4RELEASE
Sub 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

'----------------------------------------------------------------------------------------------------------------------
' SIMONFILE
Sub 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

'----------------------------------------------------------------------------------------------------------------------
' PLAYGAME
Sub 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

'----------------------------------------------------------------------------------------------------------------------
' PRESSPAD
Sub 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

'----------------------------------------------------------------------------------------------------------------------
' INITIALIZE
Sub 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

'----------------------------------------------------------------------------------------------------------------------
' ENDGAME
Sub 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
Reply




Users browsing this thread: 1 Guest(s)