Hi...after exploding my brain i manage to do some loading to collision sprite based on CSV data from Tiled Editor coded as below
Im creating 5X5 32 pixel tilemap,and the creating second layer for collision but im using only the CSV data to draw tiles with collision values.(in the CSV 0 is collided,-1 is passable)
SetScreenResolution(480,480)
SetVirtualResolution(480,480)
type colbox
spr as integer
endtype
dim dummy[99] as colbox
global colid //give id to dummy and give the count of dummy
columns=5 //should be known by level designer
rows=5//should be known by level designer
Dim map[rows,columns] //for storing data form text file
Dim dummysprite[99,99] //stupidly using 99
collisionsprite=LoadImage("collision.png")
tilemap=CreateSprite(LoadImage("map.png"))
file =OpenToRead("mapcollision.csv")
colid=0
//1.reading collision data from text to 2 dimensional array and creaty sprite named Dummy
For y=1 to rows
line$=ReadLine(file)
For x=1 to columns
map[y,x]=Val(GetStringToken(line$,",",x))
//create dummy sprite if map[y,x]=0
if map[y,x]=0 //if the data said 0 mean collidable(from tiled editor of course)
dummy[colid].spr=Createsprite(collisionsprite)
SetSpriteShape(dummy[colid].spr,2)
SetSpritePosition(dummy[colid].spr,(x-1)*32,(y-1)*32)
colid=colid+1
Endif
Next
Next
//=======Setting up player=============
player=createsprite(LoadImage("player.png"))
SetSpriteShape(player,2)
x#=0
y#=0
gravity#=-1
SetSpritePosition(player,x#,y#)
//======================================
do
y#=y#-gravity#
SetSpritePosition(player,x#,y#)
For i=0 to colid
if GetSpriteCollision(player,dummy[i].spr)=1
gravity#=0
endif
Next
SetSpritePosition(player,x#,y#)
Sync()
loop
But im having THREE questions.
1.Although the collision tile drawn correctly as in tiled editor CSV, but collision wont happen.Can someone check and help my code?
2. Here i use colid to assign value to dummy (colbox type) to keep track on how many dummy have i created.
Any better way to keep track of this dummy?Notice that i set dim dummy as 99 in case i dont know how may collision tile have i made in the map, any better way todo this?
3.Are these method on the right path since i never tried 2d.
Thanks