03-15-2006, 09:28 PM
Code:
? Int( Log( 256 ) )
Sleep
?
on topic:
now you can just adjust the numbers.
Code:
TYPE matrix
x AS INTEGER
y AS INTEGER
END TYPE
DEFINT A-Z
'$DYNAMIC
DIM SHARED tilesize AS matrix, mapsize AS matrix, visbox AS matrix
visbox.x = 100
visbox.y = 80
tilesize.x = 16
tilesize.y = 12
' Tile 0
DATA 1,2,3,4,5,6,1,1,1,1,1,1,1,1,1,1
DATA 1,1,1,1,2,2,1,1,1,1,2,2,1,1,1,1
DATA 1,2,3,4,5,5,4,3,3,4,5,5,4,3,2,1
DATA 1,1,1,1,2,2,1,1,1,1,2,2,1,1,1,1
DATA 1,1,1,2,3,3,1,1,1,2,3,3,2,1,1,1
DATA 1,1,2,3,4,4,3,2,1,1,4,4,3,2,1,1
DATA 1,1,1,1,2,2,1,1,1,1,2,2,1,1,1,1
DATA 1,1,2,3,4,4,3,2,1,4,4,4,3,2,1,1
DATA 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
DATA 1,1,1,1,2,2,1,1,1,1,2,2,1,1,1,1
DATA 1,2,3,4,5,5,4,3,2,4,5,5,4,3,2,1
DATA 1,1,1,2,3,3,1,1,1,2,3,3,2,1,1,1
' Tile 1
DATA 1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6
DATA 2,1,1,1,2,2,1,1,1,1,2,2,1,1,1,1
DATA 3,1,1,2,3,3,1,1,1,2,3,3,2,1,1,1
DATA 4,1,2,3,4,4,3,2,1,4,4,4,3,2,1,1
DATA 5,2,3,4,5,5,4,3,3,4,5,5,4,3,2,1
DATA 6,2,3,4,5,5,4,3,2,4,5,5,4,3,2,1
DATA 7,1,1,2,3,3,2,1,1,2,3,3,2,1,1,1
DATA 8,1,1,1,2,2,1,1,1,1,2,2,1,1,1,1
DATA 9,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
DATA 0,1,1,1,2,2,1,1,1,1,2,2,1,1,1,1
DATA 1,1,1,1,2,2,1,1,1,1,2,2,1,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1 'Load the tiles
FOR i = 0 TO (tilesize.x * tilesize.y) - 1
READ tile(j, i)
NEXT
NEXT
FOR i = 0 TO (mapsize.x * mapsize.y) - 1: READ map(i): NEXT 'Load the map
SCREEN 13
CLS
DEF SEG = &HA000 'Point to the graphics buffer
hScroll = 0 'These variables will keep track of
vScroll = 0 'how far the screen has scrolled
PRINT "Use the number pad to scroll,"
PRINT "esc to quit."
DO
verticalVal = vScroll
tileX = hScroll \ tilesize.x 'Calculate all original values
tileY = verticalVal \ tilesize.y
mapElem = tileY * mapsize.x + tileX
spriteX = hScroll MOD tilesize.x
spriteY = vScroll MOD tilesize.y
spriteElem = spriteY * tilesize.x + spriteX
WAIT &H3DA, 8 'Wait for vertical retrace
' The two FOR..NEXT loops loop through the visible screen which is the box
' from (60, 110) to (139, 209).
FOR screenY = 60 TO 60 + visbox.y - 1
' Inside the second loop, the offset will only be increased by 1 each
' time through, so it's pointless to keep on recalculating it. If we
' calculate it once for each y loop and then just add 1 inside the x
' loop we can speed things up.
offset& = screenY * 320& + 110
FOR screenX = 110 TO 110 + visbox.x - 1
' Use the faster PSET. The colour location of the pixel in the tile
' array has been precalculated, we get the tile number from the map
' and then take the specific pixel. The offset is increased by 1
' each time through the loop to move horizontally across the screen.
POKE offset&, tile(map(mapElem), spriteElem)
offset& = offset& + 1
' Move over one pixel in the sprite, if we've moved on to the next
' tile then spriteElem will be a multiple of 10 (we move through
' pixels 0 to 9 and then when we hit 10, the width of the tile,
' we've moved on to the next tile). So spriteElem is knocked back
' to the first pixel of the row and we move 1 forward along the map.
spriteElem = spriteElem + 1
IF spriteElem MOD tilesize.x = 0 THEN
spriteElem = spriteElem - tilesize.x
mapElem = mapElem + 1
END IF
NEXT
' Recalculate the map element now that we've moved down one row in the
' sprite, and possibly down one row on the map. VerticalVal keeps track
' of the vertical motion down the map.
verticalVal = verticalVal + 1
tileY = verticalVal \ tilesize.y
mapElem = tileY * mapsize.x + tileX
' Recalculate the sprite element now that we've moved down one row in
' the sprite. If we've moved down to the next tile, knock the spriteY
' value back to the top of the tile.
spriteY = spriteY + 1
IF spriteY = tilesize.y THEN spriteY = 0
spriteElem = spriteY * tilesize.x + spriteX
NEXT
' Check for a key press and then clear the keyboard buffer.
key$ = INKEY$
DO: LOOP UNTIL INKEY$ = ""
' Adjust the hScroll and vScroll values to reflect how much the screen has
' been scrolled.
Select Case key$
Case "4"
If hScroll > 0 Then hScroll = hScroll - 1
Case "6"
If hScroll < (mapsize.x - (visbox.x / tilesize.x)) * tilesize.x Then hScroll = hScroll + 1
Case "8"
IF vScroll > 0 THEN vScroll = vScroll - 1
Case "2"
IF vScroll < (mapsize.y - (visbox.y / tilesize.y)) * tilesize.y THEN vScroll = vScroll + 1
Case "7"
IF hScroll > 0 THEN hScroll = hScroll - 1
If vScroll > 0 Then vScroll = vScroll - 1
Case "9"
IF hScroll < (mapsize.x - (visbox.x / tilesize.x)) * tilesize.x THEN hScroll = hScroll + 1
If vScroll > 0 Then vScroll = vScroll - 1
Case "1"
IF hScroll > 0 THEN hScroll = hScroll - 1
If vScroll < (mapsize.y - (visbox.y / tilesize.y)) * tilesize.y Then vScroll = vScroll + 1
Case "3"
IF hScroll < (mapsize.x - (visbox.x / tilesize.x)) * tilesize.x THEN hScroll = hScroll + 1
If vScroll < (mapsize.y - (visbox.y / tilesize.y)) * tilesize.y Then vScroll = vScroll + 1
End Select
Loop Until key$ = Chr$(27)