|
- -- world module
- local world = require("world")
-
- -- love's load function
- function love.load()
- -- set the overall map offset
- offset = {
- x = 0,
- y = 0
- }
-
- -- generate the world and load the files
- world.new(10, 10)
- world.loadTiles()
-
- -- store the mouse position
- mouse = {
- x = love.mouse.getX(),
- y = love.mouse.getY()
- }
- end
-
- -- love's update function
- function love.update(dt)
- -- get the current mouse location
- local mouseNow = {
- x = love.mouse.getX(),
- y = love.mouse.getY()
- }
-
- -- if mouse is pressed move the offset
- if love.mouse.isDown(1) then
- local mouseDelta = {
- x = mouse.x - mouseNow.x,
- y = mouse.y - mouseNow.y,
- }
-
- offset.x = offset.x - mouseDelta.x
- offset.y = offset.y - mouseDelta.y
- end
-
- mouse = mouseNow
- end
-
- -- love's key press funciton
- function love.keypressed(key, scanCode, isRepeat)
- -- arrow keys for moving offset
- if key == "left" then
- offset.x = offset.x - 16
- end
-
- if key == "right" then
- offset.x = offset.x + 16
- end
-
- if key == "up" then
- offset.y = offset.y - 16
- end
-
- if key == "down" then
- offset.y = offset.y + 16
- end
- end
-
- -- love's draw function
- function love.draw()
- -- clear the window
- love.graphics.clear()
-
- -- draw the map
- world.render(offset)
- end
|