-- given the coordinates of a cell on the map, return the x,y coordinates of it's top-left corner in world/screen maps.
-- example of use: x, y = map2world(x,y)
function map2world(mx,my)
-- fill this in
end
-- given an x,y coordinate on the screen/world, return the mx,my coordinates of the cell containing that point
-- example of use: mx, my = world2map(x,y)
function world2map(x,y)
-- fill this in
end
Ok so i think I am getting it so far. I need to find the x and y of one cell which is 32 and the y is 32. Then I store them in map2world, but I have no idea what I should do where it says -- fill this in.
Also mx and my is the map's coordinates or the player's coordinates?
I'll help you because it seems you are a bit stuck. Don't get accustomed to that.
Here's the code for both functions. It is very simple: in order to convert map coordinates (mx,my) into world coordinates(x,y) you have to multiply by tile_w and tile_h respectively. In order to do the inverse, you have to divide by them (math.floor just removes the decimal part)
-- given the coordinates of a cell on the map, return the x,y coordinates of it's top-left corner in world/screen maps.
-- example of use: x, y = map2world(x,y)
function map2world(mx,my)
return mx*tile_w, my*tile_h
end
-- given an x,y coordinate on the screen/world, return the mx,my coordinates of the cell containing that point
-- example of use: mx, my = world2map(x,y)
function world2map(x,y)
return math.floor(x/tile_w), math.floor(y/tile_h)
end
I am getting an error that mx and my are null. I know it is because world2map is non existent but so is map2world so I don't know why this is happening, ill try declaring them, but then setting it to zero will make everything thing multiplying and dividing 0.
toaster468 wrote:I am getting an error that mx and my are null. I know it is because world2map is non existent but so is map2world so I don't know why this is happening, ill try declaring them, but then setting it to zero will make everything thing multiplying and dividing 0.
If I'm right about what the issue is: mx and my are just formal parameters in map2world, you need to give it arguments. If not: have you tried putting the functions in your code and calling them?
I'm sorry, It's very hard to help you out with this (and just giving you a heap of code is not "helping out" in my books), this is mostly basic programming skills, really.
Ill read the manuals and stuff so I know the code, then I will come back with a full knowledge of the syntax, then I just need too learn how to make games.
OK, so it has compiled correctly but the screen does not move. Ill check the code to see if i did ask it to move it has been a while since I've worked on this.