Code: Select all
REM breakout
REM just a fun toy i made as i was waiting.
REM you can add more bricks and patterns
REM i was plannimg on adding sound, colors and diffrent backgrounds.
REM i ran out of time... v.2 bug fixes
REM enjoy...
GRAPHICS
sw=INT(SCREEN_WIDTH())
sh=INT(SCREEN_HEIGHT())-4
res = 20 ' size 2-20
deltax=res
deltay=res
DIM board(sw+res+res,sh+res+res)
px=sw/2
py=sh/2
brick=5 'brick strength
wall=10 'wall fix strength
'setup bricks and walls
setup:
FOR x = 0 TO sw-res STEP res
board(x,0) = wall
board(x,sh-res) = wall
NEXT x
FOR y = res TO sh-res STEP res
board(0,y) = wall
board(sw-res,y) = wall
NEXT y
FOR x = res TO sw-res-res STEP res
board(x,res) = brick
board(x,res*2) = brick
board(x,res*3) = brick
board(x,sh/2) = brick
NEXT x
FOR y = res TO sh-res-res STEP res
board(sw/2,y) = brick
NEXT y
main:
REFRESH OFF
GRAPHICS CLEAR 0,0,0
GOSUB moveplayer
GOSUB moveblock
GOSUB drawgrid
DRAW COLOR 0,1,0
DRAW TEXT px&":"&py&" "&deltax&":"&deltay AT 0,0
REFRESH
GOTO main
moveplayer:
'draw tail
FILL COLOR 0,0,0
FILL RECT px,py TO px+res,py+res
'move
px=px+deltax
py=py+deltay
'draw player / ball
FILL COLOR 1,0,0
FILL RECT px,py TO px+res,py+res
'test brick and ball
IF board(px,py-res)>0 AND deltay < 0 THEN
deltay=-deltay
IF board(px,py-res) <=brick THEN board(px,py-res)=board(px,py-res)-1
END IF
IF board(px+res,py)>0 AND deltax > 0 THEN
deltax=-deltax
IF board(px+res,py) <=brick THEN board(px+res,py)=board(px+res,py)-1
END IF
IF board(px,py+res)>0 AND deltay > 0 THEN
deltay=-deltay
IF board(px,py+res)<=brick THEN board(px,py+res)=board(px,py+res)-1
END IF
IF board(px-res,py)>0 AND deltax < 0 THEN
deltax=-deltax
IF board(px-res,py)<=brick THEN board(px-res,py)=board(px-res,py)-1
END IF
RETURN
'update bricks
moveblock:
FOR x = 0 TO sw STEP res
FOR y = 0 TO sh STEP res
IF board(x,y) > 0 THEN
IF board(x,y) = wall THEN
FILL COLOR 1,0,0
ELSE
FILL COLOR (board(x,y))/brick,board(x,y)/brick,board(x,y)/brick
END IF
FILL RECT x,y TO x+res,y+res
END IF
NEXT y
NEXT x
RETURN
'standard grid
drawgrid:
DRAW COLOR 1,1,1
FOR x = 0 TO sw-res STEP res
FOR y = 0 TO sh-res STEP res
DRAW RECT x,y TO x+res,y+res
NEXT y
NEXT x
RETURN