DIM MAP(9999) :'Defines and array for the map
FOR I=0 TO 9998 :'Set each tile of the map to 2
MAP(I)=2
NEXT I
GPAGE 0 :'Tell it we want to use the top screeen
SPPAGE 0 :'Tell it we want to use sprites on the top screen
SPSET 0,1,0,0,0,1,16,16 :'Creates sprite with id#0, arrow graphic, 16*16 dimensions
SPOFS 0,20,20 :'Sets the sprite's position to 20,20
WIDTH=15 :'Width of the map
HEIGHT=11 :'Height of the map
TILEW=16 :'Width of each map tile
TILEH=16 :'Height of each map tile
X=0 :'Cursors x position
Y=0 :'Cursors y position
TYPE=4 :'Color tile to be placed
BT=0 :'Bt and oldbt store the button pressed, and last button pressed
OLDBT=0
'Bgmplay 2 :' turns on background music, really annoying.
GCLS :' these next two lines clear the screen
CLS
GOTO @START :'Tells the program to skip ahead to the @start label, because the next section
:'will contain our subroutine definitions
@CHECKKEYS :'Checks for a and y being pressed and takes action
IF BT==64 THEN GOSUB @ACT
IF BT==16 THEN GOSUB @PENDOWN
RETURN
@UP :'Moves cursor up
OLDX=X
OLDY=Y
Y=Y-1
IF Y<0 THEN Y=0 :'Makes sure it doesn't go over the edge
RETURN
@DOWN :'Moves cursor down
OLDX=X
OLDY=Y
Y=Y+1
IF Y>HEIGHT THEN Y=HEIGHT :'Makes sure it doesn't go over the edge
RETURN
@LEFT :'Moves cursor left
OLDX=X
OLDY=Y
X=X-1
IF X<0 THEN X=0 :'Makes sure it doesn't go over the edge
RETURN
@RIGHT :'Moves cursor right
OLDX=X
OLDY=Y
X=X+1
IF X>WIDTH THEN X=WIDTH :'Makes sure it doesn't go over the edge
RETURN
@ACT :'Cycle through tile types
TYPE=TYPE+1
IF TYPE>9 THEN TYPE=0 :'Makes sure it doesn't try to use invalid tile type
RETURN
@PENDOWN :'Function places pendown if it was up and up if it was down
IF PDOWN==0 THEN BPDOWN=1
IF PDOWN==1 THEN BPDOWN=0
PDOWN=BPDOWN
RETURN
@START :'This is the start of the game loop
OLDBT=BT :'Updates what button is pressed, preserving the previous button press for comparison
BT=BUTTON()
IF BT==1 THEN GOSUB @UP
IF BT==8 THEN GOSUB @RIGHT
IF BT==2 THEN GOSUB @DOWN
IF BT==4 THEN GOSUB @LEFT
IF OLDBT==0 THEN GOSUB @CHECKKEYS :'Makes sure action is only taken the first time it dectects each button is hit.
IF PDOWN==1 THEN MAP(X+Y*WIDTH)=TYPE
SPOFS 0,X*TILEW,Y*TILEH :'Set the sprites position to our x,y coords * the dimensions of the tiles
FOR C=0 TO WIDTH :'This nested foor loop goes through the map and draws it tiles by tile
FOR V=0 TO HEIGHT :'Based on the values stored in the array map
GFILL C*TILEW,V*TILEH,C*TILEW+TILEW,V*TILEH+TILEH,MAP(C+V*WIDTH)
NEXT V
NEXT C
GOTO @START :'Completes came loop