'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
Start
AS _BYTE 'is level started or not(nothing happens until started)
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~&
Layer
(1) = _NEWIMAGE(640, 440, 32) 'mix layerLayer
(2) = _NEWIMAGE(320, 220, 32) 'Grid LayerLayer
(3) = _NEWIMAGE(640, 440, 32) 'Sprite layerLayer
(4) = _NEWIMAGE(320, 220, 32) 'Info layerLayer
(5) = _NEWIMAGE(640, 440, 32) 'Collision 'Gapper\Catcher' layerLayer
(6) = _NEWIMAGE(640, 440, 32) 'Collision 'Grid' layerLayer
(7) = _NEWIMAGE(640, 440, 32) 'debug layer
Game_INIT
DrawBoard
G.Start = TRUE
IF NOT Collision_Grid
(Gapper
, UP
) THEN G.GD
= UP
G.Start = TRUE
IF NOT Collision_Grid
(Gapper
, DOWN
) THEN G.GD
= DOWN
G.Start = TRUE
IF NOT Collision_Grid
(Gapper
, LEFT
) THEN G.GD
= LEFT
G.Start = TRUE
IF NOT Collision_Grid
(Gapper
, RIGHT
) THEN G.GD
= RIGHT
IF G.Start
THEN Move_Seeker: Move_Gapper
Game_Data_Update
Place_Gapper
Place_Seeker
ClearLayer Layer(1)
Frames% = Frames% + 1
'place gapper-----
_PUTIMAGE (G.GX
, G.GY
), Layer
(3), Layer
(1), (318, 218)-STEP(15, 13)
'place Seeker----
_PUTIMAGE (G.SX
, G.SY
), Layer
(3), Layer
(1), (341, 218)-STEP(14, 11) '-----------------
'Player----
DRAW "c" + STR$(Cyan
) + "drurd8l2dr3u9d2rd5ru5rd5ru5ru2d9r3ul2u8r2dlbl3c" + STR$(Magenta
) + "u3ld3lu3ld3" DRAW "bd7d3ru3rd3ru3bu3br3r4ul4bl9l4dr4" '----------
'Seeker----
DRAW "c" + STR$(Cyan
) + "r3dl3bd10r3ul3br10r3dl3bu10r3ul3c" + STR$(Magenta
) + "bd2brl3dr3bd5l3dr3bl6l3ur3" DRAW "bu5l3ur3d2lr5dl5dr5dl5" '------------
'Header
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
'------------------------
'Info area updating ---------------
_PRINTSTRING (7, 192), "Score[ ] Lives[ ] Level[ ]", Layer
(4) '-----------------------------------
CASE 1 'draw level 1 grid LINE (4, 10 + I%%
* 60)-STEP(311, 0), Cyan
'horizontal lines LINE (4 + I%%
* 104, 10)-STEP(0, 180), Cyan
'vertical lines G.SS = 1 'set seeker speed 1\4th player speed
G.Start = FALSE
ClearLayer Layer(6)
_PUTIMAGE , Layer
(2), Layer
(6) 'make a copy for the collision layer
FUNCTION Collision_Grid%%
(who%%
, Direction%%
) Result%% = TRUE 'always assume collision
' _SOURCE Layer(6)
SELECT CASE who%%
'who are we checking collision for? 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) 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) 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)
Seeker_Logic
Mover%% = Mover%% + 1
Mover%% = 0
IF NOT Collision_Grid
(Seeker
, UP
) THEN G.SY
= G.SY
- 2 IF NOT Collision_Grid
(Seeker
, DOWN
) THEN G.SY
= G.SY
+ 2 IF NOT Collision_Grid
(Seeker
, LEFT
) THEN G.SX
= G.SX
- 2 IF NOT Collision_Grid
(Seeker
, RIGHT
) THEN G.SX
= G.SX
+ 2
IF NOT Collision_Grid
(Gapper
, UP
) THEN G.GY
= G.GY
- 2 IF NOT Collision_Grid
(Gapper
, DOWN
) THEN G.GY
= G.GY
+ 2 IF NOT Collision_Grid
(Gapper
, LEFT
) THEN G.GX
= G.GX
- 2 IF NOT Collision_Grid
(Gapper
, RIGHT
) THEN G.GX
= G.GX
+ 2 Color_Line
DistX% = (G.SX - G.GX) 'find X distance between seeker and gapper
DistY% = (G.SY - G.GY) 'find Y distance between Seeker and Gapper
IF DistX%
> DistY%
THEN 'if player is farther on the X then Turn_Seeker RIGHT 'try going right to get closer
Turn_Seeker LEFT 'try going left to get closer
ELSE 'player is farther on the Y then Turn_Seeker DOWN 'try going down to get closer
Turn_Seeker UP 'try going up to get closer
SUB Turn_Seeker
(Direction%%
) IF NOT Collision_Grid
(Seeker
, UP
) THEN G.SD
= UP
IF NOT Collision_Grid
(Seeker
, DOWN
) THEN G.SD
= DOWN
IF NOT Collision_Grid
(Seeker
, LEFT
) THEN G.SD
= LEFT
IF NOT Collision_Grid
(Seeker
, RIGHT
) THEN G.SD
= RIGHT
LINE (4 + G.GX \
2, 3 + G.GY \
2)-STEP(0, 0), Magenta
, BF
G.FPS = Frames%
Frames% = 0