Code: Select all
-- Office Man Stan --
function love.load()
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"
-- debug stuff delete later
mouse_x = love.mouse.getX()
mouse_y = love.mouse.getY()
canDrawHUD = true
-- background color
--love.graphics.setBackgroundColor(104, 136, 248)
-- map stuff
-- map variables
map_x = 0
map_y = 0
map_w = 320
map_h = 320
map_display_w = 7
map_display_h = 5
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},
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{ 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] [x] ], x*tile_w, y*tile_h)
end
end
end
function love.update(dt)
mouse_x = love.mouse.getX()
mouse_y = love.mouse.getY()
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()
love.graphics.print( player_X, 35, 10 )
love.graphics.print( player_Y, 60, 10 )
love.graphics.print( mouse_x, 190, 10)
love.graphics.print( mouse_y, 210, 10)
end