Author Topic: Gapper Playable to level 5  (Read 4829 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
Gapper Playable to level 5
« on: November 14, 2021, 10:14:55 pm »
ok so its like super easy right now as the seeker speed doesn't scale yet. and I say up to level 5 because for some reason it wont complete all the boxes at that level.

@bplus any idea why BoxSurrounded stops working on that level?

Arrow Keys move your icon which starts in the top left corner, dont get caught by the seeker who starts in the bottom right corner.
ESC quits.

Code: QB64: [Select]
  1. 'Gapper(1986) Clone
  2. '10\25\2019 Cobalt
  3. 'ÃInital Start; Layout, Gapper, Seeker, L1 Grid finished [13:55EDT]
  4. 'ÀCorreted 'Catcher' to 'Seeker' as per original game
  5. '10\31\2021
  6. 'ÃFixed Seeker movement issue with help from Bplus and Keybone, used ABS as per Bplus
  7. 'Àadded startup screen, player initials input,game options
  8. '11\1\2021
  9. 'ÃAdded the instructions screens
  10. 'Àenabled collision of Seeker and Gapper
  11. '11\11\2021
  12. 'ÃFinished all 8 boards
  13. '11\13\2021
  14. 'ÃInserted Bplus's code for detecting completed boxes.
  15. '11\14\2021
  16. 'ÃIntegrated Bplus's code for detecting completed boxes and filling them.
  17. 'ÃAdded score amount to filled boxes
  18. 'ÃLevels now end when boxes are full
  19. 'ÀScore is now kept
  20.  
  21. TYPE GameData
  22.  Player AS STRING * 4
  23.  Score AS LONG
  24.  Lives AS _BYTE
  25.  Level AS _BYTE
  26.  GX AS INTEGER 'Gapper X location
  27.  GY AS INTEGER 'Gapper Y location
  28.  GD AS _BYTE 'Gapper direction
  29.  SX AS INTEGER
  30.  SY AS INTEGER
  31.  SS AS _BYTE 'Seeker speed
  32.  SD AS _BYTE 'Seeker direction
  33.  Start AS _BYTE 'is level started or not(nothing happens until started)
  34.  FPS AS INTEGER
  35.  Quit AS _BYTE
  36.  Caught AS _BYTE 'has the seeker caught the gapper?
  37.  'board info
  38.  CellHeight AS _BYTE
  39.  CellWidth AS _BYTE
  40.  Rows AS _BYTE
  41.  Columns AS _BYTE
  42.  Offx AS _BYTE
  43.  Offy AS _BYTE
  44.  Needed AS _BYTE 'number of cells needing finished to win level
  45.  Finished AS _BYTE 'number of cells currently boxed in
  46.  
  47. TYPE High_Scores
  48.  Nam AS STRING * 4
  49.  Score AS LONG
  50.  Level AS INTEGER
  51.  
  52. CONST TRUE = -1, FALSE = NOT TRUE, Gapper = 1, Seeker = 2
  53. CONST UP = 1, DOWN = 2, LEFT = 3, RIGHT = 4
  54. CONST Key_Right = 19712, Key_Left = 19200, Key_Up = 18432, Key_Down = 20480
  55. CONST Key_Space = 32, Key_Enter = 13
  56. CONST Cyan = &HFF10E0E0~& '_RGB32(0, 170, 170)
  57. CONST Magenta = &HFFC040C0~&
  58. CONST OffWhite = &HFFC0C0C0~&
  59. CONST Brown = &HFFB06000~&
  60. CONST Yellow = &HFFFFFF00~&
  61. CONST Black = &HFF000000~&
  62.  
  63. SCREEN _NEWIMAGE(640, 440, 32)
  64. DIM SHARED Layer(11) AS LONG, G AS GameData, Frames%
  65. DIM SHARED Scores(10) AS High_Scores
  66. DIM SHARED FinishedBox(72) AS _BYTE
  67.  
  68. Layer(0) = _DISPLAY
  69. Layer(1) = _NEWIMAGE(640, 440, 32) 'mix layer
  70. Layer(2) = _NEWIMAGE(320, 220, 32) 'Grid Layer
  71. Layer(3) = _NEWIMAGE(640, 440, 32) 'Sprite layer
  72. Layer(4) = _NEWIMAGE(320, 220, 32) 'Info layer
  73. Layer(5) = _NEWIMAGE(640, 440, 32) 'Collision 'Gapper\Catcher' layer
  74. Layer(6) = _NEWIMAGE(640, 440, 32) 'Collision 'Grid' layer
  75. Layer(7) = _NEWIMAGE(640, 440, 32) 'debug layer
  76. Layer(8) = _NEWIMAGE(320, 220, 32) 'Menu layer
  77. Layer(9) = _NEWIMAGE(320, 240, 32) 'instructions layer
  78. Layer(10) = _NEWIMAGE(320, 8, 32) 'title bar layer
  79. Layer(11) = _NEWIMAGE(320, 220, 32) 'point test location layer
  80.  
  81. _FONT 8, Layer(4)
  82. _FONT 8, Layer(8)
  83. _FONT 8, Layer(9)
  84. _FONT 8, Layer(10)
  85. _FONT 8, Layer(2)
  86. _CLEARCOLOR _RGB32(0, 0, 0), Layer(3)
  87. _CLEARCOLOR _RGB32(0, 0, 0), Layer(7)
  88.  
  89. _SOURCE Layer(6)
  90.  
  91. ON TIMER(t1&, 1) FPS
  92. 'Title_Startup
  93. 'END
  94. Game_INIT
  95. DrawBoard
  96. TIMER(t1&) ON
  97.  IF _KEYDOWN(27) THEN ExitFlag%% = TRUE
  98.  IF _KEYDOWN(Key_Up) THEN
  99.   G.Start = TRUE
  100.   IF NOT Collision_Grid(Gapper, UP) THEN G.GD = UP
  101.  IF _KEYDOWN(Key_Down) THEN
  102.   G.Start = TRUE
  103.   IF NOT Collision_Grid(Gapper, DOWN) THEN G.GD = DOWN
  104.  IF _KEYDOWN(Key_Left) THEN
  105.   G.Start = TRUE
  106.   IF NOT Collision_Grid(Gapper, LEFT) THEN G.GD = LEFT
  107.  IF _KEYDOWN(Key_Right) THEN
  108.   G.Start = TRUE
  109.   IF NOT Collision_Grid(Gapper, RIGHT) THEN G.GD = RIGHT
  110.  
  111.  IF G.Start THEN Move_Seeker: Move_Gapper
  112.  
  113.  FOR i%% = 1 TO G.Needed
  114.   IF BoxSurrounded(i%%) THEN FinishedBox(i%%) = TRUE
  115.   IF FinishedBox(i%%) THEN FillBox i%%
  116.  NEXT i%%
  117.  
  118.  Game_Data_Update
  119.  _PUTIMAGE (0, 0)-STEP(639, 15), Layer(10), Layer(1) 'title bar
  120.  _PUTIMAGE , Layer(4), Layer(1) 'information bar
  121.  _PUTIMAGE , Layer(2), Layer(1) 'game board
  122.  Place_Gapper
  123.  Place_Seeker
  124.  IF G.Caught THEN 'seeker caught 'em
  125.   ClearLayer Layer(5)
  126.   Reset_Pos
  127.   DrawBoard
  128.   G.Lives = G.Lives - 1
  129.   IF G.Lives = -1 THEN ExitFlag%% = TRUE
  130.  _PRINTSTRING (600, 0), STR$(G.FPS), Layer(7)
  131.  _PUTIMAGE , Layer(7), Layer(1) 'debug layer
  132.  _PUTIMAGE , Layer(1), Layer(0)
  133.  _LIMIT 60
  134.  ClearLayer Layer(1)
  135.  Frames% = Frames% + 1
  136.  IF G.Finished = G.Needed THEN Change_Level
  137. LOOP UNTIL ExitFlag%%
  138.  
  139. SUB Place_Gapper
  140.  old& = _DEST
  141.  _DEST Layer(5)
  142.  LINE (G.GX - 2, G.GY - 2)-STEP(20, 18), Black, BF
  143.  _DEST old&
  144.  'place gapper-----
  145.  _PUTIMAGE (G.GX, G.GY), Layer(3), Layer(1), (318, 218)-STEP(15, 13)
  146.  'place Gapper shadow
  147.  _PUTIMAGE (G.GX, G.GY), Layer(3), Layer(5), (318, 218)-STEP(15, 13)
  148.  
  149. SUB Place_Seeker
  150.  'place Seeker----
  151.  _PUTIMAGE (G.SX, G.SY), Layer(3), Layer(1), (341, 218)-STEP(14, 11)
  152.  '-----------------
  153.  
  154.  
  155. SUB Game_INIT
  156.  _DEST Layer(3)
  157.  'Player----
  158.  DRAW "c" + STR$(Cyan) + "drurd8l2dr3u9d2rd5ru5rd5ru5ru2d9r3ul2u8r2dlbl3c" + STR$(Magenta) + "u3ld3lu3ld3"
  159.  DRAW "bd7d3ru3rd3ru3bu3br3r4ul4bl9l4dr4"
  160.  '----------
  161.  DRAW "br20bu7"
  162.  'Seeker----
  163.  DRAW "c" + STR$(Cyan) + "r3dl3bd10r3ul3br10r3dl3bu10r3ul3c" + STR$(Magenta) + "bd2brl3dr3bd5l3dr3bl6l3ur3"
  164.  DRAW "bu5l3ur3d2lr5dl5dr5dl5"
  165.  '------------
  166.  Title_Header
  167.  _DEST Layer(5)
  168.  LINE (0, 0)-STEP(639, 439), Black, BF
  169.  _DEST Layer(0)
  170.  G.Score = 0
  171.  G.Lives = 2
  172.  G.Level = 1
  173.  
  174. SUB Title_Header
  175.  'Header
  176.  _DEST Layer(10)
  177.  LINE (84, 0)-STEP(151, 8), Magenta, BF
  178.  LINE (132, 0)-STEP(52, 8), Cyan, BF
  179.  COLOR Magenta
  180.  _PRINTSTRING (135, 1), "GAPPER"
  181.  COLOR OffWhite
  182.  
  183. SUB Game_Data_Update
  184.  'Info area updating ---------------
  185.  _PRINTSTRING (7, 192), "Score[      ]    Lives[ ]    Level[  ]", Layer(4)
  186.  _PRINTSTRING (95 - ((LEN(LTRIM$(STR$(G.Score))) - 1) * 8), 192), LTRIM$(STR$(G.Score)), Layer(4)
  187.  _PRINTSTRING (191, 192), LTRIM$(STR$(G.Lives)), Layer(4)
  188.  _PRINTSTRING (295 - ((LEN(LTRIM$(STR$(G.Level))) - 1) * 8), 192), LTRIM$(STR$(G.Level)), Layer(4)
  189.  '-----------------------------------
  190.  
  191. SUB DrawBoard
  192.  _DEST Layer(2)
  193.  SELECT CASE G.Level
  194.   CASE 1 'draw level 1 grid
  195.    Level_1_Board
  196.   CASE 2
  197.    Level_2_Board
  198.   CASE 3
  199.    Level_3_Board
  200.   CASE 4
  201.    Level_4_Board
  202.   CASE 5
  203.    Level_5_Board
  204.   CASE 6
  205.    Level_6_Board
  206.   CASE 7
  207.    Level_7_Board
  208.   CASE 8
  209.    Level_8_Board
  210.   CASE ELSE 'after level 8 board is random between 5 and 8
  211.    SELECT CASE INT(RND * 4) + 5
  212.     CASE 5
  213.      Level_5_Board
  214.     CASE 6
  215.      Level_6_Board
  216.     CASE 7
  217.      Level_7_Board
  218.     CASE 8
  219.      Level_8_Board
  220.    END SELECT
  221.  _DEST Layer(0)
  222.  ClearLayer Layer(6)
  223.  _PUTIMAGE , Layer(2), Layer(6) 'make a copy for the collision layer
  224.  
  225. SUB ClearLayer (L&)
  226.  _DEST L&
  227.  CLS
  228.  
  229. SUB ClearLayerTrans (L&)
  230.  _DEST L&
  231.  CLS , 0
  232.  
  233. FUNCTION Collision_Seeker%%
  234.  Result%% = FALSE
  235.  _SOURCE Layer(5)
  236.  IF POINT(G.SX, G.SY) <> Black THEN Result%% = TRUE
  237.  IF POINT(G.SX + 8, G.SY) <> Black THEN Result%% = TRUE
  238.  IF POINT(G.SX, G.SY + 8) <> Black THEN Result%% = TRUE
  239.  IF POINT(G.SX + 8, G.SY + 8) <> Black THEN Result%% = TRUE
  240.  IF Result%% THEN LOCATE 1, 1: PRINT POINT(G.SX, G.SY), POINT(G.SX + 8, G.SY), POINT(G.SX, G.SY + 8), POINT(G.SX + 8, G.SY + 8)
  241.  Collision_Seeker = Result%%
  242.  _SOURCE Layer(6)
  243.  
  244. FUNCTION Collision_Grid%% (who%%, Direction%%)
  245.  Result%% = TRUE 'always assume collision
  246.  SELECT CASE who%% 'who are we checking collision for?
  247.   CASE Gapper
  248.    SELECT CASE Direction%%
  249.     CASE UP 'see if there is grid up from Gappers position
  250.      Check~& = POINT(G.GX + 8, G.GY + 5)
  251.     CASE DOWN 'see if there is Grid below Gapper
  252.      Check~& = POINT(G.GX + 8, G.GY + 9)
  253.     CASE LEFT 'check for grid to the left of Gapper
  254.      Check~& = POINT(G.GX + 6, G.GY + 7)
  255.     CASE RIGHT 'Check for grid to the Right of Gapper
  256.      Check~& = POINT(G.GX + 10, G.GY + 7)
  257.    END SELECT
  258.   CASE Seeker
  259.    SELECT CASE Direction%%
  260.     CASE UP 'see if there is grid up from Gappers position
  261.      Check~& = POINT(G.SX + 8, G.SY + 5)
  262.      _PRINTSTRING (250, 400), "UP   ", Layer(7)
  263.     CASE DOWN 'see if there is Grid below Gapper
  264.      Check~& = POINT(G.SX + 8, G.SY + 9)
  265.      _PRINTSTRING (250, 400), "DOWN ", Layer(7)
  266.     CASE LEFT 'check for grid to the left of Gapper
  267.      Check~& = POINT(G.SX + 6, G.SY + 7)
  268.      _PRINTSTRING (250, 400), "LEFT ", Layer(7)
  269.     CASE RIGHT 'Check for grid to the Right of Gapper
  270.      Check~& = POINT(G.SX + 10, G.SY + 7)
  271.      _PRINTSTRING (240, 400), "RIGHT", Layer(7)
  272.    END SELECT
  273.  Blue~%% = _BLUE32(Check~&) 'check for Blue, grid is Cyan in color
  274.  IF Blue~%% THEN Result%% = FALSE 'there is grid to move onto, no collision with edge of grid
  275.  
  276.  
  277.  Collision_Grid = Result%%
  278.  '_SOURCE Layer(0)
  279.  
  280.  
  281. SUB Move_Seeker
  282.  STATIC Mover%%
  283.  Seeker_Logic
  284.  IF Mover%% < G.SS THEN
  285.   Mover%% = Mover%% + 1 'Slow our seeker down
  286.   Mover%% = 0
  287.   SELECT CASE G.SD
  288.    CASE UP
  289.     IF NOT Collision_Grid(Seeker, UP) THEN G.SY = G.SY - 2
  290.    CASE DOWN
  291.     IF NOT Collision_Grid(Seeker, DOWN) THEN G.SY = G.SY + 2
  292.    CASE LEFT
  293.     IF NOT Collision_Grid(Seeker, LEFT) THEN G.SX = G.SX - 2
  294.    CASE RIGHT
  295.     IF NOT Collision_Grid(Seeker, RIGHT) THEN G.SX = G.SX + 2
  296.  IF Collision_Seeker THEN G.Caught = TRUE
  297.  
  298. SUB Move_Gapper
  299.  SELECT CASE G.GD
  300.   CASE UP
  301.    IF NOT Collision_Grid(Gapper, UP) THEN G.GY = G.GY - 2
  302.   CASE DOWN
  303.    IF NOT Collision_Grid(Gapper, DOWN) THEN G.GY = G.GY + 2
  304.   CASE LEFT
  305.    IF NOT Collision_Grid(Gapper, LEFT) THEN G.GX = G.GX - 2
  306.   CASE RIGHT
  307.    IF NOT Collision_Grid(Gapper, RIGHT) THEN G.GX = G.GX + 2
  308.  Color_Line
  309.  
  310. SUB Seeker_Logic
  311.  DistX% = (G.SX - G.GX) 'find X distance between seeker and gapper
  312.  DistY% = (G.SY - G.GY) 'find Y distance between Seeker and Gapper
  313.  IF ABS(DistX%) > ABS(DistY%) THEN 'if player is farther on the X then
  314.   IF DistX% < 0 THEN
  315.    Turn_Seeker RIGHT 'try going right to get closer
  316.   ELSE
  317.    Turn_Seeker LEFT 'try going left to get closer
  318.   END IF
  319.  ELSE 'player is farther on the Y then
  320.   IF DistY% < 0 THEN
  321.    Turn_Seeker DOWN 'try going down to get closer
  322.   ELSE
  323.    Turn_Seeker UP 'try going up to get closer
  324.   END IF
  325.  
  326. SUB Turn_Seeker (Direction%%)
  327.  SELECT CASE Direction%%
  328.   CASE UP
  329.    IF NOT Collision_Grid(Seeker, UP) THEN G.SD = UP
  330.   CASE DOWN
  331.    IF NOT Collision_Grid(Seeker, DOWN) THEN G.SD = DOWN
  332.   CASE LEFT
  333.    IF NOT Collision_Grid(Seeker, LEFT) THEN G.SD = LEFT
  334.   CASE RIGHT
  335.    IF NOT Collision_Grid(Seeker, RIGHT) THEN G.SD = RIGHT
  336.  
  337. SUB Color_Line
  338.  _DEST Layer(2)
  339.  LINE (4 + G.GX \ 2, 3 + G.GY \ 2)-STEP(0, 0), Magenta, BF
  340.  _DEST Layer(0)
  341.  
  342. SUB FPS
  343.  G.FPS = Frames%
  344.  Frames% = 0
  345.  
  346. SUB Title_Startup
  347.  _DEST Layer(8)
  348.  LINE (84, 0)-STEP(151, 8), Brown, BF
  349.  LINE (132, 0)-STEP(52, 8), Cyan, BF
  350.  COLOR Brown
  351.  _PRINTSTRING (135, 1), "GAPPER"
  352.  LINE (0, 140)-STEP(639, 8), Brown, BF
  353.  COLOR Black
  354.  _PRINTSTRING (0, 141), "Score:"
  355.  _PRINTSTRING (220, 141), "Level:"
  356.  _PRINTSTRING (100 - (LEN(LTRIM$(STR$(G.Score))) * 8), 141), STR$(G.Score) + "."
  357.  _PRINTSTRING (284 - (LEN(LTRIM$(STR$(G.Level))) * 8), 141), STR$(G.Level)
  358.  
  359.  COLOR Yellow
  360.  _PRINTSTRING (100, 160), "P: Play a game."
  361.  _PRINTSTRING (100, 170), "Q: Quit"
  362.  _PRINTSTRING (100, 180), "N: New Player"
  363.  _PRINTSTRING (100, 190), "I: Instuctions"
  364.  COLOR Magenta
  365.  _PRINTSTRING (0, 210), "Enter your initials:"
  366.  COLOR OffWhite
  367.  
  368.  Get_Player
  369.  IF Search_For_Player THEN AddPlayer 'first time this player has played!
  370.  Display_HighScores
  371.  IF NOT G.Quit THEN Get_Menu_Selection
  372.  
  373. SUB Get_Player
  374.  Blink%% = TRUE: I$ = ""
  375.  DO 'Initials input Loop
  376.   KBD& = _KEYHIT
  377.   SELECT CASE KBD&
  378.    CASE 8 'delete
  379.     IF LEN(I$) THEN I$ = LEFT$(I$, LEN(I$) - 1)
  380.     LINE (168, 210)-(248, 219), Black, BF
  381.    CASE 32 TO 122 'characters
  382.     IF LEN(I$) < 3 THEN I$ = I$ + CHR$(KBD&)
  383.     LINE (168, 210)-(248, 219), Black, BF
  384.    CASE 13 'accept input(if any)
  385.     IF RTRIM$(I$) <> "" THEN ExitFlag%% = TRUE
  386.    CASE 27
  387.     ExitFlag%% = TRUE
  388.     G.Quit = TRUE
  389.   COLOR OffWhite
  390.   _PRINTSTRING (168, 210), I$
  391.   IF Blink%% THEN COLOR Black ELSE COLOR OffWhite
  392.   _PRINTSTRING (168 + LEN(I$) * 8, 210), "_"
  393.   _PUTIMAGE , Layer(8), _DISPLAY
  394.   _LIMIT 30
  395.   t%% = t%% + 1
  396.   IF t%% = 4 THEN Blink%% = NOT Blink%%: t%% = 0
  397.  LOOP UNTIL ExitFlag%%
  398.  G.Player = I$
  399.  
  400. SUB Get_Menu_Selection
  401.  LINE (0, 210)-STEP(200, 9), Black, BF
  402.  _PRINTSTRING (0, 210), "Please enter selection:  "
  403.  DO
  404.   KBD& = _KEYHIT
  405.   SELECT CASE KBD&
  406.    CASE ASC("p") OR ASC("P")
  407.    CASE ASC("q") OR ASC("Q")
  408.     ExitFlag%% = TRUE
  409.     G.Quit = TRUE
  410.    CASE ASC("n") OR ASC("N")
  411.    CASE ASC("i") OR ASC("I")
  412.     Instructions
  413.    CASE 27
  414.     ExitFlag%% = TRUE
  415.     G.Quit = TRUE
  416.   _PUTIMAGE , Layer(8), _DISPLAY
  417.  LOOP UNTIL ExitFlag%%
  418.  
  419. SUB Display_HighScores
  420.  _DEST Layer(8)
  421.  IF LTRIM$(RTRIM$(Scores(1).Nam)) <> "" THEN
  422.   COLOR Magenta
  423.   _PRINTSTRING (0, 24), "High scores:"
  424.   FOR i%% = 1 TO 10
  425.    IF G.Player = Scores(i%%).Nam THEN
  426.     COLOR Yellow 'player shows up Yellow
  427.    ELSEIF i%% = 1 THEN
  428.     COLOR Magenta 'High score if not player shows magenta
  429.    ELSE
  430.     COLOR OffWhite 'everybody else is off white
  431.    END IF
  432.   NEXT i%%
  433.  
  434. SUB Instructions
  435.  ClearLayer Layer(0)
  436.  _DEST Layer(9)
  437.  LINE (84, 0)-STEP(151, 8), Brown, BF
  438.  LINE (132, 0)-STEP(52, 8), Cyan, BF
  439.  COLOR Brown
  440.  _PRINTSTRING (135, 1), "GAPPER"
  441.  COLOR OffWhite
  442.  _PRINTSTRING (84, 10), "OBJECT"
  443.  _PRINTSTRING (1, 20), "To color all the blue lines"
  444.  _PRINTSTRING (1, 30), "res by moving your man GAPPER"
  445.  _PRINTSTRING (1, 40), "with the arrow keys.  At the"
  446.  _PRINTSTRING (1, 50), "same time, you myst avoid"
  447.  _PRINTSTRING (1, 60), "the SEEKER."
  448.  
  449.  _PRINTSTRING (84, 80), "POINTS"
  450.  _PRINTSTRING (1, 90), "Fifty points are awarded for"
  451.  _PRINTSTRING (1, 100), "each square that you surround"
  452.  _PRINTSTRING (1, 110), "in red.  100 points are given"
  453.  _PRINTSTRING (1, 120), "when you encircle the extra"
  454.  _PRINTSTRING (1, 130), "point box while it is on. Each"
  455.  _PRINTSTRING (1, 140), "gap costs 5 points."
  456.  
  457.  _PRINTSTRING (84, 150), "GAPPING"
  458.  _PRINTSTRING (1, 160), "You can create a temporary"
  459.  _PRINTSTRING (1, 170), "gap in the lines by pressing"
  460.  _PRINTSTRING (1, 180), "the SPACE bar or RETURN.  The"
  461.  _PRINTSTRING (1, 190), "word ON appears as long as the"
  462.  _PRINTSTRING (1, 200), "gap is active.  Neither you nor"
  463.  _PRINTSTRING (1, 210), "the seeker can cross the gap."
  464.  
  465.  _PRINTSTRING (0, 230), "Press a key..."
  466.  _PUTIMAGE , Layer(9), _DISPLAY
  467.  _DELAY .5
  468.  'end of page 1
  469.  DO: _LIMIT 24: LOOP WHILE INKEY$ = ""
  470.  CLS
  471.  LINE (84, 0)-STEP(151, 8), Brown, BF
  472.  LINE (132, 0)-STEP(52, 8), Cyan, BF
  473.  COLOR Brown
  474.  _PRINTSTRING (135, 1), "GAPPER"
  475.  COLOR OffWhite
  476.  _PRINTSTRING (84, 10), "LEVELS"
  477.  _PRINTSTRING (1, 20), "The level increases each time"
  478.  _PRINTSTRING (1, 30), "you complete a screen.  The"
  479.  _PRINTSTRING (1, 40), "seeker gets faster, the gap"
  480.  _PRINTSTRING (1, 50), "time shorter and there will"
  481.  _PRINTSTRING (1, 60), "be more boxes."
  482.  
  483.  _PRINTSTRING (84, 80), "LIVES"
  484.  _PRINTSTRING (1, 90), "You start out with 2 extra"
  485.  _PRINTSTRING (1, 100), "men.  One more will be given"
  486.  _PRINTSTRING (1, 110), "for each 5000 points."
  487.  
  488.  _PRINTSTRING (84, 130), "START"
  489.  _PRINTSTRING (1, 140), "When the grid appears, you"
  490.  _PRINTSTRING (1, 150), "Will be in the top left and"
  491.  _PRINTSTRING (1, 160), "the seeker at the low right."
  492.  _PRINTSTRING (1, 170), "Press a key to begin each new"
  493.  _PRINTSTRING (1, 180), "screen."
  494.  
  495.  _PRINTSTRING (0, 230), "Press a key..."
  496.  'end of page 2
  497.  _PUTIMAGE , Layer(9), _DISPLAY
  498.  _DELAY .5
  499.  DO: _LIMIT 24: LOOP WHILE INKEY$ = ""
  500.  ClearLayer Layer(0)
  501.  
  502. SUB Load_Scores
  503.  OPEN "Gapper.HSL" FOR BINARY AS #1
  504.  GET #1, , Count%%
  505.  FOR i%% = 1 TO Count%%
  506.   GET #1, , Scores(i%%).Nam
  507.   GET #1, , Scores(i%%)
  508.   GET #1, , Scores(i%%)
  509.  NEXT i%%
  510.  CLOSE #1
  511.  
  512. FUNCTION Search_For_Player
  513.  FOR i%% = 1 TO 10
  514.   IF G.Player = Scores(i%%).Nam THEN Result%% = TRUE: i%% = 11 ELSE Result%% = FALSE
  515.  NEXT i%%
  516.  Search_For_Player = Result%%
  517.  
  518. SUB AddPlayer
  519.  OPEN "Gapper.HSL" FOR BINARY AS #1
  520.  GET #1, , Count%%
  521.  IF Count%% < 10 THEN Count%% = Count%% + 1
  522.  PUT #1, 1, Count%%
  523.  PUT #1, 1 + 10 * Count%%, G.Player
  524.  PUT #1, , NULL& 'filler for score
  525.  PUT #1, , NULL% 'filler for level
  526.  CLOSE #1
  527.  Load_Scores 'reload score list
  528.  
  529. SUB Reset_Pos
  530.  PLAY "o1l32aacceegg"
  531.  _DELAY .25
  532.  G.Start = FALSE
  533.  G.Caught = FALSE
  534.  SELECT CASE G.Level
  535.   CASE 1
  536.    'Level 1 Start Pos.------
  537.    G.GX = 0: G.GY = 14 'Gapper
  538.    G.SX = 626: G.SY = 374 'Seeker
  539.    '------------------------
  540.  
  541. SUB Level_1_Board
  542.  FOR I%% = 0 TO 3
  543.   LINE (4, 10 + I%% * 60)-STEP(311, 0), Cyan 'horizontal lines
  544.   LINE (4 + I%% * 104, 10)-STEP(0, 180), Cyan 'vertical lines
  545.  NEXT I%%
  546.  G.SS = 2 'set seeker speed 1\4th player speed
  547.  G.Start = FALSE
  548.  'Level 1 Start Pos.------
  549.  G.GX = 0: G.GY = 14 'Gapper
  550.  G.SX = 626: G.SY = 374 'Seeker
  551.  'Level 1 board info------
  552.  G.CellWidth = 104
  553.  G.CellHeight = 60
  554.  G.Rows = 3
  555.  G.Columns = 3
  556.  G.Offx = 4
  557.  G.Offy = 10
  558.  G.Needed = 9
  559.  G.Finished = 0
  560.  '------------------------
  561.  
  562.  
  563. SUB Level_2_Board
  564.  FOR I%% = 0 TO 4
  565.   LINE (8, 12 + I%% * 44)-STEP(304, 0), Cyan 'horizontal lines
  566.   LINE (8 + I%% * 76, 12)-STEP(0, 176), Cyan 'vertical lines
  567.  NEXT I%%
  568.  G.SS = 1 'set seeker speed 1\4th player speed
  569.  G.Start = FALSE
  570.  'Level 2 Start Pos.------
  571.  G.GX = 8: G.GY = 18 'Gapper
  572.  G.SX = 616: G.SY = 370 'Seeker
  573.  '------------------------
  574.  'Level 2 board info------
  575.  G.CellWidth = 76
  576.  G.CellHeight = 44
  577.  G.Rows = 4
  578.  G.Columns = 4
  579.  G.Offx = 8
  580.  G.Offy = 12
  581.  G.Needed = 16
  582.  G.Finished = 0
  583.  '------------------------
  584.  
  585. SUB Level_3_Board
  586.  FOR I%% = 0 TO 5
  587.   LINE (10, 10 + I%% * 36)-STEP(300, 0), Cyan 'horizontal lines
  588.   LINE (10 + I%% * 60, 10)-STEP(0, 180), Cyan 'vertical lines
  589.  NEXT I%%
  590.  G.SS = 1 'set seeker speed 1\4th player speed
  591.  G.Start = FALSE
  592.  'Level 3 Start Pos.------
  593.  G.GX = 12: G.GY = 14 'Gapper
  594.  G.SX = 612: G.SY = 374 'Seeker
  595.  '------------------------
  596.  'Level 3 board info------
  597.  G.CellWidth = 60
  598.  G.CellHeight = 36
  599.  G.Rows = 5
  600.  G.Columns = 5
  601.  G.Offx = 10
  602.  G.Offy = 10
  603.  G.Needed = 25
  604.  G.Finished = 0
  605.  '------------------------
  606.  
  607. SUB Level_4_Board
  608.  FOR I%% = 0 TO 6
  609.   LINE (16, 16 + I%% * 24)-STEP(288, 0), Cyan 'horizontal lines
  610.   LINE (16 + I%% * 48, 16)-STEP(0, 168), Cyan 'vertical lines
  611.  NEXT I%%
  612.  LINE (16, 16 + I%% * 24)-STEP(288, 0), Cyan 'horizontal lines
  613.  G.SS = 1 'set seeker speed 1\4th player speed
  614.  G.Start = FALSE
  615.  'Level 4 Start Pos.------
  616.  G.GX = 24: G.GY = 26 'Gapper
  617.  G.SX = 600: G.SY = 362 'Seeker
  618.  '------------------------
  619.  'Level 4 board info------
  620.  G.CellWidth = 48
  621.  G.CellHeight = 24
  622.  G.Rows = 7
  623.  G.Columns = 6
  624.  G.Offx = 16
  625.  G.Offy = 16
  626.  G.Needed = 42
  627.  G.Finished = 0
  628.  '------------------------
  629.  
  630. SUB Level_5_Board
  631.  FOR I%% = 0 TO 4
  632.   LINE (16, 16 + I%% * 24)-STEP(288, 0), Cyan 'horizontal lines
  633.   LINE (88 + I%% * 36, 16)-STEP(0, 168), Cyan 'vertical lines
  634.  NEXT I%%
  635.  FOR I%% = 0 TO 2
  636.   LINE (88, 136 + I%% * 24)-STEP(144, 0), Cyan 'horizontal lines
  637.   LINE (16 + I%% * 36, 16)-STEP(0, 96), Cyan 'vertical lines
  638.   LINE (268 + I%% * 36, 16)-STEP(0, 96), Cyan 'vertical lines
  639.  NEXT I%%
  640.  
  641.  G.SS = 1 'set seeker speed = player speed
  642.  G.Start = FALSE
  643.  'Level 5 Start Pos.------
  644.  G.GX = 24: G.GY = 26 'Gapper
  645.  G.SX = 458: G.SY = 362 'Seeker
  646.  '------------------------
  647.  'Level 5 board info------
  648.  G.CellWidth = 36
  649.  G.CellHeight = 24
  650.  G.Rows = 7
  651.  G.Columns = 8
  652.  G.Offx = 16
  653.  G.Offy = 16
  654.  G.Needed = 44
  655.  G.Finished = 0
  656.  '------------------------
  657.  
  658. SUB Level_6_Board
  659.  FOR I%% = 0 TO 3
  660.   LINE (16, 64 + I%% * 24)-STEP(288, 0), Cyan 'horizontal lines
  661.   LINE (88 + I%% * 36, 16)-STEP(0, 168), Cyan 'vertical lines
  662.  NEXT I%%
  663.  LINE (88 + I%% * 36, 16)-STEP(0, 168), Cyan 'vertical lines
  664.  
  665.  FOR I%% = 0 TO 1
  666.   LINE (88, 16 + I%% * 24)-STEP(144, 0), Cyan 'horizontal lines
  667.   LINE (88, 160 + I%% * 24)-STEP(144, 0), Cyan 'horizontal lines
  668.   LINE (16 + I%% * 36, 64)-STEP(0, 72), Cyan 'vertical lines
  669.   LINE (268 + I%% * 36, 64)-STEP(0, 72), Cyan 'vertical lines
  670.  NEXT I%%
  671.  
  672.  G.SS = 1 'set seeker speed = player speed
  673.  G.Start = FALSE
  674.  'Level 6 Start Pos.------
  675.  G.GX = 168: G.GY = 26 'Gapper
  676.  G.SX = 458: G.SY = 362 'Seeker
  677.  '------------------------
  678.  'Level 6 board info------
  679.  G.CellWidth = 36
  680.  G.CellHeight = 24
  681.  G.Rows = 7
  682.  G.Columns = 8
  683.  G.Offx = 16
  684.  G.Offy = 16
  685.  G.Needed = 40
  686.  G.Finished = 0
  687.  '------------------------
  688.  
  689. SUB Level_7_Board
  690.  FOR I%% = 0 TO 4
  691.   LINE (16, 88 + I%% * 24)-STEP(288, 0), Cyan 'horizontal lines
  692.   LINE (88 + I%% * 36, 16)-STEP(0, 168), Cyan 'vertical lines
  693.  NEXT I%%
  694.  FOR I%% = 0 TO 1
  695.   LINE (88, 16 + I%% * 24)-STEP(144, 0), Cyan 'horizontal lines
  696.   LINE (16 + I%% * 36, 88)-STEP(0, 96), Cyan 'vertical lines
  697.   LINE (268 + I%% * 36, 88)-STEP(0, 96), Cyan 'vertical lines
  698.  NEXT I%%
  699.  LINE (88, 16 + I%% * 24)-STEP(144, 0), Cyan 'horizontal lines
  700.  
  701.  G.SS = 0 'set seeker speed = player speed
  702.  G.Start = FALSE
  703.  'Level 7 Start Pos.------
  704.  G.GX = 168: G.GY = 26 'Gapper
  705.  G.SX = 600: G.SY = 362 'Seeker
  706.  '------------------------
  707.  'Level 7 board info------
  708.  G.CellWidth = 36
  709.  G.CellHeight = 24
  710.  G.Rows = 7
  711.  G.Columns = 8
  712.  G.Offx = 16
  713.  G.Offy = 16
  714.  G.Needed = 44
  715.  G.Finished = 0
  716.  '------------------------
  717.  
  718. SUB Level_8_Board
  719.  FOR I%% = 0 TO 7
  720.   LINE (16, 16 + I%% * 24)-STEP(288, 0), Cyan 'horizontal lines
  721.   LINE (16 + I%% * 36, 16)-STEP(0, 168), Cyan 'vertical lines
  722.  NEXT I%%
  723.  LINE (16 + I%% * 36, 16)-STEP(0, 168), Cyan 'vertical lines
  724.  G.SS = 0 'set seeker speed 1\4th player speed
  725.  G.Start = FALSE
  726.  'Level 8 Start Pos.------
  727.  G.GX = 24: G.GY = 26 'Gapper
  728.  G.SX = 600: G.SY = 362 'Seeker
  729.  '------------------------
  730.  'Level 1 board info------
  731.  G.CellWidth = 36
  732.  G.CellHeight = 24
  733.  G.Rows = 8
  734.  G.Columns = 7
  735.  G.Offx = 16
  736.  G.Offy = 16
  737.  G.Needed = 56
  738.  G.Finished = 0
  739.  '------------------------
  740.  
  741. FUNCTION BoxSurrounded%% (boxNumber AS INTEGER) 'save already tested boxes in shared array BoxesSurrounded()
  742.  'Bplus contributed code. 11\12\2021
  743.  'some variables changed to use existing, `**` comments are added
  744.  _SOURCE Layer(2)
  745.  IF FinishedBox(boxNumber) = 0 THEN '**Is the box completed already?
  746.   row = INT((boxNumber - 1) / G.Columns) '[cellsPerCpl)] '**which row
  747.   col = (boxNumber - 1) MOD G.Columns + 1 '[cellsAcross + 1] '**which column
  748.  
  749.   Good%% = TRUE
  750.   FOR I% = row * G.CellHeight TO (row + 1) * G.CellHeight STEP 4 '**No need to check every pixel
  751.    IF POINT(G.Offx + (col - 1) * G.CellWidth, G.Offy + I%) <> Magenta THEN I% = 9999: Good%% = FALSE ' False Baox not surrounded
  752.    IF POINT(G.Offx + col * G.CellWidth, G.Offy + I%) <> Magenta THEN I% = 9999: Good%% = FALSE
  753.   NEXT I%
  754.  
  755.   IF Good%% THEN '**only check other lines if it hasn't failed yet
  756.    FOR I% = (col - 1) * G.CellWidth TO col * G.CellWidth STEP 4 '**No need to check every pixel
  757.     IF POINT(G.Offx + I%, G.Offy + row * G.CellHeight) <> Magenta THEN I% = 9999: Good%% = FALSE ' False Baox not surrounded
  758.     IF POINT(G.Offx + I%, G.Offy + (row + 1) * G.CellHeight) <> Magenta THEN I% = 9999: Good%% = FALSE
  759.    NEXT I%
  760.   END IF
  761.   IF Good%% THEN BoxSurrounded = -1: G.Finished = G.Finished + 1: G.Score = G.Score + 50 'all OK
  762.   BoxSurrounded = -1
  763.  _SOURCE Layer(6)
  764.  
  765. SUB FillBox (boxNumber)
  766.  _DEST Layer(2)
  767.  row = INT((boxNumber - 1) / G.Columns)
  768.  col = (boxNumber - 1) MOD G.Columns + 1
  769.  LINE (G.Offx + (col - 1) * G.CellWidth + 3, G.Offy + row * G.CellHeight + 3)-STEP(G.CellWidth - 6, G.CellHeight - 6), OffWhite, BF
  770.  COLOR Black
  771.  _PRINTSTRING (G.Offx + (col - 1) * G.CellWidth + 3 + (INT(G.CellWidth \ 2) - 8), G.Offy + row * G.CellHeight + 3 + (INT(G.CellHeight \ 2) - 8)), "50", Layer(2)
  772.  COLOR OffWhite
  773.  _DEST Layer(0)
  774.  
  775. SUB Change_Level
  776.  G.Level = G.Level + 1
  777.  ClearLayerTrans Layer(2)
  778.  ClearLayer Layer(5)
  779.  ClearLayer Layer(6)
  780.  '_CLEARCOLOR _RGB32(0, 0, 0), Layer(2)
  781.  DrawBoard
  782.  FOR i%% = 0 TO 72
  783.   FinishedBox(i%%) = FALSE
  784.  NEXT i%%
Granted after becoming radioactive I only have a half-life!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Gapper Playable to level 5
« Reply #1 on: November 15, 2021, 12:01:43 am »
Quote
@bplus any idea why BoxSurrounded stops working on that level?

The first set of code I posted in the other thread was flawed, not just the typo but several things needed fixing that the typo covered up. So if you are using that,...  well should have problems on all levels.

My codes calculated cellWidth and CellHeight from cellsAcross and cellsDown not merely assigned as you have it here. And from those numbers the grid was based and drawn. I didn't worry about x margin and y margins because grids of different sizes fitting in same space left different margins after rounding to integer values and then multiplying by cellsAcross or cellsDown. I took the CellWidth = int(_Width/cellsAcross) -1 to be sure all the bars of grid were visible on screen, likewise similar calc for CellHeight.

So perhaps you miscalc'd on the level with a problem.

You could save allot of lines of code:
Code: QB64: [Select]
  1.  
  2. SUB Level_1_Board
  3.  FOR I%% = 0 TO 3
  4.   LINE (4, 10 + I%% * 60)-STEP(311, 0), Cyan 'horizontal lines
  5.   LINE (4 + I%% * 104, 10)-STEP(0, 180), Cyan 'vertical lines
  6.  NEXT I%%
  7.  G.SS = 2 'set seeker speed 1\4th player speed
  8.  G.Start = FALSE
  9.  'Level 1 Start Pos.------
  10.  G.GX = 0: G.GY = 14 'Gapper
  11.  G.SX = 626: G.SY = 374 'Seeker
  12.  'Level 1 board info------
  13.  G.CellWidth = 104
  14.  G.CellHeight = 60
  15.  G.Rows = 3
  16.  G.Columns = 3
  17.  G.Offx = 4
  18.  G.Offy = 10
  19.  G.Needed = 9
  20.  G.Finished = 0
  21.  '------------------------
  22.  
  23.  
  24. SUB Level_2_Board
  25.  FOR I%% = 0 TO 4
  26.   LINE (8, 12 + I%% * 44)-STEP(304, 0), Cyan 'horizontal lines
  27.   LINE (8 + I%% * 76, 12)-STEP(0, 176), Cyan 'vertical lines
  28.  NEXT I%%
  29.  G.SS = 1 'set seeker speed 1\4th player speed
  30.  G.Start = FALSE
  31.  'Level 2 Start Pos.------
  32.  G.GX = 8: G.GY = 18 'Gapper
  33.  G.SX = 616: G.SY = 370 'Seeker
  34.  '------------------------
  35.  'Level 2 board info------
  36.  G.CellWidth = 76
  37.  G.CellHeight = 44
  38.  G.Rows = 4
  39.  G.Columns = 4
  40.  G.Offx = 8
  41.  G.Offy = 12
  42.  G.Needed = 16
  43.  G.Finished = 0
  44.  '------------------------
  45.  
  46. SUB Level_3_Board
  47.  FOR I%% = 0 TO 5
  48.   LINE (10, 10 + I%% * 36)-STEP(300, 0), Cyan 'horizontal lines
  49.   LINE (10 + I%% * 60, 10)-STEP(0, 180), Cyan 'vertical lines
  50.  NEXT I%%
  51.  G.SS = 1 'set seeker speed 1\4th player speed
  52.  G.Start = FALSE
  53.  'Level 3 Start Pos.------
  54.  G.GX = 12: G.GY = 14 'Gapper
  55.  G.SX = 612: G.SY = 374 'Seeker
  56.  '------------------------
  57.  'Level 3 board info------
  58.  G.CellWidth = 60
  59.  G.CellHeight = 36
  60.  G.Rows = 5
  61.  G.Columns = 5
  62.  G.Offx = 10
  63.  G.Offy = 10
  64.  G.Needed = 25
  65.  G.Finished = 0
  66.  '------------------------
  67.  
  68. SUB Level_4_Board
  69.  FOR I%% = 0 TO 6
  70.   LINE (16, 16 + I%% * 24)-STEP(288, 0), Cyan 'horizontal lines
  71.   LINE (16 + I%% * 48, 16)-STEP(0, 168), Cyan 'vertical lines
  72.  NEXT I%%
  73.  LINE (16, 16 + I%% * 24)-STEP(288, 0), Cyan 'horizontal lines
  74.  G.SS = 1 'set seeker speed 1\4th player speed
  75.  G.Start = FALSE
  76.  'Level 4 Start Pos.------
  77.  G.GX = 24: G.GY = 26 'Gapper
  78.  G.SX = 600: G.SY = 362 'Seeker
  79.  '------------------------
  80.  'Level 4 board info------
  81.  G.CellWidth = 48
  82.  G.CellHeight = 24
  83.  G.Rows = 7
  84.  G.Columns = 6
  85.  G.Offx = 16
  86.  G.Offy = 16
  87.  G.Needed = 42
  88.  G.Finished = 0
  89.  '------------------------
  90.  
  91. SUB Level_5_Board
  92.  FOR I%% = 0 TO 4
  93.   LINE (16, 16 + I%% * 24)-STEP(288, 0), Cyan 'horizontal lines
  94.   LINE (88 + I%% * 36, 16)-STEP(0, 168), Cyan 'vertical lines
  95.  NEXT I%%
  96.  FOR I%% = 0 TO 2
  97.   LINE (88, 136 + I%% * 24)-STEP(144, 0), Cyan 'horizontal lines
  98.   LINE (16 + I%% * 36, 16)-STEP(0, 96), Cyan 'vertical lines
  99.   LINE (268 + I%% * 36, 16)-STEP(0, 96), Cyan 'vertical lines
  100.  NEXT I%%
  101.  
  102.  G.SS = 1 'set seeker speed = player speed
  103.  G.Start = FALSE
  104.  'Level 5 Start Pos.------
  105.  G.GX = 24: G.GY = 26 'Gapper
  106.  G.SX = 458: G.SY = 362 'Seeker
  107.  '------------------------
  108.  'Level 5 board info------
  109.  G.CellWidth = 36
  110.  G.CellHeight = 24
  111.  G.Rows = 7
  112.  G.Columns = 8
  113.  G.Offx = 16
  114.  G.Offy = 16
  115.  G.Needed = 44
  116.  G.Finished = 0
  117.  '------------------------
  118.  
  119. SUB Level_6_Board
  120.  FOR I%% = 0 TO 3
  121.   LINE (16, 64 + I%% * 24)-STEP(288, 0), Cyan 'horizontal lines
  122.   LINE (88 + I%% * 36, 16)-STEP(0, 168), Cyan 'vertical lines
  123.  NEXT I%%
  124.  LINE (88 + I%% * 36, 16)-STEP(0, 168), Cyan 'vertical lines
  125.  
  126.  FOR I%% = 0 TO 1
  127.   LINE (88, 16 + I%% * 24)-STEP(144, 0), Cyan 'horizontal lines
  128.   LINE (88, 160 + I%% * 24)-STEP(144, 0), Cyan 'horizontal lines
  129.   LINE (16 + I%% * 36, 64)-STEP(0, 72), Cyan 'vertical lines
  130.   LINE (268 + I%% * 36, 64)-STEP(0, 72), Cyan 'vertical lines
  131.  NEXT I%%
  132.  
  133.  G.SS = 1 'set seeker speed = player speed
  134.  G.Start = FALSE
  135.  'Level 6 Start Pos.------
  136.  G.GX = 168: G.GY = 26 'Gapper
  137.  G.SX = 458: G.SY = 362 'Seeker
  138.  '------------------------
  139.  'Level 6 board info------
  140.  G.CellWidth = 36
  141.  G.CellHeight = 24
  142.  G.Rows = 7
  143.  G.Columns = 8
  144.  G.Offx = 16
  145.  G.Offy = 16
  146.  G.Needed = 40
  147.  G.Finished = 0
  148.  '------------------------
  149.  
  150. SUB Level_7_Board
  151.  FOR I%% = 0 TO 4
  152.   LINE (16, 88 + I%% * 24)-STEP(288, 0), Cyan 'horizontal lines
  153.   LINE (88 + I%% * 36, 16)-STEP(0, 168), Cyan 'vertical lines
  154.  NEXT I%%
  155.  FOR I%% = 0 TO 1
  156.   LINE (88, 16 + I%% * 24)-STEP(144, 0), Cyan 'horizontal lines
  157.   LINE (16 + I%% * 36, 88)-STEP(0, 96), Cyan 'vertical lines
  158.   LINE (268 + I%% * 36, 88)-STEP(0, 96), Cyan 'vertical lines
  159.  NEXT I%%
  160.  LINE (88, 16 + I%% * 24)-STEP(144, 0), Cyan 'horizontal lines
  161.  
  162.  G.SS = 0 'set seeker speed = player speed
  163.  G.Start = FALSE
  164.  'Level 7 Start Pos.------
  165.  G.GX = 168: G.GY = 26 'Gapper
  166.  G.SX = 600: G.SY = 362 'Seeker
  167.  '------------------------
  168.  'Level 7 board info------
  169.  G.CellWidth = 36
  170.  G.CellHeight = 24
  171.  G.Rows = 7
  172.  G.Columns = 8
  173.  G.Offx = 16
  174.  G.Offy = 16
  175.  G.Needed = 44
  176.  G.Finished = 0
  177.  '------------------------
  178.  
  179. SUB Level_8_Board
  180.  FOR I%% = 0 TO 7
  181.   LINE (16, 16 + I%% * 24)-STEP(288, 0), Cyan 'horizontal lines
  182.   LINE (16 + I%% * 36, 16)-STEP(0, 168), Cyan 'vertical lines
  183.  NEXT I%%
  184.  LINE (16 + I%% * 36, 16)-STEP(0, 168), Cyan 'vertical lines
  185.  G.SS = 0 'set seeker speed 1\4th player speed
  186.  G.Start = FALSE
  187.  'Level 8 Start Pos.------
  188.  G.GX = 24: G.GY = 26 'Gapper
  189.  G.SX = 600: G.SY = 362 'Seeker
  190.  '------------------------
  191.  'Level 1 board info------
  192.  G.CellWidth = 36
  193.  G.CellHeight = 24
  194.  G.Rows = 8
  195.  G.Columns = 7
  196.  G.Offx = 16
  197.  G.Offy = 16
  198.  G.Needed = 56
  199.  G.Finished = 0
  200.  '------------------------
  201.  

With one sub that also draws the grid
Code: QB64: [Select]
  1. Sub Level(cellsAcross, cellsDown)  
  2.     nCells = cellsAcross * cellsDown
  3.     cellWidth = Int(_Width / cellsAcross - 1) 'subtract 1 to get borders around all cells on screen
  4.     cellHeight = Int(_Height / cellsDown - 1)
  5.     ' surroundColor = _RGB32(255, 0, 255) ' purple as I recall
  6.     ReDim Shared BoxesSurrounded(1 To nCells) As Integer
  7.     '_Title "Box Surrounded Test: To demo, we need to start with a grid... zzz = Sleep, press any to continue."
  8.     'Sleep
  9.     'drawGrid
  10.     For I = 0 To _Width Step cellWidth
  11.         Line (I, 0)-(I, cellsDown * cellHeight)
  12.     Next
  13.     For I = 0 To _Height Step cellHeight
  14.         Line (0, I)-(cellsAcross * cellWidth, I)
  15.     Next
  16.     'label cells (boxes) with id number
  17.     'I = 1
  18.     'For r = 1 To cellsDown
  19.     '    For c = 1 To cellsAcross
  20.     '        _PrintString ((c - 1) * cellWidth + 2, (r - 1) * cellHeight + 2), _Trim$(Str$(I))
  21.     '        I = I + 1
  22.     '    Next
  23.     'Next

Your mod of my code isn't even using the part that saves you all that redundant box checking by using an array to store boxes already checked! the BoxesSurrounded array:
Code: QB64: [Select]
  1. Function BoxSurrounded% (boxNumber As Integer) 'save already tested boxes in shared array BoxesSurrounded()
  2.     If BoxesSurrounded(boxNumber) = 0 Then  ' <<<<<  Save time don't check any box twice!!!!!!!!!!!!!!
  3.         row = Int((boxNumber - 1) / cellsAcross)
  4.         col = (boxNumber - 1) Mod cellsAcross + 1
  5.         For i = row * cellHeight To row * cellHeight + row
  6.             If Point((col - 1) * cellWidth, i) <> surroundColor Then Exit Function ' False Box not surrounded
  7.             If Point(col * cellWidth, i) <> surroundColor Then Exit Function
  8.         Next
  9.         For i = (col - 1) * cellWidth To col * cellWidth
  10.             If Point(i, row * cellHeight) <> surroundColor Then Exit Function ' False Box not surrounded
  11.             If Point(i, row * cellHeight + row) <> surroundColor Then Exit Function
  12.         Next
  13.  BoxesSurrounded(boxNumber) = -1  '<<<< set this too while we're here
  14.         BoxSurrounded% = -1 'all OK
  15.     Else
  16.         BoxSurrounded = -1
  17.     End If
  18.  
  19.  
« Last Edit: November 15, 2021, 12:07:47 am by bplus »

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Gapper Playable to level 5
« Reply #2 on: November 15, 2021, 12:10:10 pm »
The first set of code I posted in the other thread was flawed, not just the typo but several things needed fixing that the typo covered up. So if you are using that,...  well should have problems on all levels.

I made the adjustment to the code when you posted that. But I will go over it again and make sure I didn't miss something (not that that would ever happen[heavy sarcasm!])

My codes calculated cellWidth and CellHeight from cellsAcross and cellsDown not merely assigned as you have it here. And from those numbers the grid was based and drawn. I didn't worry about x margin and y margins because grids of different sizes fitting in same space left different margins after rounding to integer values and then multiplying by cellsAcross or cellsDown. I took the CellWidth = int(_Width/cellsAcross) -1 to be sure all the bars of grid were visible on screen, likewise similar calc for CellHeight.

So perhaps you miscalc'd on the level with a problem.

Its all pretty straight forward in terms of numbers. the Columns and Rows max out at 8x7 at level 5 and keep that till level 8. Its just the shape that changes with levels 5,6, and 7.

You could save allot of lines of code:

True, that was just a quick and dirty way to get them all roughed out, and a single sub for levels 1 to 4 +8 would be best. however Levels 5,6 and 7 are not "square". the layout is shaped differently, as a "T", "+", and upside down "T" (attachment below)


Your mod of my code isn't even using the part that saves you all that redundant box checking by using an array to store boxes already checked! the BoxesSurrounded array:

Actually it does, but I already had an array I was trying to use so I just popped in my array name. which was "FinishedBox". So it still makes sure the box isn't done just with a different name. And only because I already had an array for it. (as the second comment down notes)

Code: QB64: [Select]
  1. FUNCTION BoxSurrounded%% (boxNumber AS INTEGER) 'save already tested boxes in shared array BoxesSurrounded()
  2.  'Bplus contributed code. 11\12\2021
  3.  'some variables changed to use existing, `**` comments are added
  4.  _SOURCE Layer(2)
  5.  IF FinishedBox(boxNumber) = 0 THEN '**Is the box completed already? <------------- originally BoxesSurrounded
  6.   row = INT((boxNumber - 1) / G.Columns) '[cellsPerCpl)] '**which row
  7.   col = (boxNumber - 1) MOD G.Columns + 1 '[cellsAcross + 1] '**which column
  8.  
  9.   Good%% = TRUE
  10.   FOR I% = row * G.CellHeight TO (row + 1) * G.CellHeight STEP 4 '**No need to check every pixel
  11.    IF POINT(G.Offx + (col - 1) * G.CellWidth, G.Offy + I%) <> Magenta THEN I% = 9999: Good%% = FALSE ' False Baox not surrounded
  12.    IF POINT(G.Offx + col * G.CellWidth, G.Offy + I%) <> Magenta THEN I% = 9999: Good%% = FALSE
  13.   NEXT I%
  14.  
  15.   IF Good%% THEN '**only check other lines if it hasn't failed yet
  16.    FOR I% = (col - 1) * G.CellWidth TO col * G.CellWidth STEP 4 '**No need to check every pixel
  17.     IF POINT(G.Offx + I%, G.Offy + row * G.CellHeight) <> Magenta THEN I% = 9999: Good%% = FALSE ' False Baox not surrounded
  18.     IF POINT(G.Offx + I%, G.Offy + (row + 1) * G.CellHeight) <> Magenta THEN I% = 9999: Good%% = FALSE
  19.    NEXT I%
  20.   END IF
  21.   IF Good%% THEN BoxSurrounded = -1: G.Finished = G.Finished + 1: G.Score = G.Score + 50 'all OK
  22.   BoxSurrounded = -1
  23.  _SOURCE Layer(6)
  24.  

Though with the problem on level 5, I attached what it is doing. it simply stops acknowledging surrounded boxes near the bottom of the board. Now this board is "T" shaped, but I just assumed the function would treat it as if all the board was there. Thats why G.Needed(which denotes the number of boxes on screen to finish a board) is set to 44 and not 56(8*7). But it stops filling boxes at 38.
5_to_7.jpg
* 5_to_7.jpg (Filesize: 37.8 KB, Dimensions: 960x200, Views: 149)
level5_issue.jpg
* level5_issue.jpg (Filesize: 65.02 KB, Dimensions: 642x461, Views: 149)
Granted after becoming radioactive I only have a half-life!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Gapper Playable to level 5
« Reply #3 on: November 15, 2021, 12:27:08 pm »
Ah different shaped grids!! I missed that.

So the box number system would need to pretend the missing boxes (from a fully gridded rectangle) are there as the row and column the box is in is determined by numbers.

Wow tracking where you are able to go with hero and chaser would get hairy. For boxes enclosed you can't mark the pretend boxes as enclosed and you better not try and check them from boxes enclosed array that tracks boxes checked.

Well different shaped grids with missing chunks from full rectangle was not a mod I anticipated with my code.

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Gapper Playable to level 5
« Reply #4 on: November 15, 2021, 12:32:31 pm »
I think I've figured out what I did.

Code: QB64: [Select]
  1.  FOR i%% = 1 TO G.Needed
  2.   IF BoxSurrounded(i%%) THEN FinishedBox(i%%) = TRUE
  3.   IF FinishedBox(i%%) THEN FillBox i%%
  4.  NEXT i%%
  5.  

I'm pretty sure that was telling it to stop checking for boxes after what was needed for the level, where as BoxSurrounded was looking at all 56 possible boxes. I forgot about the "invisible" boxes counting. and if you add the boxes on the sides of the level 5 board that you cant see into the 38 you come up with 44. upon which the FOR:NEXT stopped checking.

Code: QB64: [Select]
  1.  FOR i%% = 1 TO G.Columns * G.Rows
  2.   IF BoxSurrounded(i%%) THEN FinishedBox(i%%) = TRUE
  3.   IF FinishedBox(i%%) THEN FillBox i%%
  4.  NEXT i%%
  5.  

This seems to have fixed it. So now its checking the entire grid space. even though it will not all be used.
Wonder what it would take to do diagonal lines? Not that the original game had those, but might make an interesting addition.

well now to clean the code up some.
Granted after becoming radioactive I only have a half-life!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Gapper Playable to level 5
« Reply #5 on: November 15, 2021, 12:47:15 pm »
Glad you have it figured out, your mods are extending beyond the original assumptions I had for BoxEnclosed function. Not sure if those boxes not being used should be premarked as enclosed or not? Maybe so or definitely not. If you want to avoid even more pixel checking you could check if adjacent boxes are enclosed ie a box has boxes enclosed on all of it's 4 sides would itself have to be enclosed without checking a single pixel.

Diagonals, ha! how about every pixel? ;-))