Author Topic: Gapper(a game from 1986!) Why does my seeker get stuck?(Fixed with ABS)  (Read 5335 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
Harry has been using his invisibility cloak to sneak some drinky drink before the quidditch match again I think!

Everything seems to be going well then the Seeker seems to get stuck. if the Seeker is to the left of the Player it has a very hard time going back right. It will tend to just "jiggle" up and down.
Also anybody have any clever idea as to how I can check to see if the player has completed a box on the screen? Or am I just going to have to use POINT(a lot) to see if the color all around a box is done?

Code: QB64: [Select]
  1. 'Gapper(1986) Clone
  2. '10\25\2019 Cobalt
  3. ' ÀInitial Start; Layout, Gapper, Seeker, L1 Grid finished [13:55EDT]
  4. ' ÀCorrected 'Catcher' to 'Seeker' as per original game
  5.  
  6. TYPE GameData
  7.  Player AS STRING * 4
  8.  Score AS LONG
  9.  Lives AS _BYTE
  10.  Level AS _BYTE
  11.  GX AS INTEGER
  12.  GY AS INTEGER
  13.  GD AS _BYTE 'Gapper direction
  14.  SX AS INTEGER
  15.  SY AS INTEGER
  16.  SS AS _BYTE 'Seeker speed
  17.  SD AS _BYTE 'Seeker direction
  18.  Start AS _BYTE 'is level started or not(nothing happens until started)
  19.  FPS AS INTEGER
  20.  
  21. CONST TRUE = -1, FALSE = NOT TRUE, Gapper = 1, Seeker = 2
  22. CONST UP = 1, DOWN = 2, LEFT = 3, RIGHT = 4
  23. CONST Key_Right = 19712, Key_Left = 19200, Key_Up = 18432, Key_Down = 20480
  24. CONST Key_Space = 32, Key_Enter = 13
  25. CONST Cyan = &HFF10E0E0~& '_RGB32(0, 170, 170)
  26. CONST Magenta = &HFFC040C0~&
  27. CONST OffWhite = &HFFC0C0C0~&
  28. CONST Brown = &HFFB06000~&
  29.  
  30.  
  31. SCREEN _NEWIMAGE(640, 440, 32)
  32. DIM SHARED Layer(10) AS LONG, G AS GameData, Frames%
  33.  
  34. Layer(0) = _DISPLAY
  35. Layer(1) = _NEWIMAGE(640, 440, 32) 'mix layer
  36. Layer(2) = _NEWIMAGE(320, 220, 32) 'Grid Layer
  37. Layer(3) = _NEWIMAGE(640, 440, 32) 'Sprite layer
  38. Layer(4) = _NEWIMAGE(320, 220, 32) 'Info layer
  39. Layer(5) = _NEWIMAGE(640, 440, 32) 'Collision 'Gapper\Catcher' layer
  40. Layer(6) = _NEWIMAGE(640, 440, 32) 'Collision 'Grid' layer
  41. Layer(7) = _NEWIMAGE(640, 440, 32) 'debug layer
  42.  
  43. _FONT 8, Layer(4)
  44. _CLEARCOLOR _RGB32(0, 0, 0), Layer(3)
  45. _CLEARCOLOR _RGB32(0, 0, 0), Layer(7)
  46. _SOURCE Layer(6)
  47.  
  48. ON TIMER(t1&, 1) FPS
  49.  
  50. Game_INIT
  51. DrawBoard
  52. TIMER(t1&) ON
  53.  IF _KEYDOWN(27) THEN ExitFlag%% = TRUE
  54.  IF _KEYDOWN(Key_Up) THEN
  55.   G.Start = TRUE
  56.   IF NOT Collision_Grid(Gapper, UP) THEN G.GD = UP
  57.  IF _KEYDOWN(Key_Down) THEN
  58.   G.Start = TRUE
  59.   IF NOT Collision_Grid(Gapper, DOWN) THEN G.GD = DOWN
  60.  IF _KEYDOWN(Key_Left) THEN
  61.   G.Start = TRUE
  62.   IF NOT Collision_Grid(Gapper, LEFT) THEN G.GD = LEFT
  63.  IF _KEYDOWN(Key_Right) THEN
  64.   G.Start = TRUE
  65.   IF NOT Collision_Grid(Gapper, RIGHT) THEN G.GD = RIGHT
  66.  
  67.  IF G.Start THEN Move_Seeker: Move_Gapper
  68.  
  69.  Game_Data_Update
  70.  _PUTIMAGE , Layer(4), Layer(1)
  71.  _PUTIMAGE , Layer(2), Layer(1)
  72.  Place_Gapper
  73.  Place_Seeker
  74.  _PRINTSTRING (600, 0), STR$(G.FPS), Layer(7)
  75.  _PUTIMAGE , Layer(7), Layer(1)
  76.  _PUTIMAGE , Layer(1), Layer(0)
  77.  _LIMIT 60
  78.  ClearLayer Layer(1)
  79.  Frames% = Frames% + 1
  80. LOOP UNTIL ExitFlag%%
  81.  
  82. _PUTIMAGE , Layer(6), Layer(0)
  83.  
  84.  
  85. SUB Place_Gapper
  86.  'place gapper-----
  87.  _PUTIMAGE (G.GX, G.GY), Layer(3), Layer(1), (318, 218)-STEP(15, 13)
  88.  
  89. SUB Place_Seeker
  90.  'place Seeker----
  91.  _PUTIMAGE (G.SX, G.SY), Layer(3), Layer(1), (341, 218)-STEP(14, 11)
  92.  '-----------------
  93.  
  94.  
  95. SUB Game_INIT
  96.  _DEST Layer(3)
  97.  'Player----
  98.  DRAW "c" + STR$(Cyan) + "drurd8l2dr3u9d2rd5ru5rd5ru5ru2d9r3ul2u8r2dlbl3c" + STR$(Magenta) + "u3ld3lu3ld3"
  99.  DRAW "bd7d3ru3rd3ru3bu3br3r4ul4bl9l4dr4"
  100.  '----------
  101.  DRAW "br20bu7"
  102.  'Seeker----
  103.  DRAW "c" + STR$(Cyan) + "r3dl3bd10r3ul3br10r3dl3bu10r3ul3c" + STR$(Magenta) + "bd2brl3dr3bd5l3dr3bl6l3ur3"
  104.  DRAW "bu5l3ur3d2lr5dl5dr5dl5"
  105.  '------------
  106.  'Header
  107.  _DEST Layer(4)
  108.  LINE (84, 0)-STEP(151, 8), Magenta, BF
  109.  LINE (132, 0)-STEP(52, 8), Cyan, BF
  110.  COLOR Magenta
  111.  _PRINTSTRING (135, 1), "GAPPER"
  112.  COLOR OffWhite
  113.  _DEST Layer(0)
  114.  G.Score = 0
  115.  G.Lives = 2
  116.  G.Level = 1
  117.  'Level 1 Start Pos.------
  118.  G.GX = 0: G.GY = 14 'Gapper
  119.  G.SX = 626: G.SY = 374 'Seeker
  120.  '------------------------
  121.  
  122. SUB Game_Data_Update
  123.  'Info area updating ---------------
  124.  _PRINTSTRING (7, 192), "Score[      ]    Lives[ ]    Level[  ]", Layer(4)
  125.  _PRINTSTRING (95 - ((LEN(LTRIM$(STR$(G.Score))) - 1) * 8), 192), LTRIM$(STR$(G.Score)), Layer(4)
  126.  _PRINTSTRING (191, 192), LTRIM$(STR$(G.Lives)), Layer(4)
  127.  _PRINTSTRING (295 - ((LEN(LTRIM$(STR$(G.Level))) - 1) * 8), 192), LTRIM$(STR$(G.Level)), Layer(4)
  128.  '-----------------------------------
  129.  
  130. SUB DrawBoard
  131.  _DEST Layer(2)
  132.  SELECT CASE G.Level
  133.   CASE 1 'draw level 1 grid
  134.    FOR I%% = 0 TO 3
  135.     LINE (4, 10 + I%% * 60)-STEP(311, 0), Cyan 'horizontal lines
  136.     LINE (4 + I%% * 104, 10)-STEP(0, 180), Cyan 'vertical lines
  137.    NEXT I%%
  138.    G.SS = 1 'set seeker speed 1\4th player speed
  139.    G.Start = FALSE
  140.  _DEST Layer(0)
  141.  ClearLayer Layer(6)
  142.  _PUTIMAGE , Layer(2), Layer(6) 'make a copy for the collision layer
  143.  
  144. SUB ClearLayer (L&)
  145.  _DEST L&
  146.  CLS
  147.  
  148. FUNCTION Collision_Grid%% (who%%, Direction%%)
  149.  Result%% = TRUE 'always assume collision
  150.  ' _SOURCE Layer(6)
  151.  SELECT CASE who%% 'who are we checking collision for?
  152.   CASE Gapper
  153.    SELECT CASE Direction%%
  154.     CASE UP 'see if there is grid up from Gappers position
  155.      Check~& = POINT(G.GX + 8, G.GY + 5)
  156.     CASE DOWN 'see if there is Grid below Gapper
  157.      Check~& = POINT(G.GX + 8, G.GY + 9)
  158.     CASE LEFT 'check for grid to the left of Gapper
  159.      Check~& = POINT(G.GX + 6, G.GY + 7)
  160.     CASE RIGHT 'Check for grid to the Right of Gapper
  161.      Check~& = POINT(G.GX + 10, G.GY + 7)
  162.    END SELECT
  163.   CASE Seeker
  164.    SELECT CASE Direction%%
  165.     CASE UP 'see if there is grid up from Gappers position
  166.      Check~& = POINT(G.SX + 8, G.SY + 5)
  167.     CASE DOWN 'see if there is Grid below Gapper
  168.      Check~& = POINT(G.SX + 8, G.SY + 9)
  169.     CASE LEFT 'check for grid to the left of Gapper
  170.      Check~& = POINT(G.SX + 6, G.SY + 7)
  171.     CASE RIGHT 'Check for grid to the Right of Gapper
  172.      Check~& = POINT(G.SX + 10, G.SY + 7)
  173.    END SELECT
  174.  Blue~%% = _BLUE32(Check~&) 'check for Blue, grid is Cyan in color
  175.  IF Blue~%% THEN Result%% = FALSE 'there is grid to move onto, no collision with edge of grid
  176.  
  177.  
  178.  Collision_Grid = Result%%
  179.  '_SOURCE Layer(0)
  180.  
  181.  
  182. SUB Move_Seeker
  183.  STATIC Mover%%
  184.  Seeker_Logic
  185.  IF Mover%% < G.SS THEN
  186.   Mover%% = Mover%% + 1
  187.   Mover%% = 0
  188.   SELECT CASE G.SD
  189.    CASE UP
  190.     IF NOT Collision_Grid(Seeker, UP) THEN G.SY = G.SY - 2
  191.    CASE DOWN
  192.     IF NOT Collision_Grid(Seeker, DOWN) THEN G.SY = G.SY + 2
  193.    CASE LEFT
  194.     IF NOT Collision_Grid(Seeker, LEFT) THEN G.SX = G.SX - 2
  195.    CASE RIGHT
  196.     IF NOT Collision_Grid(Seeker, RIGHT) THEN G.SX = G.SX + 2
  197.  _PRINTSTRING (10, 410), STR$(Mover%%) + STR$(G.SD) + STR$(G.SX - G.GX) + STR$(G.SY - G.GY), Layer(7)
  198.  
  199. SUB Move_Gapper
  200.  SELECT CASE G.GD
  201.   CASE UP
  202.    IF NOT Collision_Grid(Gapper, UP) THEN G.GY = G.GY - 2
  203.   CASE DOWN
  204.    IF NOT Collision_Grid(Gapper, DOWN) THEN G.GY = G.GY + 2
  205.   CASE LEFT
  206.    IF NOT Collision_Grid(Gapper, LEFT) THEN G.GX = G.GX - 2
  207.   CASE RIGHT
  208.    IF NOT Collision_Grid(Gapper, RIGHT) THEN G.GX = G.GX + 2
  209.  Color_Line
  210.  
  211. SUB Seeker_Logic
  212.  DistX% = (G.SX - G.GX) 'find X distance between seeker and gapper
  213.  DistY% = (G.SY - G.GY) 'find Y distance between Seeker and Gapper
  214.  IF DistX% > DistY% THEN 'if player is farther on the X then
  215.   IF DistX% < 0 THEN
  216.    Turn_Seeker RIGHT 'try going right to get closer
  217.   ELSE
  218.    Turn_Seeker LEFT 'try going left to get closer
  219.   END IF
  220.  ELSE 'player is farther on the Y then
  221.   IF DistY% < 0 THEN
  222.    Turn_Seeker DOWN 'try going down to get closer
  223.   ELSE
  224.    Turn_Seeker UP 'try going up to get closer
  225.   END IF
  226.  
  227. SUB Turn_Seeker (Direction%%)
  228.  SELECT CASE Direction%%
  229.   CASE UP
  230.    IF NOT Collision_Grid(Seeker, UP) THEN G.SD = UP
  231.   CASE DOWN
  232.    IF NOT Collision_Grid(Seeker, DOWN) THEN G.SD = DOWN
  233.   CASE LEFT
  234.    IF NOT Collision_Grid(Seeker, LEFT) THEN G.SD = LEFT
  235.   CASE RIGHT
  236.    IF NOT Collision_Grid(Seeker, RIGHT) THEN G.SD = RIGHT
  237.  
  238. SUB Color_Line
  239.  _DEST Layer(2)
  240.  LINE (4 + G.GX \ 2, 3 + G.GY \ 2)-STEP(0, 0), Magenta, BF
  241.  _DEST Layer(0)
  242.  
  243. SUB FPS
  244.  G.FPS = Frames%
  245.  Frames% = 0
« Last Edit: November 01, 2021, 07:54:56 pm by Cobalt »
Granted after becoming radioactive I only have a half-life!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Gapper(a game from 1986!) Why does my seeker get stuck?
« Reply #1 on: October 28, 2021, 11:58:00 am »
You might explain the game more, I haven't a clue what is suppose to happen.

The * controlled by arrow keys is supposed to avoid the X which seems to move on it's own?

When * runs through X nothing happens, so... ?

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Gapper(a game from 1986!) Why does my seeker get stuck?
« Reply #2 on: October 28, 2021, 03:38:29 pm »
so the Seeker(X) is trying to catch the Player(*). The goal is to color all the cyan lines magenta you get a score for each box closed in.
video of the original game.
&t=1s

Granted after becoming radioactive I only have a half-life!

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Gapper(a game from 1986!) Why does my seeker get stuck?
« Reply #3 on: October 28, 2021, 04:48:58 pm »
Interesting.  I haven't heard of this game before.  Clean code.  I haven't scored any points yet. But on the positive, I haven't died yet.  Looks like a good job cloning the look and feel of the original on the video.

- Dav

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Gapper(a game from 1986!) Why does my seeker get stuck?
« Reply #4 on: October 28, 2021, 05:00:43 pm »
@Cobalt  Might want to compare Absolute Values of DistX% and DistY% (In SeekerLogic sub)

Code: QB64: [Select]
  1. If DistX% > DistY% Then 'if player is farther on the X then    
  2.  

As a matter of chaser strategy, why doesn't the X just guard all points on middle square? I think they call it goal tending.

Update: It fixed problem for me just a couple of ABS() around DistX% and DistY% in line above.
« Last Edit: October 29, 2021, 11:54:19 am by bplus »

Offline keybone

  • Forum Regular
  • Posts: 116
  • My name a Nursultan Tulyakbay.
    • View Profile
Re: Gapper(a game from 1986!) Why does my seeker get stuck?
« Reply #5 on: October 28, 2021, 05:32:34 pm »
Gapper is awesome! I love that game.
I am from a Kazakhstan, we follow the hawk.

Offline keybone

  • Forum Regular
  • Posts: 116
  • My name a Nursultan Tulyakbay.
    • View Profile
Re: Gapper(a game from 1986!) Why does my seeker get stuck?
« Reply #6 on: October 28, 2021, 08:45:36 pm »
Here you go, i don't want to explain everthing I did, let's just say i had to redesign the seeker logic.

Code: [Select]
'Gapper(1986) Clone
'10\25\2019 Cobalt
' ÀInitial Start; Layout, Gapper, Seeker, L1 Grid finished [13:55EDT]
' ÀCorrected 'Catcher' to 'Seeker' as per original game

TYPE GameData
    Player AS STRING * 4
    Score AS LONG
    Lives AS _BYTE
    Level AS _BYTE
    GX AS INTEGER
    GY AS INTEGER
    GD AS _BYTE 'Gapper direction
    SX AS INTEGER
    SY AS INTEGER
    SS AS _BYTE 'Seeker speed
    SD AS _BYTE 'Seeker direction
    Start AS _BYTE 'is level started or not(nothing happens until started)
    FPS AS INTEGER
END TYPE

CONST TRUE = -1, FALSE = NOT TRUE, Gapper = 1, Seeker = 2
CONST UP = 1, DOWN = 2, LEFT = 3, RIGHT = 4
CONST Key_Right = 19712, Key_Left = 19200, Key_Up = 18432, Key_Down = 20480
CONST Key_Space = 32, Key_Enter = 13
CONST Cyan = &HFF10E0E0~& '_RGB32(0, 170, 170)
CONST Magenta = &HFFC040C0~&
CONST OffWhite = &HFFC0C0C0~&
CONST Brown = &HFFB06000~&


SCREEN _NEWIMAGE(640, 440, 32)
DIM SHARED Layer(10) AS _UNSIGNED LONG, G AS GameData, Frames%

Layer(0) = _DISPLAY
Layer(1) = _NEWIMAGE(640, 440, 32) 'mix layer
Layer(2) = _NEWIMAGE(320, 220, 32) 'Grid Layer
Layer(3) = _NEWIMAGE(640, 440, 32) 'Sprite layer
Layer(4) = _NEWIMAGE(320, 220, 32) 'Info layer
Layer(5) = _NEWIMAGE(640, 440, 32) 'Collision 'Gapper\Catcher' layer
Layer(6) = _NEWIMAGE(640, 440, 32) 'Collision 'Grid' layer
Layer(7) = _NEWIMAGE(640, 440, 32) 'debug layer

_FONT 8, Layer(4)
_CLEARCOLOR _RGB32(0, 0, 0), Layer(3)
_CLEARCOLOR _RGB32(0, 0, 0), Layer(7)
_PRINTMODE _KEEPBACKGROUND , Layer(4)
_SCREENMOVE 16, 16
_SOURCE Layer(6)

ON TIMER(t1&, 1) gFPS

Game_INIT
DrawBoard
TIMER(t1&) ON
DO
    IF _KEYDOWN(27) THEN ExitFlag%% = TRUE
    IF _KEYDOWN(Key_Up) THEN
        G.Start = TRUE
        IF NOT Collision_Grid(Gapper, UP) THEN G.GD = UP
    END IF
    IF _KEYDOWN(Key_Down) THEN
        G.Start = TRUE
        IF NOT Collision_Grid(Gapper, DOWN) THEN G.GD = DOWN
    END IF
    IF _KEYDOWN(Key_Left) THEN
        G.Start = TRUE
        IF NOT Collision_Grid(Gapper, LEFT) THEN G.GD = LEFT
    END IF
    IF _KEYDOWN(Key_Right) THEN
        G.Start = TRUE
        IF NOT Collision_Grid(Gapper, RIGHT) THEN G.GD = RIGHT
    END IF

    IF G.Start THEN Move_Seeker: Move_Gapper

    Game_Data_Update
    _PUTIMAGE , Layer(4), Layer(1)
    _PUTIMAGE , Layer(2), Layer(1)
    Place_Gapper
    Place_Seeker
    _PRINTSTRING (600, 0), STR$(G.FPS), Layer(7)
    _PUTIMAGE , Layer(7), Layer(1)
    _PUTIMAGE , Layer(1), Layer(0)
    _LIMIT 60
    ClearLayer Layer(1)
    Frames% = Frames% + 1
LOOP UNTIL ExitFlag%%

CLS
_PUTIMAGE , Layer(6), Layer(0)


SUB Place_Gapper
    'place gapper-----
    _PUTIMAGE (G.GX, G.GY), Layer(3), Layer(1), (318, 218)-STEP(15, 13)
END SUB

SUB Place_Seeker
    'place Seeker----
    _PUTIMAGE (G.SX, G.SY), Layer(3), Layer(1), (341, 218)-STEP(14, 11)
    '-----------------
END SUB


SUB Game_INIT
    _DEST Layer(3)
    'Player----
    DRAW "c" + STR$(Cyan) + "drurd8l2dr3u9d2rd5ru5rd5ru5ru2d9r3ul2u8r2dlbl3c" + STR$(Magenta) + "u3ld3lu3ld3"
    DRAW "bd7d3ru3rd3ru3bu3br3r4ul4bl9l4dr4"
    '----------
    DRAW "br20bu7"
    'Seeker----
    DRAW "c" + STR$(Cyan) + "r3dl3bd10r3ul3br10r3dl3bu10r3ul3c" + STR$(Magenta) + "bd2brl3dr3bd5l3dr3bl6l3ur3"
    DRAW "bu5l3ur3d2lr5dl5dr5dl5"
    '------------
    'Header
    _DEST Layer(4)
    LINE (84, 0)-STEP(151, 8), Magenta, BF
    LINE (132, 0)-STEP(52, 8), Cyan, BF
    COLOR Magenta
    _PRINTSTRING (135, 1), "GAPPER"
    COLOR OffWhite
    _DEST Layer(0)
    G.Score = 0
    G.Lives = 2
    G.Level = 1
    'Level 1 Start Pos.------
    G.GX = 0: G.GY = 14 'Gapper
    G.SX = 626: G.SY = 374 'Seeker
    '------------------------
END SUB

SUB Game_Data_Update
    'Info area updating ---------------
    _PRINTSTRING (7, 192), "Score[      ]    Lives[ ]    Level[  ]", Layer(4)
    _PRINTSTRING (95 - ((LEN(LTRIM$(STR$(G.Score))) - 1) * 8), 192), LTRIM$(STR$(G.Score)), Layer(4)
    _PRINTSTRING (191, 192), LTRIM$(STR$(G.Lives)), Layer(4)
    _PRINTSTRING (295 - ((LEN(LTRIM$(STR$(G.Level))) - 1) * 8), 192), LTRIM$(STR$(G.Level)), Layer(4)
    '-----------------------------------
END SUB

SUB DrawBoard
    _DEST Layer(2)
    SELECT CASE G.Level
        CASE 1 'draw level 1 grid
            FOR I%% = 0 TO 3
                LINE (4, 10 + I%% * 60)-STEP(311, 0), Cyan 'horizontal lines
                LINE (4 + I%% * 104, 10)-STEP(0, 180), Cyan 'vertical lines
            NEXT I%%
            G.SS = 1 'set seeker speed 1\4th player speed
            G.Start = FALSE
    END SELECT
    _DEST Layer(0)
    ClearLayer Layer(6)
    _PUTIMAGE , Layer(2), Layer(6) 'make a copy for the collision layer
END SUB

SUB ClearLayer (L&)
    _DEST L&
    CLS
    _DEST _DISPLAY
END SUB

FUNCTION Collision_Grid%% (who%%, Direction%%)
    Result%% = TRUE 'always assume collision
    ' _SOURCE Layer(6)
    SELECT CASE who%% 'who are we checking collision for?
        CASE Gapper
            SELECT CASE Direction%%
                CASE UP 'see if there is grid up from Gappers position
                    Check~& = POINT(G.GX + 8, G.GY + 5)
                CASE DOWN 'see if there is Grid below Gapper
                    Check~& = POINT(G.GX + 8, G.GY + 9)
                CASE LEFT 'check for grid to the left of Gapper
                    Check~& = POINT(G.GX + 6, G.GY + 7)
                CASE RIGHT 'Check for grid to the Right of Gapper
                    Check~& = POINT(G.GX + 10, G.GY + 7)
            END SELECT
        CASE Seeker
            SELECT CASE Direction%%
                CASE UP 'see if there is grid up from Gappers position
                    Check~& = POINT(G.SX + 8, G.SY + 5)
                CASE DOWN 'see if there is Grid below Gapper
                    Check~& = POINT(G.SX + 8, G.SY + 9)
                CASE LEFT 'check for grid to the left of Gapper
                    Check~& = POINT(G.SX + 6, G.SY + 7)
                CASE RIGHT 'Check for grid to the Right of Gapper
                    Check~& = POINT(G.SX + 10, G.SY + 7)
            END SELECT
    END SELECT
    Blue~%% = _BLUE32(Check~&) 'check for Blue, grid is Cyan in color
    IF Blue~%% THEN Result%% = FALSE 'there is grid to move onto, no collision with edge of grid


    Collision_Grid = Result%%
    '_SOURCE Layer(0)
END FUNCTION


SUB Move_Seeker
    STATIC Mover%%
    Seeker_Logic
    IF Mover%% < G.SS THEN
        Mover%% = Mover%% + 1
    ELSE
        Mover%% = 0
        SELECT CASE G.SD
            CASE UP
                IF NOT Collision_Grid(Seeker, UP) THEN G.SY = G.SY - 2
            CASE DOWN
                IF NOT Collision_Grid(Seeker, DOWN) THEN G.SY = G.SY + 2
            CASE LEFT
                IF NOT Collision_Grid(Seeker, LEFT) THEN G.SX = G.SX - 2
            CASE RIGHT
                IF NOT Collision_Grid(Seeker, RIGHT) THEN G.SX = G.SX + 2
        END SELECT
    END IF
    _PRINTSTRING (10, 410), STR$(Mover%%) + STR$(G.SD) + STR$(G.SX - G.GX) + STR$(G.SY - G.GY), Layer(7)
END SUB

SUB Move_Gapper
    SELECT CASE G.GD
        CASE UP
            IF NOT Collision_Grid(Gapper, UP) THEN G.GY = G.GY - 2
        CASE DOWN
            IF NOT Collision_Grid(Gapper, DOWN) THEN G.GY = G.GY + 2
        CASE LEFT
            IF NOT Collision_Grid(Gapper, LEFT) THEN G.GX = G.GX - 2
        CASE RIGHT
            IF NOT Collision_Grid(Gapper, RIGHT) THEN G.GX = G.GX + 2
    END SELECT
    Color_Line
END SUB

SUB Seeker_Logic
    IF G.SX > G.GX THEN
        DistX% = (G.SX - G.GX) 'find X distance between seeker and gapper
    ELSE
        DistX% = (G.GX - G.SX) 'find X distance between seeker and gapper
    END IF
    IF G.SY > G.GY THEN
        DistY% = (G.SY - G.GY) 'find Y distance between seeker and gapper
    ELSE
        DistY% = (G.GY - G.SY) 'find Y distance between seeker and gapper
    END IF
    IF DistX% > DistY% THEN 'if player is farther on the X then
        IF G.SX > G.GX THEN
            Turn_Seeker LEFT
        ELSE
            Turn_Seeker RIGHT
        END IF
    ELSE 'player is farther on the Y then
        IF G.SY > G.GY THEN
            Turn_Seeker UP
        ELSE
            Turn_Seeker DOWN
        END IF
    END IF
END SUB

SUB Turn_Seeker (Direction%%)
    SELECT CASE Direction%%
        CASE UP
            IF NOT Collision_Grid(Seeker, UP) THEN G.SD = UP
        CASE DOWN
            IF NOT Collision_Grid(Seeker, DOWN) THEN G.SD = DOWN
        CASE LEFT
            IF NOT Collision_Grid(Seeker, LEFT) THEN G.SD = LEFT
        CASE RIGHT
            IF NOT Collision_Grid(Seeker, RIGHT) THEN G.SD = RIGHT
    END SELECT
END SUB

SUB Color_Line
    _DEST Layer(2)
    LINE (4 + G.GX \ 2, 3 + G.GY \ 2)-STEP(0, 0), Magenta, BF
    _DEST Layer(0)
END SUB

SUB gFPS
    G.FPS = Frames%
    Frames% = 0
END SUB

« Last Edit: October 28, 2021, 09:06:07 pm by keybone »
I am from a Kazakhstan, we follow the hawk.

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Gapper(a game from 1986!) Why does my seeker get stuck?
« Reply #7 on: October 30, 2021, 03:40:31 pm »
@Cobalt  Might want to compare Absolute Values of DistX% and DistY% (In SeekerLogic sub)

Code: QB64: [Select]
  1. If DistX% > DistY% Then 'if player is farther on the X then    
  2.  

As a matter of chaser strategy, why doesn't the X just guard all points on middle square? I think they call it goal tending.

Update: It fixed problem for me just a couple of ABS() around DistX% and DistY% in line above.

Yep, all it needed. Noticing the 2 lines above it having  () I probably had tried ABS there at one time which didn't work. Just needed to place them in the right place.

And its called a Seeker, not Goal Keeper. So its out to get you, not stop you. Well not stop you from getting somewhere anyway.
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: Gapper(a game from 1986!) Why does my seeker get stuck?
« Reply #8 on: October 30, 2021, 03:47:30 pm »
Here you go, i don't want to explain everthing I did, let's just say i had to redesign the seeker logic.

Thanks @keybone. why the change to FPS though?

Bplus's fix is a little less 'invasive' though
Granted after becoming radioactive I only have a half-life!

Offline keybone

  • Forum Regular
  • Posts: 116
  • My name a Nursultan Tulyakbay.
    • View Profile
Re: Gapper(a game from 1986!) Why does my seeker get stuck?
« Reply #9 on: October 31, 2021, 09:54:51 am »
Thanks @keybone. why the change to FPS though?

Bplus's fix is a little less 'invasive' though

Youre welcome. It's just something I did during the 3 hours I spent trying to figure out why it wasn't working.  I'm not entirely sure why i did it at this point.
« Last Edit: October 31, 2021, 10:00:39 am by keybone »
I am from a Kazakhstan, we follow the hawk.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Gapper(a game from 1986!) Why does my seeker get stuck?
« Reply #10 on: November 05, 2021, 11:32:19 pm »
@Cobalt  Might want to compare Absolute Values of DistX% and DistY% (In SeekerLogic sub)

Code: QB64: [Select]
  1. If DistX% > DistY% Then 'if player is farther on the X then    
  2.  

As a matter of chaser strategy, why doesn't the X just guard all points on middle square? I think they call it goal tending.

Update: It fixed problem for me just a couple of ABS() around DistX% and DistY% in line above.

Great catch! You got it!
The subtile logic that negative number are littler than 0 and so it looses the negative dimension (i.e-2) vs 0 in math,
otherwise the 0 distance is littler than another position both to right/down (positive) both to left/bottom (negative).
Programming isn't difficult, only it's  consuming time and coffee

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Gapper(a game from 1986!) Why does my seeker get stuck?(Fixed with ABS)
« Reply #11 on: November 08, 2021, 02:43:51 pm »
@Cobalt
Waiting for final release to play....

I cannot play it without your sharing...!
Programming isn't difficult, only it's  consuming time and coffee