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

Re: jumping tutorial?

Post by toaster468 »

I dont really want to use array maps, too cumbersome IMO. Can I just draw a rectangle for the ground?
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 »

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

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

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.
Last edited by kikito on Tue Nov 16, 2010 12:06 am, edited 1 time in total.
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 »

one problem, my map looks like this:

Image
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 »

Oh. I thought you had finished the previous step.

Please paste your complete code again.
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 »

Well i am 50% done, i made the map a 20x20 square and it outputs a rectangle. I dont have my code ATM. sorry
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 »

No worries. Take your time.
When I write def I mean function.
User avatar
zac352
Party member
Posts: 496
Joined: Sat Aug 28, 2010 8:13 pm
Location: In your head.
Contact:

Re: jumping tutorial?

Post by zac352 »

Is anyone else wondering about this? >_>

Code: Select all

tile[map[y] [x]]
Hello, I am not dead.
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: jumping tutorial?

Post by vrld »

zac352 wrote:Is anyone else wondering about this? >_>

Code: Select all

tile[map[y] [x]]
No, what's wrong with that?
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
Post Reply

Who is online

Users browsing this forum: Majestic-12 [Bot] and 0 guests