Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / help using tilemaps and x,y location of tile

Author
Message
im not really here
14
Years of Service
User Offline
Joined: 14th Oct 2010
Location: iowa
Posted: 14th Jan 2011 03:48
Hello im trying to crate a game using tilemaps i have my tilemap laid out fine



i have my sprites working fine....


but i cant figure out how to check if a sprite is on a certain tile


for example : if Sprite was on a water tile i want it to play a water sound


here is my code



as you can see im using mouse to move my sprite but i dont want to be able to leave the water....

could someone maybe edit or give an example in the simplest way im just learning how to use arrays so go easy =)
im not really here
14
Years of Service
User Offline
Joined: 14th Oct 2010
Location: iowa
Posted: 15th Jan 2011 06:55
nobody?....
Pilz X Schizo
17
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Massachusetts, USA
Posted: 15th Jan 2011 19:36
I don't have very much time right now so I didn't get to look through your code, but the general idea is to figure out your position and check the map array to know where you are.

if your using say 32x32 images for your game you can figure out the screen position of what you want to check and divide the x and y each by 32 to get the map array position. Then its just a matter of doing what you want with that data, if water then play water sound, if grass then move back to last position.

Hope that helps a little.

Cuddle Bunniezzz 12
15
Years of Service
User Offline
Joined: 14th Jan 2009
Location: Buffalo, NY
Posted: 15th Jan 2011 19:53 Edited at: 15th Jan 2011 19:58
EDIT:
Misread stuff, please disregard this post.

http://ref.darkgdk.us/ <- Online DarkGDK Refernece. More content coming soon.
im not really here
14
Years of Service
User Offline
Joined: 14th Oct 2010
Location: iowa
Posted: 17th Jan 2011 09:26
ahh yes i see what your saying pilz....i get the idea...if you get a chance could you post an example code...
could save me some time...as for now im gunna try and figure it out on my own...thanks a bunch
im not really here
14
Years of Service
User Offline
Joined: 14th Oct 2010
Location: iowa
Posted: 18th Jan 2011 11:26
i just ended up
saying
int tileX=32;
int tileY=32;

and used if statements

if (dbSpriteX(sprite)>tileX*5&&dbSpriteY(sprite)<TileY*2)
{play sound yadda yadda
}


was alot of if statements but it did the job

hope this is what you ment
Pilz X Schizo
17
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Massachusetts, USA
Posted: 19th Jan 2011 19:47
Say for example this is your Map Array:

int Map[5][5] = {
1, 0, 0, 0, 1, // 0 = water, 1 = grass
1, 0, 0, 0, 1,
1, 0, 0, 0, 1,
1, 0, 0, 0, 1,
1, 0, 0, 0, 1
};


with that all you really need is your player position and you can easilly elimiate a lot of IF statments.

x = dbSpriteX(sprite) / 32;
y = dbSpriteY(sprite) / 32;

switch(Map[x][y]){

case 0:
// Play water sound //
break;

case 1:
//on ground, move back to last position //
break;
}

Login to post a reply

Server time is: 2024-11-19 14:45:59
Your offset time is: 2024-11-19 14:45:59