Page 7 of 14

Re: jumping tutorial?

Posted: Wed Nov 10, 2010 11:01 pm
by toaster468
I dont really want to use array maps, too cumbersome IMO. Can I just draw a rectangle for the ground?

Re: jumping tutorial?

Posted: Wed Nov 10, 2010 11:23 pm
by kikito
Sorry, no. You will need to be able to insert platforms and walls later.

map_x and map_y, you say? They should be removed too... just like robin said.

Can you put your drawing function here?

Re: jumping tutorial?

Posted: Thu Nov 11, 2010 1:28 am
by toaster468
uh sure, im guessing you are asking for draw_map() not love.draw()

Code: Select all

function draw_map()

   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

Re: jumping tutorial?

Posted: Thu Nov 11, 2010 9:54 am
by kikito
toaster468 wrote:uh sure, im guessing you are asking for draw_map() not love.draw()

Code: Select all

function draw_map()

   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
Mmm... I don't see map_x or map_y there. Not sure why you need them anywhere else.

But, well, onto next step: Walls.

Before attempting to jump, you need your character to stop 'traversing' walls.

The easiest way to do that is using the map itself. When the character is moving left, it has to check whether there's a wall to the left, and the same goes for the right.

A) Coordinate transformation

You will need to know things like 'in what cell is the player' or 'what kind of cell is to the left of the player'. Given the fact that the player's coordinate system is different from the map's coordinate system, it will be useful to be able to convert between the two systems.

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
Hint 1: notice that both functions return 2 elements.
Hint 2: your drawing function could be re-written as follows:

Code: Select all

function draw_map()
   for my=1, map_display_h do
      for mx=1, map_display_w do
         local x,y = map2world(mx,my)
         love.graphics.draw(tile[map[my][mx]], x,y)
      end
   end
end
Once it is working, continue with B).

B) Bumping into walls

Change your keypressed function so when the 'left' key is pressed, the player moves to the left only if the cell to the left is not a brick cell. Then do the same on the right.

Make sure that you can create your character inside points 1 and 2 of the map, and he's not able to move from 1 to 2, or traverse the exterior walls:

Code: Select all

##########################################
#                                        #
#                                        #
#                                        #
#                    #      ####         #
#          ####      #                   #
#          1         #         2         #
##########################################
That is all for now.

Next we'll start with vertical movement. 2 lessons left for having a jumping character.

Re: jumping tutorial?

Posted: Thu Nov 11, 2010 11:18 am
by toaster468
one problem, my map looks like this:

Image

Re: jumping tutorial?

Posted: Thu Nov 11, 2010 11:48 am
by kikito
Oh. I thought you had finished the previous step.

Please paste your complete code again.

Re: jumping tutorial?

Posted: Thu Nov 11, 2010 11:57 am
by toaster468
Well i am 50% done, i made the map a 20x20 square and it outputs a rectangle. I dont have my code ATM. sorry

Re: jumping tutorial?

Posted: Thu Nov 11, 2010 12:51 pm
by kikito
No worries. Take your time.

Re: jumping tutorial?

Posted: Thu Nov 11, 2010 2:30 pm
by zac352
Is anyone else wondering about this? >_>

Code: Select all

tile[map[y] [x]]

Re: jumping tutorial?

Posted: Thu Nov 11, 2010 3:16 pm
by vrld
zac352 wrote:Is anyone else wondering about this? >_>

Code: Select all

tile[map[y] [x]]
No, what's wrong with that?