Page 10 of 14

Re: jumping tutorial?

Posted: Sat Nov 20, 2010 3:04 pm
by toaster468

Code: Select all

-- 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?

Re: jumping tutorial?

Posted: Sat Nov 20, 2010 4:07 pm
by kikito
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)

Code: Select all

-- 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 hope this helps. Continue with the second part.

Re: jumping tutorial?

Posted: Sat Nov 20, 2010 5:22 pm
by toaster468
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.

Re: jumping tutorial?

Posted: Sat Nov 20, 2010 5:37 pm
by Robin
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?

Re: jumping tutorial?

Posted: Sat Nov 20, 2010 6:50 pm
by toaster468
I still do not know what to do :|

Re: jumping tutorial?

Posted: Sat Nov 20, 2010 9:29 pm
by Robin
toaster468 wrote:I still do not know what to do :|
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.

Re: jumping tutorial?

Posted: Sat Nov 20, 2010 10:50 pm
by toaster468
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.

Re: jumping tutorial?

Posted: Wed Dec 01, 2010 1:57 am
by toaster468
I didn't really think clear that day. I know what I need now, I need to change the arguements. I cannot believe I made that mistake.

Re: jumping tutorial?

Posted: Wed Dec 01, 2010 2:05 am
by toaster468
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.

Re: jumping tutorial?

Posted: Wed Dec 01, 2010 2:08 am
by toaster468
OK, so I think I've found that I haven't asked it to move :crazy:. So here is my code for drawing the map:

Code: Select all

function draw_map(mx, my)

   for y=1, map_display_h do
      for x=1, map_display_w do
         love.graphics.draw(tile[ map[y] [x] ], x*tile_w, y*tile_h)
      end
   end
end
What do I do now?