Page 1 of 1

### finding what tile the player is on

Posted: Sat Oct 14, 2006 10:17 pm
hi im making a game engine, and another problem im having is finding out what tile im on. its tile*tile atm, and ive worked out when im going to another tile by going posx = playerpos/16 and posy = playerpos/16, but because you start in the middle of a 40x40 map i dont know how the engine can read if you are standing on, say, tile number 5 for example.

anyone with ideas?
i have tried

for x = 1 to 40 etc
If map(x,y) = 5 then
bla bla bla

and also

if playerposx = 16 and playerposy = 16 '(where there is a tile 5 located)
then ontile5 = "true"

which doesnt work

Posted: Sun Oct 15, 2006 7:49 am
Could you post some example of how youre doin your thing?
I didnt get whats your problem here. Might be up of my english skills too.

Posted: Sun Oct 15, 2006 4:14 pm
Try looking at some tutorials written by Darkdread on this site. They could help. Also, what size are your tiles? 16 by 16?

Posted: Sun Oct 15, 2006 8:44 pm
yeah sorry im at uni and the program is at home :/

yeah the tiles are 16*16. i can sort of pseudo-code here:

screen 13

open map for input as #1
for x = 1 to 40
for y = 1 to 40
input #1,map (x,y)
next
next

' in a sub
select case map(x,y)

case 1
put(x,y),grass,pset

case 2
put(x,y),house,pset
etc
etc

'in another sub
sub putplaypic

'playerY = 96
'playerX = 160

put (worlddata.playerX, world data.PlayerY), player, pset

Do

if key is pressed
up, down, left, right, exit
loop

'END HERE---------------------

do you get the idea? the player always starts in the middle of the map and screen. so how would i read the map to see if you are standing on tile 5?

i thought that you could do it by working out posX = worlddata.playerX/16
which would find the place you are standing, so i could work out from where u start where tile 5 is (which means that tile 5 would have to be pre-defined in the map rather than being worked out)

for example, map data:

1,1,1,1,1,1,1,1,1,1,1,1
1,1,1,1,1,1,5,1,1,1,1,1
1,1,1,1,1,1,1,1,1,1,1,1
1,1,1,1,1,1,1,1,1,1,1,1
1,1,1,1,1,1,8,1,1,1,1,1
1,1,1,1,1,1,1,1,1,1,1,1
1,1,1,1,1,1,1,1,1,1,1,1

you start at 8, i want to find out when im standing on 5

Posted: Mon Oct 16, 2006 8:04 am

Code: Select all

``````mapx = playerpos\16
mapy = playerpos\16

tile = map(mapx,mapy)``````

Posted: Mon Oct 16, 2006 10:44 pm
ok thanks very simple, ill give it a try!