Wow, now that's streamlined! Ah, but old Silver knows his grid navs... the lowest I can get it in GM is 23 lines:
Card Script
gridMap$ = "1111111100000110000011000001100000110000011111111"
playerSpriteX = 137
playerSpriteY = 137
SPRITE 1 playerSpriteX playerSpriteY Player 1.gif
Keydown
ON KEYDOWN
playerNewSpriteX = playerSpriteX
playerNewSpriteY = playerSpriteY
IF keydown$ = "UPARROW" THEN playerNewSpriteY = playerSpriteY - 44
IF keydown$ = "DOWNARROW" THEN playerNewSpriteY = playerSpriteY + 44
IF keydown$ = "LEFTARROW" THEN playerNewSpriteX = playerSpriteX - 44
IF keydown$ = "RIGHTARROW" THEN playerNewSpriteX = playerSpriteX + 44
playerNewGridY = playerNewSpriteY / 44
playerNewGridX = playerNewSpriteX / 44
playerNewGridX = playerNewGridX + 1
playerNewGridY = playerNewGridY + 1
playerNewGridXY = 7 * playerNewGridY
playerNewGridXY = playerNewGridXY - 7
playerNewGridXY = playerNewGridXY + playerNewGridX
playerTile$ = MID$ gridMap$ playerNewGridXY 1
IF playerTile$ = "0" THEN playerSpriteX = playerNewSpriteX
IF playerTile$ = "0" THEN playerSpriteY = playerNewSpriteY
SPRITE 1 playerSpriteX playerSpriteY
END KEYDOWN
I'm not particularly fond of the streamlined versions however, as they only handle the bare minimum of features.
Here's an example of what can be done with a little tinkering:
(http://img197.imageshack.us/img197/4633/picture1mhh.th.png) (http://img197.imageshack.us/i/picture1mhh.png/)
Giant player sprites. The only difference to the code is the "playerSize" variable in the player property block, and the "giant sprite" collision routine. If you set "playerSize" to 1, collision will be calculated as normal. If you set it to 2, collision will be detected on a 4x4 tile radius.
' --- Edit these vars to set the attributes of the grid.
gridMap$ = "1000001100000010000101000000100100010000001000001"
gridSize = 7
tileSize = 44
' --- Edit these vars to set the attributes of the player.
playerSprite$ = "Giant Spider.gif"
playerGridX = 1
playerGridY = 1
playerMoveSpeed = 16
playerSize = 2
' --- Determine the player's sprite coordinates based on its grid coordinates.
playerSpriteY = playerGridY * tileSize
playerSpriteY = playerSpriteY - tileSize
playerSpriteY = playerSpriteY + 5
playerSpriteX = playerGridX * tileSize
playerSpriteX = playerSpriteX - tileSize
playerSpriteX = playerSpriteX + 5
SPRITE 1 playerSpriteX playerSpriteY $playerSprite$$
'------------------------------------------------------------------------------------------------
ON KEYDOWN
playerNewGridX = playerGridX
playerNewGridY = playerGridY
' --- Check which direction the player wants to move in.
IF keydown$ = "UPARROW" THEN playerNewGridY = playerGridY - 1
IF keydown$ = "DOWNARROW" THEN playerNewGridY = playerGridY + 1
IF keydown$ = "LEFTARROW" THEN playerNewGridX = playerGridX - 1
IF keydown$ = "RIGHTARROW" THEN playerNewGridX = playerGridX + 1
' --- Check what kind of tile the player is trying to move onto. (check if it's traversable or not)
playerNewGridXY = 0
playerNewGridXY = gridSize * playerNewGridY
playerNewGridXY = playerNewGridXY - gridSize
playerNewGridXY = playerNewGridXY + playerNewGridX
playerTile$ = MID$ gridMap$ playerNewGridXY 1
IF playerTile$ = "0" THEN playerTile$ = "Empty Tile"
IF playerTile$ = "1" THEN playerTile$ = "Obstacle"
IF playerNewGridX < 1 THEN playerTile$ = "Obstacle"
IF playerNewGridX > gridSize THEN playerTile$ = "Obstacle"
IF playerNewGridY < 1 THEN playerTile$ = "Obstacle"
IF playerNewGridY > gridSize THEN playerTile$ = "Obstacle"
' --- Calculate collision for giant sprites.
IF playerSize = 2 THEN
IF keydown$ = "UPARROW" THEN
IF playerTile$ = "Empty Tile" THEN
playerNewGridXY2 = playerNewGridXY + 1
playerTile$ = MID$ gridMap$ playerNewGridXY2 1
IF playerTile$ = "0" THEN playerTile$ = "Empty Tile"
IF playerTile$ = "1" THEN playerTile$ = "Obstacle"
END IF
END IF
IF keydown$ = "DOWNARROW" THEN
IF playerTile$ = "Empty Tile" THEN
playerNewGridXY2 = playerNewGridXY + gridSize
playerTile$ = MID$ gridMap$ playerNewGridXY2 1
IF playerTile$ = "0" THEN playerTile$ = "Empty Tile"
IF playerTile$ = "1" THEN playerTile$ = "Obstacle"
END IF
IF playerTile$ = "Empty Tile" THEN
playerNewGridXY2 = playerNewGridXY2 + 1
playerTile$ = MID$ gridMap$ playerNewGridXY2 1
IF playerTile$ = "0" THEN playerTile$ = "Empty Tile"
IF playerTile$ = "1" THEN playerTile$ = "Obstacle"
END IF
END IF
IF keydown$ = "LEFTARROW" THEN
IF playerTile$ = "Empty Tile" THEN
playerNewGridXY2 = playerNewGridXY + gridSize
playerTile$ = MID$ gridMap$ playerNewGridXY2 1
IF playerTile$ = "0" THEN playerTile$ = "Empty Tile"
IF playerTile$ = "1" THEN playerTile$ = "Obstacle"
END IF
END IF
IF keydown$ = "RIGHTARROW" THEN
IF playerTile$ = "Empty Tile" THEN
playerNewGridXY2 = playerNewGridXY + 1
playerTile$ = MID$ gridMap$ playerNewGridXY2 1
IF playerTile$ = "0" THEN playerTile$ = "Empty Tile"
IF playerTile$ = "1" THEN playerTile$ = "Obstacle"
END IF
IF playerTile$ = "Empty Tile" THEN
playerNewGridXY2 = playerNewGridXY2 + gridSize
playerTile$ = MID$ gridMap$ playerNewGridXY2 1
IF playerTile$ = "0" THEN playerTile$ = "Empty Tile"
IF playerTile$ = "1" THEN playerTile$ = "Obstacle"
END IF
END IF
IF playerNewGridX < 1 THEN playerTile$ = "Obstacle"
IF playerNewGridX = gridSize THEN playerTile$ = "Obstacle"
IF playerNewGridY < 1 THEN playerTile$ = "Obstacle"
IF playerNewGridY = gridSize THEN playerTile$ = "Obstacle"
END IF
' --- If the tile has no obstacles on it, move the player onto the tile.
IF playerTile$ = "Empty Tile" THEN
playerGridX = playerNewGridX
playerGridY = playerNewGridY
END IF
' --- Determine the player's sprite coordinates based on its grid coordinates.
playerSpriteY = playerGridY * tileSize
playerSpriteY = playerSpriteY - tileSize
playerSpriteY = playerSpriteY + 5
playerSpriteX = playerGridX * tileSize
playerSpriteX = playerSpriteX - tileSize
playerSpriteX = playerSpriteX + 5
SPRITEPATH 1 playerSpriteX playerSpriteY playerMoveSpeed
CLEAR TEXT
PRINT keydown$: $keydown$$
PRINT playerNewGridXY: $playerNewGridXY$
PRINT playerNewGridXY2: $playerNewGridXY2$
PRINT playerTile$: $playerTile$$
PRINT
PRINT playerNewGridX: $playerNewGridX$
PRINT playerNewGridY: $playerNewGridY$
END KEYDOWN