Log In    Hello y'all,

I'm working on making a puzzle game, and I've come across a problem with the collision detection/map reading when I try to change to the next map. I think this stems from the fact that I'm missing a concept somewhere on how maps work. Everything seems to work find until I move to the third map...not sure what I'm missing.

 ```--sprite 0 is blank --sprite 1 is player --sprite 2 is to mark where the player spawned --sprite 16 is wall function _update() moveplayer() solidstuff() end function _draw() cls() map(0,0,0,0,16*3,16) spr(1,player.x,player.y,1,1,0,false) camera(cel_x*8,cel_y*8) end function moveplayer() --moving player if btnp(0,0) and solid.li!=16 and solid.lf!=16 then player.x-=player.dx end if btnp(1,0) and solid.ri!=16 and solid.rf!=16 then player.x+=player.dx end if btnp(3,0) and solid.di!=16 and solid.df!=16 then player.y+=player.dy end if btnp(2,0) and solid.ui!=16 and solid.uf!=16 then player.y-=player.dy end --switches the map if btnp(5,0) then cel_x+=16 readmap() player.x+=16*8 end if btnp(4,0) then cel_x-=16 readmap() player.x-=16*8 end end function readmap() for x=0,15 do for y=0,15 do tile=mget(x+cel_x,y+cel_y) if tile==1 then mset(x+cel_x,y+cel_y,2) player.x=x*8 player.y=y*8 end end end end function solidstuff() solid.di=mget(flr((player.x)/8),flr((player.y+8)/8)) solid.df=mget(flr((player.x+7)/8),flr((player.y+8)/8)) solid.ui=mget(flr((player.x)/8),flr((player.y-8)/8)) solid.uf=mget(flr((player.x+7)/8),flr((player.y-8)/8)) solid.li=mget(flr((player.x-1)/8),flr((player.y)/8)) solid.lf=mget(flr((player.x-1)/8),flr((player.y)/8)) solid.ri=mget(flr((player.x+8)/8),flr((player.y)/8)) solid.rf=mget(flr((player.x+8)/8),flr((player.y)/8)) end function _init() player={} player.x=8 player.y=8 player.dx=8 player.dy=8 solid={} solid.di=0 solid.df=0 solid.ui=0 solid.uf=0 solid.li=0 solid.lf=0 solid.ri=0 solid.rf=0 cel_x=0 cel_y=0 tile=0 readmap() end ```
P#42528 2017-07-15 22:03 ( Edited 2017-07-16 16:26)  I forgot to mention that I'm trying to make a system where the initial player player location (and other game related items) is obtained from reading the map.

P#42529 2017-07-15 22:31 ( Edited 2017-07-16 02:31)  At first, you'd to mention that this problem appears only whenplayer.dyis not a multiple of tile height. Your bug is in this two lines:

 ```solid.ui=mget(flr((player.x)/8),flr((player.y-8)/8)) solid.uf=mget(flr((player.x+7)/8),flr((player.y-8)/8))```

You see,player.xandplayer.yare coordinates of upper left corner of sprite, so if you want to check one pixel above, you has to checkplayer.y-1.

P.S.: mgetfunction can take non-integer values so you no need to useflr().

P#42543 2017-07-16 12:26 ( Edited 2017-07-16 16:26)