Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 72 lines (57 sloc) 1.892 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
require("gui/tilepanel")

Editor = {}

function Editor:new(lvl)
    local object = {}

    local level = lvl or 1

    object.world = World:new(level)
    -- FIXME
    world = object.world

    object.tilePanel = TilePanel:new(50, 50)

    object.drawEnabled = false

    setmetatable(object, self)
    self.__index = self
    return object
end

function Editor:saveBaseImgData(filePath)
    self.world.baseImg:encode(filePath, "png")
end

function Editor:update(dt)
    if self.drawEnabled then
        local x = love.mouse.getX()
        local y = love.mouse.getY()
        local imgx = math.floor((cam.x+x)/(self.world.scale*8))
        local imgy = math.floor((cam.y+y)/(self.world.scale*8))
        local color = selectedTile.imageDataColor
        if selectedTile.name == "player" then
            local r, g, b, a = self.world.baseImg:getPixel(imgx, imgy)
            if (r == 0 and g == 0 and b == 0) then
                self.world.baseImg:setPixel(imgx, imgy, color.r, color.g, color.b, 0)
            end
        else
            self.world.baseImg:setPixel(imgx, imgy, color.r, color.g, color.b, 0)
        end
    end
    self.tilePanel:update(dt)
end

function Editor:draw()
    self.world:draw()

    local mouseX = love.mouse.getX()
    local mouseY = love.mouse.getY()
    local sx, sy = world:getTilePos(mouseX, mouseY)
    local r, g, b, c = love.graphics.getColor()
    love.graphics.setColor(255, 255, 255, 40)
    love.graphics.rectangle("fill", sx, sy, 8*world.scale, 8*world.scale)
    love.graphics.setColor(r, g, b, a)

    self.tilePanel:draw()
end

function Editor:mousepressed(x, y, button)
    if not self.tilePanel:mousepressed(x, y, button) then
        if selectedTile then
            self.drawEnabled = true
        end
    end
end

function Editor:mousereleased(x, y, button)
    self.tilePanel:mousereleased(x, y, button)
    self.drawEnabled = false
end
Something went wrong with that request. Please try again.