Author Topic: the Latest from UniKorn ProDucKions: SIMON 64!  (Read 4381 times)

0 Members and 1 Guest are viewing this topic.

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
the Latest from UniKorn ProDucKions: SIMON 64!
« on: January 18, 2019, 11:32:08 pm »
For my second release of 2019 I give you SIMON 64!
despite my best efforts I wasn't able to get the tones using SOUND like I wanted so there is an additional SFX file needed to play.
Also I wasn't able to get the images compact enough to store as DATA too, so we get another GFX file for that.

Code: QB64: [Select]
  1. 'Simon Game
  2. 'Cobalt 2019-01-13
  3. 'INformation:
  4. ' 4 levels:
  5. '  1-8 count pattern
  6. '  2-16 count pattern
  7. '  3-24 count pattern
  8. '  4-32 count pattern
  9. ' Speed increase at 5,9,13,22,29 counts
  10. ' Tones E,C#,A,E-O1 ????
  11. 'Program actually adapts based off users screen size(upto 640vl anyway)
  12.  
  13. '------------------Types-------------------------
  14. TYPE Game_Data
  15.  Level AS _BYTE '1-4(easy,med,Norm,Hard)
  16.  Speed AS _BYTE
  17.  Length AS _BYTE
  18.  ScrnHeight AS INTEGER 'computer's screen height
  19.  Height AS INTEGER 'games screen height
  20.  Factor AS SINGLE 'scale factor computer's height \640
  21.  GamePlay AS _BYTE 'has player pressed START\GO! button?
  22.  GO_GO_GO AS _BYTE 'game started flag\ displaying pattern flag
  23.  Yellow_On AS _BYTE
  24.  Last_Click AS _BYTE
  25.  Display AS _BYTE 'flag to display sequence
  26.  Time_It AS SINGLE 'after sequence display give player X# secs to enter each entry
  27.  Current_Light AS _BYTE 'where is player in sequence
  28.  Loser AS _BYTE
  29.  '---these pertain to click area colors-----------
  30.  Up_Arrow AS _UNSIGNED LONG
  31.  Down_Arrow AS _UNSIGNED LONG
  32.  Go_Button AS _UNSIGNED LONG
  33.  Yellow_Button AS _UNSIGNED LONG
  34.  Blue_Button AS _UNSIGNED LONG
  35.  Green_Button AS _UNSIGNED LONG
  36.  Red_Button AS _UNSIGNED LONG
  37.  '------------------------------------------------
  38. '------------------------------------------------
  39.  
  40. '-----------------Arrays and Consts--------------
  41. DIM SHARED Sequence(32) AS _BYTE, G AS Game_Data, SFX(5) AS LONG
  42. DIM SHARED Play_Back(32), Layer(7) AS LONG, Ti(5) AS LONG
  43. DIM SHARED StartUp%%
  44. CONST TRUE = -1, FALSE = NOT TRUE
  45. CONST EASY = 1, MED = 2, NORM = 3, HARD = 4
  46. CONST SLOWEST = 9, SLOWER = 7, SLOW = 6, FAST = 5, FASTER = 3, FASTEST = 1
  47. CONST RED = 15, BLUE = 31, GREEN = 63, YELLOW = 127, LOSER = 1, GO = 69
  48. '------------------------------------------------
  49.  
  50. '-------------Setup------------------------------
  51. G.ScrnHeight = _DESKTOPHEIGHT
  52. G.ScrnHeight = 640
  53. IF G.ScrnHeight >= 640 THEN G.Factor = 1 ELSE G.Factor = G.ScrnHeight / 640 - .0125
  54. '-------------layer loader-----------------------
  55. DIM Size(64) AS LONG, FOffset&(64)
  56. OPEN "simon.gfx" FOR BINARY AS #1
  57. GET #1, , c~%% 'number of records
  58. FOR w% = 1 TO c~%%
  59.  GET #1, , FOffset&(w%)
  60.  GET #1, , Size(w%)
  61.  FOffset&(w%) = FOffset&(w%) + 1
  62. '------------------------------------------------
  63. SCREEN _NEWIMAGE(640, 640 * G.Factor, 32)
  64. Layer(0) = _NEWIMAGE(640, 640 * G.Factor, 32)
  65. Layer(1) = LoadGFX&(FOffset&(4), Size(4))
  66. Layer(2) = LoadGFX&(FOffset&(3), Size(3))
  67. Layer(3) = LoadGFX&(FOffset&(5), Size(5))
  68. Layer(4) = LoadGFX&(FOffset&(2), Size(2))
  69. Layer(5) = LoadGFX&(FOffset&(1), Size(1))
  70. CLOSE #1 'close GFX file
  71. Layer(6) = _NEWIMAGE(640, 640 * G.Factor, 32)
  72. Layer(7) = _NEWIMAGE(640, 640 * G.Factor, 32)
  73. _CLEARCOLOR _RGB32(0, 0, 0), Layer(1)
  74. _CLEARCOLOR _RGB32(0, 0, 0), Layer(2)
  75. _CLEARCOLOR _RGB32(0, 0, 0), Layer(3)
  76. _CLEARCOLOR _RGB32(0, 0, 0), Layer(4)
  77. '--------------Sound Loader----------------------
  78. OPEN "simon.SFX" FOR BINARY AS #1
  79. GET #1, , c%%
  80. FOR w% = 1 TO c%%
  81.  GET #1, , FOffset&(w%)
  82.  GET #1, , Size(w%)
  83.  FOffset&(w%) = FOffset&(w%) + 1
  84. SFX(0) = LoadSFX&(FOffset&(3), Size(3)) '_SNDOPEN("RedTone.wav")
  85. SFX(1) = LoadSFX&(FOffset&(1), Size(1)) '_SNDOPEN("BlueTone.wav")
  86. SFX(2) = LoadSFX&(FOffset&(2), Size(2)) '_SNDOPEN("GreenTone.wav")
  87. SFX(3) = LoadSFX&(FOffset&(4), Size(4)) '_SNDOPEN("YellowTone.wav")
  88. SFX(4) = LoadSFX&(FOffset&(5), Size(5)) '_SNDOPEN("LoseTone.wav")
  89. CLOSE #1 'Close SFX file
  90.  
  91. FOR i%% = 0 TO 3
  92.  _SNDVOL SFX(i%%), .2
  93. _SNDVOL SFX(4), .5
  94. _DELAY .02
  95. G.Yellow_Button = _RGB32(255, 255, 0)
  96. G.Blue_Button = _RGB32(0, 0, 255)
  97. G.Green_Button = _RGB32(0, 255, 0)
  98. G.Red_Button = _RGB32(255, 0, 0)
  99. G.Up_Arrow = _RGB32(128, 0, 128)
  100. G.Down_Arrow = _RGB32(160, 0, 160)
  101. G.Go_Button = _RGB32(192, 0, 192)
  102. Ti(0) = _FREETIMER
  103. ON TIMER(Ti(0), .05) Start_Flash_Yellow
  104. Simon_Base
  105. Simon_Label
  106. Setup_Click_Area
  107. _TITLE "Simon 64! 2019 V0.8b"
  108. '------------------------------------------------
  109.  
  110. Start_Up_Values
  111.  
  112. '------------------Main Loop---------------------
  113.  nul% = _MOUSEINPUT
  114.  IF _MOUSEBUTTON(1) AND G.GO_GO_GO THEN
  115.   Simon_Mouse
  116.  
  117.  IF G.Display THEN _DELAY .75: G.GO_GO_GO = FALSE: Display_Sequence
  118.  IF G.GamePlay AND (NOT StartUp%%) AND G.Last_Click THEN
  119.   IF G.Last_Click = Sequence(G.Current_Light) THEN
  120.    IF G.Current_Light = G.Level * 8 THEN Winner%% = TRUE: exitflag%% = TRUE: G.Current_Light = 0
  121.    G.Current_Light = G.Current_Light + 1
  122.    IF G.Current_Light > G.Length THEN Add_Color
  123.   ELSE
  124.    G.Loser = TRUE
  125.    Start_Tone LOSER
  126.    Build_Display
  127.    LOCATE 1, 1: PRINT G.Last_Click; Sequence(G.Current_Light); G.Current_Light
  128.    _DELAY 2.5
  129.    Stop_Tone LOSER
  130.    Start_Up_Values
  131.   END IF
  132.  IF G.Length = 5 THEN G.Speed = SLOWER
  133.  IF G.Length = 9 THEN G.Speed = SLOW
  134.  IF G.Length = 14 THEN G.Speed = FAST
  135.  IF G.Length = 22 THEN G.Speed = FASTER
  136.  IF G.Length = 29 THEN G.Speed = FASTEST
  137.  Build_Display
  138.  
  139.  _DELAY .05
  140.  DO: LOOP WHILE _MOUSEINPUT 'clear mouse buffer
  141.  IF INKEY$ = CHR$(27) THEN exitflag%% = TRUE
  142.  G.Last_Click = FALSE
  143. LOOP UNTIL exitflag%%
  144. '------------------------------------------------
  145. IF Winner%% THEN PRINT "YOU WIN!"
  146.  
  147. SUB Lose_Game_Sound
  148.  FOR i%% = 0 TO 15
  149.   SOUND 142, .8 'lose
  150.   SOUND 72, .6 'lose
  151.  
  152. SUB Red_Sound (t%%)
  153.  FOR i%% = o TO t%%
  154.   SOUND 440, 1 'Red
  155.   _DELAY .015
  156.  NEXT i%%
  157.  
  158. SUB Blue_Sound (t%%)
  159.  FOR i%% = o TO t%%
  160.   SOUND 330, 1 'Blue
  161.   _DELAY .015
  162.  NEXT i%%
  163.  
  164. SUB Green_Sound (t%%)
  165.  FOR i%% = o TO t%%
  166.   SOUND 294, 1 'Green
  167.   _DELAY .015
  168.  NEXT i%%
  169.  
  170. SUB Yellow_Sound (t%%)
  171.  FOR i%% = o TO t%%
  172.   SOUND 277, 1 'Yellow
  173.   _DELAY .015
  174.  NEXT i%%
  175.  
  176. SUB Yellow_Light
  177.  _PUTIMAGE (0, 0)-STEP(320 * G.Factor, 320 * G.Factor), Layer(3), Layer(0), (0, 0)-(146, 146)
  178.  
  179. SUB Green_Light
  180.  _PUTIMAGE (320 * G.Factor, 320 * G.Factor)-STEP(320 * G.Factor, 320 * G.Factor), Layer(3), Layer(0), (147, 147)-(293, 293)
  181.  
  182. SUB Blue_Light
  183.  _PUTIMAGE (320 * G.Factor, 0)-STEP(320 * G.Factor, 320 * G.Factor), Layer(3), Layer(0), (147, 0)-(293, 146)
  184.  
  185. SUB Red_Light
  186.  _PUTIMAGE (0, 320 * G.Factor)-STEP(320 * G.Factor, 320 * G.Factor), Layer(3), Layer(0), (0, 147)-(146, 293)
  187.  
  188. SUB Simon_Base
  189.  _PUTIMAGE (0, 0)-STEP(640 * G.Factor, 640 * G.Factor), Layer(1), Layer(7)
  190.  
  191. SUB Add_Color ()
  192.  Result%% = INT(RND * 100)
  193.  G.Length = G.Length + 1 'add one level to sequence
  194.  G.Display = TRUE 'tell main loop to display new sequence
  195.  G.Current_Light = 1 'start player at first entry
  196.  SELECT CASE Result%%
  197.   CASE 0 TO 24
  198.    Sequence(G.Length) = YELLOW
  199.   CASE 25 TO 49
  200.    Sequence(G.Length) = BLUE
  201.   CASE 50 TO 74
  202.    Sequence(G.Length) = RED
  203.   CASE 75 TO 99
  204.    Sequence(G.Length) = GREEN
  205.  
  206. SUB Simon_Label
  207.  x% = 170 * G.Factor
  208.  y% = 158 * G.Factor
  209.  _PUTIMAGE (x%, y%)-STEP(294 * G.Factor, 294 * G.Factor), Layer(2), Layer(7)
  210.  
  211. SUB Level_LED
  212.  x% = 170 * G.Factor
  213.  y% = 284 * G.Factor
  214.  _PUTIMAGE (x%, y%)-STEP(294 * G.Factor, 37 * G.Factor), Layer(4), Layer(0), (0, 32)-(127, 47)
  215.  SELECT CASE G.Level
  216.   CASE EASY
  217.    _PUTIMAGE (x% + 60, y%)-STEP(45 * G.Factor, 37 * G.Factor), Layer(4), Layer(0), (3, 16)-(22, 31)
  218.   CASE MED
  219.    _PUTIMAGE (x% + 107, y%)-STEP(44 * G.Factor, 37 * G.Factor), Layer(4), Layer(0), (23, 16)-(42, 31)
  220.   CASE NORM
  221.    _PUTIMAGE (x% + 152, y%)-STEP(44 * G.Factor, 37 * G.Factor), Layer(4), Layer(0), (43, 16)-(62, 31)
  222.   CASE HARD
  223.    _PUTIMAGE (x% + 198, y%)-STEP(45 * G.Factor, 37 * G.Factor), Layer(4), Layer(0), (63, 16)-(82, 31)
  224.  
  225. SUB Level_Adjust_Arrows
  226.  x% = 196 * G.Factor
  227.  y% = 284 * G.Factor
  228.  _PUTIMAGE (x%, y%)-STEP(22 * G.Factor, 32 * G.Factor), Layer(4), Layer(0), (85, 0)-(96, 15)
  229.  _PUTIMAGE (x% + 224, y%)-STEP(22 * G.Factor, 32 * G.Factor), Layer(4), Layer(0), (85, 16)-(96, 31)
  230.  _DEST Layer(6)
  231.  LINE (x%, y%)-STEP(22 * G.Factor, 32 * G.Factor), G.Down_Arrow, BF
  232.  LINE (x% + 224, y%)-STEP(22 * G.Factor, 32 * G.Factor), G.Up_Arrow, BF
  233.  
  234. SUB Start_Button (state%%)
  235.  x% = 292 * G.Factor
  236.  y% = 360 * G.Factor
  237.  IF NOT state%% THEN
  238.   _PUTIMAGE (x%, y%)-STEP(52 * G.Factor, 32 * G.Factor), Layer(4), Layer(0), (97, 0)-(123, 15)
  239.   _PUTIMAGE (x%, y%)-STEP(52 * G.Factor, 32 * G.Factor), Layer(4), Layer(0), (97, 16)-(123, 31)
  240.  _DEST Layer(6)
  241.  LINE (x%, y%)-STEP(52 * G.Factor, 32 * G.Factor), G.Go_Button, BF
  242.  
  243. SUB Button_Down_Lock
  244.  ButtonDown%% = TRUE
  245.  '--------lock mouse until button release---------
  246.  'stops program progess but not timer progress
  247.  'player could lose if they hold button down.
  248.  'this IS ment to be.
  249.  IF G.GO_GO_GO THEN Press_Color: Start_Tone G.Last_Click
  250.  DO
  251.    IF NOT _MOUSEBUTTON(1) THEN ButtonDown%% = FALSE
  252.   END IF
  253.   _DELAY .001
  254.  LOOP WHILE ButtonDown%%
  255.  Stop_Tone G.Last_Click
  256.  '------------------------------------------------
  257.  Build_Display
  258.  
  259. SUB Start_Flash_Yellow
  260.  G.Yellow_On = G.Yellow_On + 1
  261.  IF G.Yellow_On > 19 THEN G.Yellow_On = 1
  262.  
  263. SUB Setup_Click_Area
  264.  _PUTIMAGE (0, 0)-STEP(640 * G.Factor, 640 * G.Factor), Layer(5), Layer(6)
  265.  
  266. SUB Simon_Mouse
  267.   CASE G.Up_Arrow
  268.    IF G.Level < 4 AND (NOT G.GamePlay) THEN G.Level = G.Level + 1
  269.   CASE G.Down_Arrow
  270.    IF G.Level > 1 AND (NOT G.GamePlay) THEN G.Level = G.Level - 1
  271.   CASE G.Go_Button
  272.    IF NOT G.GamePlay THEN
  273.     G.GamePlay = TRUE
  274.     StartUp%% = TRUE
  275.     TIMER(Ti(0)) ON
  276.     G.Last_Click = GO
  277.    END IF
  278.   CASE G.Yellow_Button
  279.    IF StartUp%% THEN TIMER(Ti(0)) OFF: G.Yellow_On = FALSE: StartUp%% = FALSE: Add_Color
  280.    G.Last_Click = YELLOW
  281.   CASE G.Blue_Button
  282.    G.Last_Click = BLUE
  283.   CASE G.Green_Button
  284.    G.Last_Click = GREEN
  285.   CASE G.Red_Button
  286.    G.Last_Click = RED
  287.  Button_Down_Lock
  288.  
  289. SUB Display_Sequence
  290.  FOR i%% = 1 TO G.Length
  291.   _PUTIMAGE , Layer(7), Layer(0)
  292.   Level_LED
  293.   Level_Adjust_Arrows
  294.   Start_Button G.GamePlay
  295.   Start_Tone Sequence(i%%)
  296.   SELECT CASE Sequence(i%%)
  297.    CASE YELLOW
  298.     Yellow_Light
  299.    CASE BLUE
  300.     Blue_Light
  301.    CASE GREEN
  302.     Green_Light
  303.    CASE RED
  304.     Red_Light
  305.   _PUTIMAGE , Layer(0), _DISPLAY
  306.   _DELAY G.Speed / 12
  307.   Stop_Tone Sequence(i%%)
  308.  
  309.   Build_Display
  310.  
  311.   _DELAY G.Speed / 20
  312.  NEXT i%%
  313.  G.Display = FALSE 'done displaying sequence
  314.  G.Time_It = TIMER + .25 'start player input timer +.25 for delay
  315.  _DELAY .25 'short pause before player can start entering sequence
  316.  G.GO_GO_GO = TRUE 'allow player to have mouse actions
  317.  G.Last_Click = FALSE
  318.  
  319. SUB Press_Color
  320.  _PUTIMAGE , Layer(7), Layer(0)
  321.  
  322.  SELECT CASE G.Last_Click
  323.   CASE YELLOW
  324.    Yellow_Light
  325.   CASE BLUE
  326.    Blue_Light
  327.   CASE GREEN
  328.    Green_Light
  329.   CASE RED
  330.    Red_Light
  331.  
  332.  Level_LED
  333.  Level_Adjust_Arrows
  334.  Start_Button G.GamePlay
  335.  _PUTIMAGE , Layer(0), _DISPLAY
  336.  
  337. SUB Start_Tone (id%%)
  338.  SELECT CASE id%%
  339.   CASE LOSER
  340.    _SNDLOOP SFX(4)
  341.   CASE YELLOW
  342.    _SNDLOOP SFX(3)
  343.   CASE BLUE
  344.    _SNDLOOP SFX(1)
  345.   CASE GREEN
  346.    _SNDLOOP SFX(2)
  347.   CASE RED
  348.    _SNDLOOP SFX(0)
  349.  
  350. SUB Stop_Tone (id%%)
  351.  SELECT CASE id%%
  352.   CASE LOSER
  353.    _SNDSTOP SFX(4)
  354.   CASE YELLOW
  355.    _SNDSTOP SFX(3)
  356.   CASE BLUE
  357.    _SNDSTOP SFX(1)
  358.   CASE GREEN
  359.    _SNDSTOP SFX(2)
  360.   CASE RED
  361.    _SNDSTOP SFX(0)
  362.  
  363. SUB Build_Display
  364.  '---------Build Display--------------------------
  365.  _PUTIMAGE , Layer(7), Layer(0)
  366.  IF StartUp%% AND G.Yellow_On > 10 THEN Yellow_Light
  367.  IF G.Loser THEN Red_Light
  368.  Level_LED
  369.  Level_Adjust_Arrows
  370.  Start_Button G.GamePlay
  371.  _PUTIMAGE , Layer(0), _DISPLAY
  372.  '------------------------------------------------
  373.  
  374. SUB Start_Up_Values
  375.  '----------------Start Up Values ----------------
  376.  G.Level = 1
  377.  G.Speed = SLOWEST
  378.  G.Length = 0
  379.  G.Loser = FALSE
  380.  G.GamePlay = FALSE
  381.  G.GO_GO_GO = TRUE
  382.  G.Current_Light = 0
  383.  G.Display = FALSE
  384.  _SOURCE Layer(6)
  385.  '------------------------------------------------
  386.  
  387. FUNCTION LoadGFX& (Foff&, Size&)
  388.  IF _FILEEXISTS("temp.dat") THEN KILL "temp.dat"
  389.  OPEN "temp.dat" FOR BINARY AS #3
  390.  dat$ = SPACE$(Size&)
  391.  GET #1, Foff&, dat$
  392.  PUT #3, , dat$
  393.  CLOSE #3
  394.  LoadGFX& = _LOADIMAGE("temp.dat", 32)
  395.  
  396. FUNCTION LoadSFX& (Foff&, Size&)
  397.  IF _FILEEXISTS("temp.dat") THEN KILL "temp.dat"
  398.  OPEN "temp.dat" FOR BINARY AS #3
  399.  dat$ = SPACE$(Size&)
  400.  GET #1, Foff&, dat$
  401.  PUT #3, , dat$
  402.  CLOSE #3
  403.  LoadSFX& = _SNDOPEN("temp.dat")
  404.  

