Page 1 of 1

Trouble making a true equation

Posted: Thu May 25, 2006 4:49 pm
by DaveUnit
Sorry about the vague title...
My program loads a map file and whatnot, let's say one of the points has a tile number of 9. I need to take that number, then, based on the number of tiles horizontal and the number of tiles vertical in the tileset, find the column and row that tile is in, then finally convert those to x and y coordinates.
So... In a step by step form
let's say...
tile number= 9
tiles vertical= 3
tiles horizontal= 6

step 1: see how many times 6 can go into 9, subtract 6 * the amount of times six goes into 9, which is one, we're left with 3. 3 is the column the tile is in.
step 2: the amount of times 6 went into 9 plus one will equal the row the tiles is in.

I may have screwed up typing and totally made my idea total gibberish so point out if I did.

I can think of how to do it in my head but when I try to type down actual equations for it everything gets all frigged up.

I came close today but there's something that mod does that ruins it.

This should be simple math but for some reason I can't think of the equation.

Thanks for any help. It's much appreciated.

Dave.

Posted: Thu May 25, 2006 7:02 pm
by DaveUnit
EDIT: got rid of everything I posted earlier...
I just thought of something...
ya know those old qb double buffering tutorials?
ya know to put the right pixel color on the right spot on the array you'd use the equation x+320*y?
Well... for me the 320 would be whatever the image width was.
It sucks there are two variables for me to eliminate, it makes it hard to work with that equation to fit my needs of starting without an x,y coordinate.
I'm trying to remember stuff from my geometry class 1st semester but I'm drawing a blank, how can I possibly work with that equation to create the new one I need for my program?

Posted: Sat May 27, 2006 7:15 am
by DaveUnit
I imagine that I confused the hell out of all of you. Sorry.
But I'm kinda glad no one replied because I figured it out on my own, and it was really easy too! I can't believe it took me so long to figure out. :oops:

Posted: Sat May 27, 2006 8:30 am
by MystikShadows
Hey, don't worry about it...sometimes you just don't see it until you slept it off and sometimes even a few days hehe. Something to be said about looking at your code for too long ;-).

Posted: Tue May 30, 2006 3:18 pm
by Zim
As a teacher, one of the things I've noticed with students having difficulties is this. If you can force the student into an EXACT explanation of their question, many times they will spontaneously obtain the solution at that point. Forcing yourself to formulate an exact question (in writing, as on a message board) helps you to find the answer yourself!

Posted: Tue May 30, 2006 4:19 pm
by DaveUnit
Hmmm... that's really interesting, Zim. Thanks for the advice!
I realized my problem was with the division being rounded up so I ended up subtracting .4 from the result and it will always being a number rounded down. it has worked flawlessly and now I got my map displaying properly. My first FB scroller! woot. My map format works nicely too. I'm pretty proud of where my program is going. Everything has been neat and orgranized so far. Granted, I only have a scrolling map at the moment. Next is sprite handling! Hopefully I won't screw up too bad! :P

Later,
Dave