jumping tutorial?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- toaster468
- Citizen
- Posts: 77
- Joined: Sat Nov 06, 2010 11:30 pm
Re: jumping tutorial?
I dont really want to use array maps, too cumbersome IMO. Can I just draw a rectangle for the ground?
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: jumping tutorial?
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?
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.
- toaster468
- Citizen
- Posts: 77
- Joined: Sat Nov 06, 2010 11:30 pm
Re: jumping tutorial?
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
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: jumping tutorial?
Mmm... I don't see map_x or map_y there. Not sure why you need them anywhere else.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
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 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
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 #
##########################################
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.
- toaster468
- Citizen
- Posts: 77
- Joined: Sat Nov 06, 2010 11:30 pm
Re: jumping tutorial?
one problem, my map looks like this:
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: jumping tutorial?
Oh. I thought you had finished the previous step.
Please paste your complete code again.
Please paste your complete code again.
When I write def I mean function.
- toaster468
- Citizen
- Posts: 77
- Joined: Sat Nov 06, 2010 11:30 pm
Re: jumping tutorial?
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?
Is anyone else wondering about this? >_>
Code: Select all
tile[map[y] [x]]
Hello, I am not dead.
Re: jumping tutorial?
No, what's wrong with that?zac352 wrote:Is anyone else wondering about this? >_>Code: Select all
tile[map[y] [x]]
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 2 guests