jumping tutorial?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
toaster468
Citizen
Posts: 77
Joined: Sat Nov 06, 2010 11:30 pm

Re: jumping tutorial?

Post 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?
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: jumping tutorial?

Post 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.
When I write def I mean function.
User avatar
toaster468
Citizen
Posts: 77
Joined: Sat Nov 06, 2010 11:30 pm

Re: jumping tutorial?

Post 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.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: jumping tutorial?

Post 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?
Help us help you: attach a .love.
User avatar
toaster468
Citizen
Posts: 77
Joined: Sat Nov 06, 2010 11:30 pm

Re: jumping tutorial?

Post by toaster468 »

I still do not know what to do :|
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: jumping tutorial?

Post 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.
Help us help you: attach a .love.
User avatar
toaster468
Citizen
Posts: 77
Joined: Sat Nov 06, 2010 11:30 pm

Re: jumping tutorial?

Post 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.
User avatar
toaster468
Citizen
Posts: 77
Joined: Sat Nov 06, 2010 11:30 pm

Re: jumping tutorial?

Post 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.
User avatar
toaster468
Citizen
Posts: 77
Joined: Sat Nov 06, 2010 11:30 pm

Re: jumping tutorial?

Post 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.
User avatar
toaster468
Citizen
Posts: 77
Joined: Sat Nov 06, 2010 11:30 pm

Re: jumping tutorial?

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

Who is online

Users browsing this forum: Google [Bot] and 3 guests