With the help of TDK_Man's tutorials to explain arrays to me, and Zenassem's idea of using them to manage tiles, even though I didn't really get it because his tutorial isn't finished, I got it working on multiple tiles, and now I can have a whole screen full of tiles
Now my next step is figuring out how to move the "camera" and move around maps bigger than the screen. I know from Zenassem's tutorial that it's not actually a camera moving, but the world moving around the player. But then I can't really think how you would handle enemies that move around on their own
plus move relative to the player. Anyway, here's the code if anyone cares:
sync on
sync rate 60
set display mode 640,480,32
load image "bricks.png",2,1
load image "clear.png",1,1
load image "redguy.png",3,1
dim tiles(2,2,2)
`dim tiletype(2,2)
data 1,1,1
data 1,1,1
data 2,2,2
data 0,0,0
data 0,0,0
data 1,1,1
`z=2 display, sprite number
` 11,12,13
` 21,22,23
` 31,32,33
sprite 1,32,32,3
spriteno=11
playerposx=32
playerposy=32
`setting up arrays
for y=0 to 2
for x=0 to 2
read value
tiles(x,y,0)=value
sprite spriteno,x*32,y*32,tiles(x,y,0)
inc spriteno
next x
inc spriteno,8
next y
for y=0 to 2
for x=0 to 2
read value
tiles(x,y,1)=value
next x
next y
spriteno=11
for y=0 to 2
for x=0 to 2
tiles(x,y,2)=spriteno
inc spriteno
next x
inc spriteno,8
next y
`-------------------------
do
if leftkey()=1 then dec playerposx,2
if rightkey()=1 then inc playerposx,2
inc playerposy,6
`checking collision on all tiles
for y=0 to 2
for x=0 to 2
if tiles(x,y,1)=1
playerposy=solidmidupper (tiles(x,y,2),playerposx,playerposy)
sprite 1,playerposx,playerposy,3
endif
next x
next y
sync
loop
function solidmidupper(spriteno,playerposx,playerposy)
if playerposy>=sprite y(spriteno)-32 and playerposy<=sprite y(spriteno)-16 and playerposx<sprite x(spriteno)+32 and playerposx>sprite x(spriteno)-32 then dec playerposy,(playerposy-(sprite y(spriteno)-32))
endfunction playerposy
Though I have this unshakable feeling that there must be a more efficient way to do collisions. Can anyone give me some suggestions?