4 levels of play with patterns of up to 8,16,24, and 32. (think I made it to 14 once)  I'm still tweeking the speed, seems a little too slow in the beginning. I also have not implemented the time restraint so it doesn't matter how long it takes you to enter the sequence as of yet. controls are entirely mouse driven right now.  use the 2 black arrows to raise or lower the level (green, yellow, amber, and red 'LED's) then press START. you will see the Yellow Button flashing, press that once (careful cause if you accidentally double click you lose, still have to address that.) then the sequence begins.
Haven't figured out a nice winner screen or anything yet so right now it just prints "YOU WIN" and quits. If you lose you get a nice loud tone and everything resets(but doesn't quit the game) if you get tired of messing with it, ESC quits though if its in a sequence display you will have to wait it out.(or just close the window)

the max vertical size is 640. I have limitedly tested reduced screen sizes(to 480) and the automatic scaling seems to work. its hard coded to max at 640 vertical at the present and may not scale correctly on the horizontal beyond that.
* Simon.GFX (Filesize: 273.46 KB, Downloads: 231)
* Simon.SFX (Filesize: 87.93 KB, Downloads: 256)
Granted after becoming radioactive I only have a half-life!

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: the Latest from UniKorn ProDucKions: SIMON 64!
« Reply #1 on: January 19, 2019, 10:35:29 am »
Minor update, added the time limit on sequence entry. Pretty generous at 8 seconds.
 couple other tweaks as well, but nothing major. Wont be giving this the 1.0 go ahead until I figure something out for a winning game.

