I now added collision, but I noticed when he walks diagonally, between the tiles he is not supposed to cross he is able to slink through the gaps... Any tips to prevent this is appreciated.
edit: well, 1 minute later I got an idea, and answered my own question. I had to make the impassable tiles 3 pixels larger, so he couldn't slide through.
// Project: NewTest2dtiles
// Created: 2017-02-12
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "NewTest2dtiles" )
SetWindowSize( 1024, 768, 0 )
// set display properties
SetVirtualResolution( 1024, 768 )
SetOrientationAllowed( 1, 1, 1, 1 )
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
dim map# [64,64,10]
global playerx = 80
global playery = 80
global viewx
global viewy
loadimage(1, "RPGtest.png")
loadimage(2, "player.png")
createsprite(2, 2)
setspritedepth(2,4)
setspriteposition(2,playerx,playery)
setspritephysicson(2,2)
SetSpritePhysicsCanRotate (2,0)
loadimage(3, "House1.png")
createsprite(3,3)
Setspritedepth(3,4)
SetSpritePosition(3,125,125)
setspritephysicson(3,1)
load()
do
loadmap()
Mapdisplay()
sync()
loop
function load()
OpentoRead(1,"maptest")
for y=0 to 64
for x=0 to 64
a=ReadInteger(1)
map#[x,y,0]=a
next x
next y
closefile(1)
endfunction
Function Displaymap(x,y,z)
xmod = MOD(x,64)
ymod = MOD(y,64)
zmod = 0
obj = (zmod*0)+(ymod*64)+xmod
obj = obj + 2000
main_tile = readtile(x,y,z)
if getspriteexists( obj )=1 then deletesprite(obj)
if main_tile = 0 then exitfunction
if main_tile>0
createsprite(obj,1)
SetSpriteAnimation(obj, 32, 32,3)
SetSpriteUVBorder(obj, 1)
setspriteframe(obj,main_tile)
setspriteposition(obj,x*32,y*32)
if main_tile =2
setspritephysicson(obj,1)
endif
setspritedepth(obj,5)
endif
endfunction
function readtile(x,y,z)
if x<1 then exitfunction 0
if x>64 then exitfunction 0
if y<1 then exitfunction 0
if y>64 then exitfunction 0
if z<0 then exitfunction 0
if z>10 then exitfunction 0
ret=map#[x,y,z]
endfunction ret
function loadmap()
x=1
y=1
z=0
for x = 1 to 64
for y = 1 to 64
Displaymap(x,y,0)
next y
next x
endfunction
function Mapdisplay()
map_w =2048
map_h=2048
screen_w=1024
screen_h=786
oldx=getspritex(2)
oldy=getspritey(2)
movex=0
movey=0
viewx=0
viewy=0
if getrawkeystate(38)=1 //up key
if oldy <65
movey = 0
else
movey=-16
endif
endif
if getrawkeystate(40)=1 //down key ** not working **
if oldy >32*61
movey=0
else
movey=16
endif
endif
if getrawkeystate(37)=1
if oldx < 33
movex = 0
else
movex=-16//left key
endif
endif
if getrawkeystate(39)=1 //right key
if oldx >32*63
movex=0
else
movex=16
endif
endif
newplayerxposition = oldx+movex
newplayeryposition = oldy+movey
setspriteposition(2,newplayerxposition,newplayeryposition)
viewx = (newplayerxposition)-200
viewy = (newplayeryposition+24)
if viewx < (map_w)-(screen_w)
viewx = newplayerxposition-200
if viewx<32
viewx=32
endif
elseif viewx>map_w-screen_w+8
viewx = map_w-screen_w+16
endif
if viewy>(map_h/16)-(screen_h/16)
viewy = newplayeryposition-80
if viewy<32
viewy=32
endif
if viewy>map_h-screen_h
viewy = map_h-screen_h+32
if viewy > 1264
viewy=1264
endif
endif
endif
setviewoffset(viewx, viewy)
endfunction