Tile map editor in BlitzPlus. Need help with collision
Posted: Wed Mar 04, 2009 12:32 am
Code
I don't know where to begin, can anyone help
Code: Select all
;Platform Map editor NOW WITH MORE COLLISION MAPS
AppTitle "ShadowX Platform Map Editor"
gwidth=800
gheight=600
tsize=40
numtiles=4
Timer = CreateTimer(30)
showCols = False
Graphics gwidth,gheight,16,2
ClsColor 80,80,200
scr_left = 0
scr_top = 0
infile = OpenFile("map1.map");Assign infile to loading the map
If infile <> 0 Then
mapx = ReadInt(infile)
mapy = ReadInt(infile)
Else
mapx = 50
mapy = 20
EndIf
Dim map$(mapx,mapy)
If infile <> 0 Then
;read tile layer
For y = 0 To mapy-1
For x = 0 To mapx-1
map(x,y) = ReadInt(infile)
Next
Next
Else
;otherwise wipe map
For y = 0 To mapy-1
For x = 0 To mapx - 1
map(x,y) = 0
Next
Next
EndIf
CloseFile infile
img_tiles = LoadAnimImage("tileset.bmp",tsize,tsize,0,numtiles)
;LOL
;LOL
seltile = 2
SetBuffer BackBuffer()
Color 0,255,255
While Not KeyHit(1)
Cls
For y = 0 To mapy
For x = 0 To mapx
tilenum = Int(map(x,y))-1
If (x*tsize)-scr_left > -tsize And (x*tsize)-scr_left < gwidth And (y*tsize)-scr_top > -tsize And (y*tsize)-scr_top < gheight Then
;draw tile
If tilenum > -1 Then DrawImage img_tiles,(x*tsize)-scr_left,(y*tsize)-scr_top,tilenum
EndIf
Next
Next
;Scrolling around map w/ keys
If KeyDown(208) And scr_top < (mapy*tsize-gheight) Then scr_top = scr_top+15
If KeyDown(205) And scr_left < (mapx*tsize-gheight )Then scr_left = scr_left+15
If KeyDown(203) And scr_left > -menuwidth Then scr_left = scr_left-15
If KeyDown(200) And scr_top > 0 Then scr_top = scr_top-15
Rect (((MouseX()+scr_left)/tsize)*tsize)-scr_left-1,(((MouseY()+scr_top)/tsize)*tsize)-scr_top-1,tsize+2,tsize+2,0
If seltile > 0 DrawImage img_tiles,(((MouseX()+scr_left)/tsize)*tsize)-scr_left,(((MouseY()+scr_top)/tsize)*tsize)-scr_top,seltile-1
If MouseDown(1)
map((MouseX()+scr_left)/tsize,(MouseY()+scr_top)/tsize) = seltile
EndIf
If selmouse < MouseZ() Then seltile = seltile + 1
If selmouse > MouseZ() Then seltile = seltile - 1
selmouse = MouseZ()
If MouseHit(2) Then seltile = seltile + 1
If seltile > numtiles Then seltile = 0
If seltile = -1 Then seltile = numtiles
;Clear map w/C key
If KeyHit(46) Then
For y = 0 To mapy-1
For x = 0 To mapx-1
map(x,y) = 0
Next
Next
EndIf
;save map when 's' pressed
;-----------------------------------
If KeyHit(31) Then
;open output file in write mode
fileout = WriteFile("map1.map")
;write map dimensions
WriteInt fileout,mapx
WriteInt fileout,mapy
;write tile layer
For y = 0 To mapy-1
For x = 0 To mapx-1
WriteInt fileout,map(x,y)
Next
Next
CloseFile fileout
;--------------------------------------
EndIf
Flip
Wend
EndGraphics
End