Re: jumping tutorial?
Posted: Wed Nov 10, 2010 9:36 pm
It is only 1 file so I will just post the code. I am almost certain it has to do with the size of the map and the view.
Update: OK, the real problem is when ever the player touches the tiles it gives me an error:
Ok i think i will display the player position to see if the map size is wrong which it might.
Before:
[img]
http://img823.imageshack.us/img823/1276 ... before.png
[/img]
After:
[img]
http://img705.imageshack.us/img705/3250/officeafter.png
[/img]
Code: Select all
-- Office Man Stan --
function love.load()
love.graphics.setMode(320, 320)
love.graphics.setCaption( "Office Man Stan" )
stan_right = love.graphics.newImage( "P.PNG" )
ground = love.graphics.newImage( "X.png" )
stan_left = love.graphics.newImage( "P_left.png" )
-- game variables
player_X = 0
player_Y = 0
player_direction = "r"
-- background color
love.graphics.setBackgroundColor(104, 136, 248)
-- map stuff
-- map variables
map_w = 20
map_h = 20
map_x = 0
map_y = 0
map_offset_x = 30
map_offset_y = 30
map_display_w = 14
map_display_h = 10
tile_w = 32
tile_h = 32
map={
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
}
love.graphics.setFont(12)
--tiles
tile = {}
for i=0,1 do
tile[i] = love.graphics.newImage( "tile_image"..i..".png" )
end
end
function draw_map()
for y=1, map_display_h do
for x=1, map_display_w do
love.graphics.draw(
tile[map[y+map_y] [x+map_x]],
(x*tile_w)+map_offset_x,
(y*tile_h)+map_offset_y )
end
end
end
function love.update(dt)
if love.keyboard.isDown( "left" ) then
player_X = player_X - 1
player_direction = "l"
map_y = map_y-1
map_x = math.max(map_x-1, 0)
end
if love.keyboard.isDown( "right" ) then
player_X = player_X + 1
player_direction = "r"
map_x = math.min(map_x+1, map_w-map_display_w)
end
if love.keyboard.isDown( "down" ) then
player_Y = player_Y + 1
player_direction = "d"
if map_y > map_h-map_display_h then map_y = map_h-map_display_h; end
end
if love.keyboard.isDown( "up" ) then
player_Y = player_Y - 1
player_direction = "u"
if map_y < 0 then map_y = 0; end
end
end
function love.draw()
if player_direction == "r" then
love.graphics.draw( stan_right, player_X, player_Y )
end
if player_direction == "l" then
love.graphics.draw( stan_left, player_X, player_Y )
end
if player_direction == "u" then
love.graphics.draw( stan_right, player_X, player_Y )
end
if player_direction == "d" then
love.graphics.draw( stan_right, player_X, player_Y )
end
--love.graphics.draw( ground, 0, 260 )
draw_map()
end
Ok i think i will display the player position to see if the map size is wrong which it might.
Before:
[img]
http://img823.imageshack.us/img823/1276 ... before.png
[/img]
After:
[img]
http://img705.imageshack.us/img705/3250/officeafter.png
[/img]