gdritter repos animaltransiro / 5d5aa3d main.lua
5d5aa3d

Tree @5d5aa3d (Download .tar.gz)

main.lua @5d5aa3d

6080844
 
b682204
6080844
e703309
24d65ce
8f4a6a9
f0c2586
a8c9f5c
 
 
 
 
a114db3
 
5d5aa3d
f0c2586
 
a114db3
6080844
edf5a5d
 
c6568f2
 
 
 
edf5a5d
b682204
24d65ce
e13c4dc
a557cce
6f822a9
ebab62a
a114db3
b682204
24d65ce
 
 
 
 
 
 
 
 
f9b018e
 
edf5a5d
8836666
f0c2586
 
 
 
 
 
 
b682204
edf5a5d
 
c6568f2
8836666
c6568f2
 
 
edf5a5d
24d65ce
 
 
f0c2586
24d65ce
edf5a5d
 
 
f0c2586
edf5a5d
 
 
8f4a6a9
edf5a5d
local board = require 'board'
local consts = require 'constants'
local entity = require 'entity'
local tile = require 'tile'
local event = require 'event'
local menu = require 'menu'
local draw = require 'draw'

if arg[2] == 'editor' then
   require 'editor'
   return
end

local state = {
   loadMap = function(self, name)
      self.board = board.loadBoardFromTiled('areas/' .. name .. '.lua')
   end,
   keys = {},
}

local sprites = {}

function fromScreen(x, y)
   return math.floor(x / consts.tileSize), math.floor(y / consts.tileSize)
end

function love.load()
   state.t = 0
   state.message = nil
   debug = ''

   state.board = board.loadBoardFromTiled('areas/main.lua')
   state.char = entity.Entity:new(
      state, 3 * 24, 3 * 24, 'character')

   state.canvas = love.graphics.newCanvas(
      consts.boardWidth * consts.tileSize,
      consts.boardHeight * consts.tileSize)
   state.canvas:setFilter('nearest', 'nearest')

   love.window.setMode(consts.tileSize * consts.boardWidth * 2,
                       consts.tileSize * consts.boardHeight * 2)

   love.graphics.setNewFont('font.ttf', 16)
end

function love.update()
   state.t = state.t + 1
   state.char.dx = 0
   state.char.dy = 0
   for key, enabled in pairs(state.keys) do
      if enabled and event.keys.pressed[key] then
         event.keys.pressed[key](state)
      end
   end
   state.char:move()
end

function love.mousepressed(x, y)
   local gx, gy = fromScreen(x / 2, y / 2)
   state.board:set(gx, gy, tile.getTile('stonepath'))
end

function love.keypressed(key)
   if state.message then
      state.message = nil
   else
      state.keys[key] = true
   end
end

function love.keyreleased(key)
      state.keys[key] = nil
end

function love.draw()
   draw.drawAll(state)
end