I found a video on
Youtube describing a method for automatic tiles in platform games. So I ported the script to AGK. And I thought I post it here in case someone is interested in it.
It requires a special tileset and one can be downloaded here.
http://shaunspalding.co.uk/files/tiles2.png
REM Original script by Nocturne, modifications by ShaunJS, Port to AGK by Fluorescent
REM Link to original script: http://gmc.yoyogames.com/index.php?showtopic=416796?st=0
REM set window properties
SetWindowTitle( "AutoTiles" )
SetWindowSize( 1024, 768, 0 )
REM set display properties
SetDisplayAspect(1024.0 / 768.0)
SetClearColor(127, 127, 127)
image = LoadImage("tiles.png")
SetImageMagFilter(image, 0)
SetImageMinFilter(image, 0)
tileset = CreateSprite(image)
SetSpriteAnimation(tileset, 64, 64, 48)
SetSpriteSize(tileset, 5, -1)
SetSpriteVisible(tileset, 0)
SetSpriteFrame(tileset, 44)
tilewidth# = GetSpriteWidth(tileset)
tileheight# = GetSpriteHeight(tileset)
drawntiles As Integer[]
Goto MainLoop
AutoTile:
For i = 0 To drawntiles.Length
tile = drawntiles[i]
x# = GetSpriteXByOffset(tile)
y# = GetSpriteYByOffset(tile)
left = GetSpriteHit(x# - tileWidth#, y#)
right = GetSpriteHit(x# + tileWidth#, y#)
up = GetSpriteHit(x#, y# - tileheight#)
down = GetSpriteHit(x#, y# + tileheight#)
upleft = GetSpriteHit(x# - tilewidth#, y# - tileheight#)
upright = GetSpriteHit(x# + tilewidth#, y# - tileheight#)
downleft = GetSpriteHit(x# - tilewidth#, y# + tileheight#)
downright = GetSpriteHit(x# + tilewidth#, y# + tileheight#)
If x# - tilewidth# < 0
left = 1
upleft = 1
downleft = 1
EndIf
If x# + tilewidth# > 100
right = 1
upright = 1
downright = 1
EndIf
If y# - tileheight# < 0
up = 1
upleft = 1
upright = 1
EndIf
If y# + tileheight# > 100
down = 1
downleft = 1
downright = 1
EndIf
frame = 44
If up
frame = 1
If right
frame = 5
If down
frame = 13
If left
frame = 29
If upright
frame = 30
If downright
frame = 34
If downleft
frame = 40
If upleft Then frame = 44
ElseIf upleft
frame = 41
EndIf
ElseIf downleft
frame = 38
If upleft Then frame = 42
ElseIf upleft
frame = 37
EndIf
ElseIf downright
frame = 31
If downleft
frame = 35
If upleft Then frame = 43
ElseIf upleft
frame = 39
EndIf
ElseIf downleft
frame = 32
If upleft Then frame = 36
ElseIf upleft
frame = 33
EndIf
ElseIf upright
frame = 17
If downright Then frame = 19
ElseIf downright
frame = 18
EndIf
ElseIf left
frame = 16
If upright
frame = 26
If upleft Then frame = 28
ElseIf upleft
frame = 27
EndIf
ElseIf upright
frame = 9
EndIf
ElseIf down
frame = 46
If left
frame = 15
If downleft
frame = 23
If upleft Then frame = 25
ElseIf upleft
frame = 24
EndIf
EndIf
ElseIf left
frame = 8
If upleft Then frame = 12
EndIf
ElseIf right
frame = 2
If down
frame = 6
If left
frame = 14
If downright
frame = 20
If downleft Then frame = 22
ElseIf downleft
frame = 21
EndIf
ElseIf downright
frame = 10
EndIf
ElseIf left
frame = 47
EndIf
ElseIf down
frame = 3
If left
frame = 7
If downleft Then frame = 11
EndIf
ElseIf left
frame = 4
EndIf
SetSpriteFrame(tile, frame )
Next i
Return
MainLoop:
Do
PX# = ScreenToWorldX(GetPointerX())
PY# = ScreenToWorldY(GetPointerY())
If GetPointerPressed() = 1
newtile = CloneSprite(tileset)
SetSpriteVisible(newtile, 1)
SetSpritePosition(newtile, Floor(PX# / tilewidth#) * tilewidth#, Floor(PY# / tileheight#) * tileheight#)
drawntiles.insert(newtile)
GoSub AutoTile
EndIf
Sync()
Loop