## finding what tile the player is on

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Anonymous

### finding what tile the player is on

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

bungytheworm
Veteran
Posts: 288
Joined: Sat Feb 18, 2006 4:02 pm
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.

{Nathan}
Veteran
Posts: 1169
Joined: Thu Aug 19, 2004 6:08 pm
Location: The wetlands of central Ohio, USA
Contact:
Try looking at some tutorials written by Darkdread on this site. They could help. Also, what size are your tiles? 16 by 16?

Anonymous
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

relsoft
Coder
Posts: 24
Joined: Wed Jun 07, 2006 9:04 pm
Location: Philippines
Contact:

Code: Select all

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

tile = map(mapx,mapy)``````
Hello. :*)

Anonymous
ok thanks very simple, ill give it a try!