anybody found any hiccups yet? or anything that just doesn't feel smooth?

Code: QB64: [Select]
  1. 'Simon Game
  2. 'Cobalt 2019-01-13
  3. 'INformation:
  4. ' 4 levels:
  5. '  1-8 count pattern
  6. '  2-16 count pattern
  7. '  3-24 count pattern
  8. '  4-32 count pattern
  9. ' Speed increase at 5,9,13,22,29 counts
  10. ' Tones E,C#,A,E-O1 ????
  11. 'Program actually adapts based off users screen size(upto 640vl anyway)
  12.  
  13. '------------------Types-------------------------
  14. TYPE Game_Data
  15.  Level AS _BYTE '1-4(easy,med,Norm,Hard)
  16.  Speed AS _BYTE
  17.  Length AS _BYTE
  18.  ScrnHeight AS INTEGER 'computer's screen height
  19.  Height AS INTEGER 'games screen height
  20.  Factor AS SINGLE 'scale factor computer's height \640
  21.  GamePlay AS _BYTE 'has player pressed START\GO! button?
  22.  GO_GO_GO AS _BYTE 'game started flag\ displaying pattern flag
  23.  Yellow_On AS _BYTE
  24.  Last_Click AS _BYTE
  25.  Display AS _BYTE 'flag to display sequence
  26.  Time_It AS SINGLE 'after sequence display give player X# secs to enter each entry
  27.  Current_Light AS _BYTE 'where is player in sequence
  28.  Loser AS _BYTE
  29.  '---these pertain to click area colors-----------
  30.  Up_Arrow AS _UNSIGNED LONG
  31.  Down_Arrow AS _UNSIGNED LONG
  32.  Go_Button AS _UNSIGNED LONG
  33.  Yellow_Button AS _UNSIGNED LONG
  34.  Blue_Button AS _UNSIGNED LONG
  35.  Green_Button AS _UNSIGNED LONG
  36.  Red_Button AS _UNSIGNED LONG
  37.  '------------------------------------------------
  38. '------------------------------------------------
  39.  
  40. '-----------------Arrays and Consts--------------
  41. DIM SHARED Sequence(32) AS _BYTE, G AS Game_Data, SFX(5) AS LONG
  42. DIM SHARED Play_Back(32), Layer(7) AS LONG, Ti(5) AS LONG
  43. DIM SHARED StartUp%%
  44. CONST TRUE = -1, FALSE = NOT TRUE
  45. CONST EASY = 1, MED = 2, NORM = 3, HARD = 4
  46. CONST SLOWEST = 9, SLOWER = 7, SLOW = 6, FAST = 5, FASTER = 3, FASTEST = 1
  47. CONST RED = 15, BLUE = 31, GREEN = 63, YELLOW = 127, LOSER = 1, GO = 69
  48. '------------------------------------------------
  49.  
  50. '-------------Setup------------------------------
  51. G.ScrnHeight = _DESKTOPHEIGHT
  52. G.ScrnHeight = 640
  53. IF G.ScrnHeight >= 640 THEN G.Factor = 1 ELSE G.Factor = G.ScrnHeight / 640 - .0125
  54. '-------------layer loader-----------------------
  55. DIM Size(64) AS LONG, FOffset&(64)
  56. OPEN "simon.gfx" FOR BINARY AS #1
  57. GET #1, , c~%% 'number of records
  58. FOR w% = 1 TO c~%%
  59.  GET #1, , FOffset&(w%)
  60.  GET #1, , Size(w%)
  61.  FOffset&(w%) = FOffset&(w%) + 1
  62. '------------------------------------------------
  63. SCREEN _NEWIMAGE(640, 640 * G.Factor, 32)
  64. Layer(0) = _NEWIMAGE(640, 640 * G.Factor, 32)
  65. Layer(1) = LoadGFX&(FOffset&(4), Size(4))
  66. Layer(2) = LoadGFX&(FOffset&(3), Size(3))
  67. Layer(3) = LoadGFX&(FOffset&(5), Size(5))
  68. Layer(4) = LoadGFX&(FOffset&(2), Size(2))
  69. Layer(5) = LoadGFX&(FOffset&(1), Size(1))
  70. CLOSE #1 'close GFX file
  71. Layer(6) = _NEWIMAGE(640, 640 * G.Factor, 32)
  72. Layer(7) = _NEWIMAGE(640, 640 * G.Factor, 32)
  73. _CLEARCOLOR _RGB32(0, 0, 0), Layer(1)
  74. _CLEARCOLOR _RGB32(0, 0, 0), Layer(2)
  75. _CLEARCOLOR _RGB32(0, 0, 0), Layer(3)
  76. _CLEARCOLOR _RGB32(0, 0, 0), Layer(4)
  77. '--------------Sound Loader----------------------
  78. OPEN "simon.SFX" FOR BINARY AS #1
  79. GET #1, , c%%
  80. FOR w% = 1 TO c%%
  81.  GET #1, , FOffset&(w%)
  82.  GET #1, , Size(w%)
  83.  FOffset&(w%) = FOffset&(w%) + 1
  84. SFX(0) = LoadSFX&(FOffset&(3), Size(3)) '_SNDOPEN("RedTone.wav")
  85. SFX(1) = LoadSFX&(FOffset&(1), Size(1)) '_SNDOPEN("BlueTone.wav")
  86. SFX(2) = LoadSFX&(FOffset&(2), Size(2)) '_SNDOPEN("GreenTone.wav")
  87. SFX(3) = LoadSFX&(FOffset&(4), Size(4)) '_SNDOPEN("YellowTone.wav")
  88. SFX(4) = LoadSFX&(FOffset&(5), Size(5)) '_SNDOPEN("LoseTone.wav")
  89. CLOSE #1 'Close SFX file
  90.  
  91. FOR i%% = 0 TO 3
  92.  _SNDVOL SFX(i%%), .2
  93. _SNDVOL SFX(4), .2
  94. _DELAY .02
  95. G.Yellow_Button = _RGB32(255, 255, 0)
  96. G.Blue_Button = _RGB32(0, 0, 255)
  97. G.Green_Button = _RGB32(0, 255, 0)
  98. G.Red_Button = _RGB32(255, 0, 0)
  99. G.Up_Arrow = _RGB32(128, 0, 128)
  100. G.Down_Arrow = _RGB32(160, 0, 160)
  101. G.Go_Button = _RGB32(192, 0, 192)
  102. Ti(0) = _FREETIMER
  103. ON TIMER(Ti(0), .05) Start_Flash_Yellow
  104. Simon_Base
  105. Simon_Label
  106. Setup_Click_Area
  107. _SOURCE Layer(6)
  108. _TITLE "Simon 64! 2019 V0.9b"
  109. '------------------------------------------------
  110.  
  111. Start_Up_Values
  112.  
  113. '------------------Main Loop---------------------
  114.  nul% = _MOUSEINPUT
  115.  IF _MOUSEBUTTON(1) AND G.GO_GO_GO THEN
  116.   Simon_Mouse
  117.  
  118.  IF G.Display THEN _DELAY .75: G.GO_GO_GO = FALSE: Display_Sequence
  119.  IF G.GamePlay AND (NOT StartUp%%) AND G.Last_Click THEN
  120.   IF G.Last_Click = Sequence(G.Current_Light) THEN
  121.    IF G.Current_Light = G.Level * 8 THEN Winner%% = TRUE: exitflag%% = TRUE: G.Current_Light = 0
  122.    G.Current_Light = G.Current_Light + 1
  123.    IF G.Current_Light > G.Length THEN Add_Color
  124.   ELSE
  125.    G.Loser = TRUE
  126.    Start_Tone LOSER
  127.    Build_Display
  128.    _DELAY 2.5
  129.    Stop_Tone LOSER
  130.    Start_Up_Values
  131.   END IF
  132.  
  133.  IF G.Length = 5 THEN G.Speed = SLOWER
  134.  IF G.Length = 9 THEN G.Speed = SLOW
  135.  IF G.Length = 14 THEN G.Speed = FAST
  136.  IF G.Length = 22 THEN G.Speed = FASTER
  137.  IF G.Length = 29 THEN G.Speed = FASTEST
  138.  
  139.  IF G.Time_It <> 0 AND TIMER > G.Time_It + 8 THEN
  140.   G.Loser = TRUE
  141.   Start_Tone LOSER
  142.   Build_Display
  143.   _DELAY 2.5
  144.   Stop_Tone LOSER
  145.   Start_Up_Values
  146.  
  147.  Build_Display
  148.  
  149.  
  150.  _DELAY .05
  151.  DO: LOOP WHILE _MOUSEINPUT 'clear mouse buffer
  152.  IF INKEY$ = CHR$(27) THEN exitflag%% = TRUE
  153.  G.Last_Click = FALSE
  154. LOOP UNTIL exitflag%%
  155. '------------------------------------------------
  156. IF Winner%% THEN PRINT "YOU WIN!"
  157.  
  158. SUB Lose_Game_Sound
  159.  FOR i%% = 0 TO 15
  160.   SOUND 142, .8 'lose
  161.   SOUND 72, .6 'lose
  162.  
  163. SUB Red_Sound (t%%)
  164.  FOR i%% = o TO t%%
  165.   SOUND 440, 1 'Red
  166.   _DELAY .015
  167.  NEXT i%%
  168.  
  169. SUB Blue_Sound (t%%)
  170.  FOR i%% = o TO t%%
  171.   SOUND 330, 1 'Blue
  172.   _DELAY .015
  173.  NEXT i%%
  174.  
  175. SUB Green_Sound (t%%)
  176.  FOR i%% = o TO t%%
  177.   SOUND 294, 1 'Green
  178.   _DELAY .015
  179.  NEXT i%%
  180.  
  181. SUB Yellow_Sound (t%%)
  182.  FOR i%% = o TO t%%
  183.   SOUND 277, 1 'Yellow
  184.   _DELAY .015
  185.  NEXT i%%
  186.  
  187. SUB Yellow_Light
  188.  _PUTIMAGE (0, 0)-STEP(320 * G.Factor, 320 * G.Factor), Layer(3), Layer(0), (0, 0)-(146, 146)
  189.  
  190. SUB Green_Light
  191.  _PUTIMAGE (320 * G.Factor, 320 * G.Factor)-STEP(320 * G.Factor, 320 * G.Factor), Layer(3), Layer(0), (147, 147)-(293, 293)
  192.  
  193. SUB Blue_Light
  194.  _PUTIMAGE (320 * G.Factor, 0)-STEP(320 * G.Factor, 320 * G.Factor), Layer(3), Layer(0), (147, 0)-(293, 146)
  195.  
  196. SUB Red_Light
  197.  _PUTIMAGE (0, 320 * G.Factor)-STEP(320 * G.Factor, 320 * G.Factor), Layer(3), Layer(0), (0, 147)-(146, 293)
  198.  
  199. SUB Simon_Base
  200.  _PUTIMAGE (0, 0)-STEP(640 * G.Factor, 640 * G.Factor), Layer(1), Layer(7)
  201.  
  202. SUB Add_Color ()
  203.  Result%% = INT(RND * 100)
  204.  G.Length = G.Length + 1 'add one level to sequence
  205.  G.Display = TRUE 'tell main loop to display new sequence
  206.  G.Current_Light = 1 'start player at first entry
  207.  SELECT CASE Result%%
  208.   CASE 0 TO 24
  209.    Sequence(G.Length) = YELLOW
  210.   CASE 25 TO 49
  211.    Sequence(G.Length) = BLUE
  212.   CASE 50 TO 74
  213.    Sequence(G.Length) = RED
  214.   CASE 75 TO 99
  215.    Sequence(G.Length) = GREEN
  216.  
  217. SUB Simon_Label
  218.  x% = 170 * G.Factor
  219.  y% = 158 * G.Factor
  220.  _PUTIMAGE (x%, y%)-STEP(294 * G.Factor, 294 * G.Factor), Layer(2), Layer(7)
  221.  
  222. SUB Level_LED
  223.  x% = 170 * G.Factor
  224.  y% = 284 * G.Factor
  225.  _PUTIMAGE (x%, y%)-STEP(294 * G.Factor, 37 * G.Factor), Layer(4), Layer(0), (0, 32)-(127, 47)
  226.  SELECT CASE G.Level
  227.   CASE EASY
  228.    _PUTIMAGE (x% + 60, y%)-STEP(45 * G.Factor, 37 * G.Factor), Layer(4), Layer(0), (3, 16)-(22, 31)
  229.   CASE MED
  230.    _PUTIMAGE (x% + 107, y%)-STEP(44 * G.Factor, 37 * G.Factor), Layer(4), Layer(0), (23, 16)-(42, 31)
  231.   CASE NORM
  232.    _PUTIMAGE (x% + 152, y%)-STEP(44 * G.Factor, 37 * G.Factor), Layer(4), Layer(0), (43, 16)-(62, 31)
  233.   CASE HARD
  234.    _PUTIMAGE (x% + 198, y%)-STEP(45 * G.Factor, 37 * G.Factor), Layer(4), Layer(0), (63, 16)-(82, 31)
  235.  
  236. SUB Level_Adjust_Arrows
  237.  x% = 196 * G.Factor
  238.  y% = 284 * G.Factor
  239.  _PUTIMAGE (x%, y%)-STEP(22 * G.Factor, 32 * G.Factor), Layer(4), Layer(0), (85, 0)-(96, 15)
  240.  _PUTIMAGE (x% + 224, y%)-STEP(22 * G.Factor, 32 * G.Factor), Layer(4), Layer(0), (85, 16)-(96, 31)
  241.  _DEST Layer(6)
  242.  LINE (x%, y%)-STEP(22 * G.Factor, 32 * G.Factor), G.Down_Arrow, BF
  243.  LINE (x% + 224, y%)-STEP(22 * G.Factor, 32 * G.Factor), G.Up_Arrow, BF
  244.  
  245. SUB Start_Button (state%%)
  246.  x% = 292 * G.Factor
  247.  y% = 360 * G.Factor
  248.  IF NOT state%% THEN
  249.   _PUTIMAGE (x%, y%)-STEP(52 * G.Factor, 32 * G.Factor), Layer(4), Layer(0), (97, 0)-(123, 15)
  250.   _PUTIMAGE (x%, y%)-STEP(52 * G.Factor, 32 * G.Factor), Layer(4), Layer(0), (97, 16)-(123, 31)
  251.  _DEST Layer(6)
  252.  LINE (x%, y%)-STEP(52 * G.Factor, 32 * G.Factor), G.Go_Button, BF
  253.  
  254. SUB Button_Down_Lock
  255.  ButtonDown%% = TRUE
  256.  '--------lock mouse until button release---------
  257.  'stops program progess but not timer progress
  258.  'player could lose if they hold button down.
  259.  'this IS ment to be.
  260.  IF G.GO_GO_GO THEN Press_Color: Start_Tone G.Last_Click
  261.  DO
  262.    IF NOT _MOUSEBUTTON(1) THEN ButtonDown%% = FALSE
  263.   END IF
  264.   _DELAY .001
  265.  LOOP WHILE ButtonDown%%
  266.  Stop_Tone G.Last_Click
  267.  '------------------------------------------------
  268.  Build_Display
  269.  
  270. SUB Start_Flash_Yellow
  271.  G.Yellow_On = G.Yellow_On + 1
  272.  IF G.Yellow_On > 19 THEN G.Yellow_On = 1
  273.  
  274. SUB Setup_Click_Area
  275.  _PUTIMAGE (0, 0)-STEP(640 * G.Factor, 640 * G.Factor), Layer(5), Layer(6)
  276.  
  277. SUB Simon_Mouse
  278.   CASE G.Up_Arrow
  279.    IF G.Level < 4 AND (NOT G.GamePlay) THEN G.Level = G.Level + 1
  280.   CASE G.Down_Arrow
  281.    IF G.Level > 1 AND (NOT G.GamePlay) THEN G.Level = G.Level - 1
  282.   CASE G.Go_Button
  283.    IF NOT G.GamePlay THEN
  284.     G.GamePlay = TRUE
  285.     StartUp%% = TRUE
  286.     TIMER(Ti(0)) ON
  287.     G.Last_Click = GO
  288.    END IF
  289.   CASE G.Yellow_Button
  290.    IF StartUp%% THEN TIMER(Ti(0)) OFF: G.Yellow_On = FALSE: StartUp%% = FALSE: Add_Color
  291.    G.Last_Click = YELLOW
  292.   CASE G.Blue_Button
  293.    G.Last_Click = BLUE
  294.   CASE G.Green_Button
  295.    G.Last_Click = GREEN
  296.   CASE G.Red_Button
  297.    G.Last_Click = RED
  298.  Button_Down_Lock
  299.  
  300. SUB Display_Sequence
  301.  FOR i%% = 1 TO G.Length
  302.   _PUTIMAGE , Layer(7), Layer(0)
  303.   Level_LED
  304.   Level_Adjust_Arrows
  305.   Start_Button G.GamePlay
  306.   Start_Tone Sequence(i%%)
  307.   SELECT CASE Sequence(i%%)
  308.    CASE YELLOW
  309.     Yellow_Light
  310.    CASE BLUE
  311.     Blue_Light
  312.    CASE GREEN
  313.     Green_Light
  314.    CASE RED
  315.     Red_Light
  316.   _PUTIMAGE , Layer(0), _DISPLAY
  317.   _DELAY G.Speed / 12
  318.   Stop_Tone Sequence(i%%)
  319.  
  320.   Build_Display
  321.  
  322.   _DELAY G.Speed / 20
  323.  NEXT i%%
  324.  G.Display = FALSE 'done displaying sequence
  325.  G.Time_It = TIMER + .15 'start player input timer +.25 for delay
  326.  _DELAY .15 'short pause before player can start entering sequence
  327.  G.GO_GO_GO = TRUE 'allow player to have mouse actions
  328.  G.Last_Click = FALSE
  329.  
  330. SUB Press_Color
  331.  _PUTIMAGE , Layer(7), Layer(0)
  332.  
  333.  SELECT CASE G.Last_Click
  334.   CASE YELLOW
  335.    Yellow_Light
  336.   CASE BLUE
  337.    Blue_Light
  338.   CASE GREEN
  339.    Green_Light
  340.   CASE RED
  341.    Red_Light
  342.  
  343.  Level_LED
  344.  Level_Adjust_Arrows
  345.  Start_Button G.GamePlay
  346.  _PUTIMAGE , Layer(0), _DISPLAY
  347.  
  348. SUB Start_Tone (id%%)
  349.  SELECT CASE id%%
  350.   CASE LOSER
  351.    _SNDLOOP SFX(4)
  352.   CASE YELLOW
  353.    _SNDLOOP SFX(3)
  354.   CASE BLUE
  355.    _SNDLOOP SFX(1)
  356.   CASE GREEN
  357.    _SNDLOOP SFX(2)
  358.   CASE RED
  359.    _SNDLOOP SFX(0)
  360.  
  361. SUB Stop_Tone (id%%)
  362.  SELECT CASE id%%
  363.   CASE LOSER
  364.    _SNDSTOP SFX(4)
  365.   CASE YELLOW
  366.    _SNDSTOP SFX(3)
  367.   CASE BLUE
  368.    _SNDSTOP SFX(1)
  369.   CASE GREEN
  370.    _SNDSTOP SFX(2)
  371.   CASE RED
  372.    _SNDSTOP SFX(0)
  373.  
  374. SUB Build_Display
  375.  '---------Build Display--------------------------
  376.  _PUTIMAGE , Layer(7), Layer(0)
  377.  IF StartUp%% AND G.Yellow_On > 10 THEN Yellow_Light
  378.  IF G.Loser THEN Red_Light
  379.  Level_LED
  380.  Level_Adjust_Arrows
  381.  Start_Button G.GamePlay
  382.  _PUTIMAGE , Layer(0), _DISPLAY
  383.  '------------------------------------------------
  384.  
  385. SUB Start_Up_Values
  386.  '----------------Start Up Values ----------------
  387.  G.Level = 1
  388.  G.Speed = SLOWEST
  389.  G.Length = 0
  390.  G.Loser = FALSE
  391.  G.GamePlay = FALSE
  392.  G.GO_GO_GO = TRUE
  393.  G.Current_Light = 0
  394.  G.Display = FALSE
  395.  G.Time_It = 0
  396.  '------------------------------------------------
  397.  
  398. FUNCTION LoadGFX& (Foff&, Size&)
  399.  IF _FILEEXISTS("temp.dat") THEN KILL "temp.dat"
  400.  OPEN "temp.dat" FOR BINARY AS #3
  401.  dat$ = SPACE$(Size&)
  402.  GET #1, Foff&, dat$
  403.  PUT #3, , dat$
  404.  CLOSE #3
  405.  LoadGFX& = _LOADIMAGE("temp.dat", 32)
  406.  
  407. FUNCTION LoadSFX& (Foff&, Size&)
  408.  IF _FILEEXISTS("temp.dat") THEN KILL "temp.dat"
  409.  OPEN "temp.dat" FOR BINARY AS #3
  410.  dat$ = SPACE$(Size&)
  411.  GET #1, Foff&, dat$
  412.  PUT #3, , dat$
  413.  CLOSE #3
  414.  LoadSFX& = _SNDOPEN("temp.dat")
  415.  
Granted after becoming radioactive I only have a half-life!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: the Latest from UniKorn ProDucKions: SIMON 64!
« Reply #2 on: January 19, 2019, 04:04:42 pm »
Working fine on my system. There's more?

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: the Latest from UniKorn ProDucKions: SIMON 64!
« Reply #3 on: January 19, 2019, 09:50:43 pm »
Working fine on my system. There's more?

technically, No. But I just feel it might be more interesting if there was some kind of victory screen if you complete the sequence to the level count(8,16,24,32). maybe a different screen for each level. or just something. Just having a hard time deciding on just what kind of image to use.
Granted after becoming radioactive I only have a half-life!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: the Latest from UniKorn ProDucKions: SIMON 64!
« Reply #4 on: January 20, 2019, 07:14:42 pm »
Working fine on my system. There's more?

technically, No. But I just feel it might be more interesting if there was some kind of victory screen if you complete the sequence to the level count(8,16,24,32). maybe a different screen for each level. or just something. Just having a hard time deciding on just what kind of image to use.

What does Simon say? ;-))