here is my code:
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" )
background = love.graphics.newImage( "z.png" )
stan_left = love.graphics.newImage( "P_left.png" )
-- game variables
player_X = 50
player_Y = 260
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 = 32
map_offset_y = 32
map_display_w = 14
map_display_h = 10
tile_w = 48
tile_h = 48
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
tile[i] = love.graphics.newImage( "tile_image"..i..".png" ) do
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