Add layout
This commit is contained in:
		
							parent
							
								
									40fdba2588
								
							
						
					
					
						commit
						0cbc05c30f
					
				
					 1 changed files with 32 additions and 34 deletions
				
			
		
							
								
								
									
										66
									
								
								main.lua
									
										
									
									
									
								
							
							
						
						
									
										66
									
								
								main.lua
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -1,45 +1,45 @@
 | 
			
		|||
-- Imports
 | 
			
		||||
local window = require("window")
 | 
			
		||||
local button = require("button")
 | 
			
		||||
 | 
			
		||||
function love.load()
 | 
			
		||||
    timer = 0
 | 
			
		||||
    bx, by = 0, 0
 | 
			
		||||
    cx, cy = 0, 0
 | 
			
		||||
 | 
			
		||||
    main = {
 | 
			
		||||
        x = 50,
 | 
			
		||||
        y = 50,
 | 
			
		||||
    rx = 50, ry = 50, width = 300, height = 200
 | 
			
		||||
local inventory = {
 | 
			
		||||
    x = 0, y = 0,
 | 
			
		||||
    width = WIDTH*0.7,
 | 
			
		||||
    height = HEIGHT*0.2,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
    function main:moverect()
 | 
			
		||||
        self.rx = self.rx + 50
 | 
			
		||||
        self.ry = self.ry + 50
 | 
			
		||||
    end
 | 
			
		||||
inventory.draw = window.draw(function(self)
 | 
			
		||||
    window.draw_border(self.width, self.height)
 | 
			
		||||
end)
 | 
			
		||||
 | 
			
		||||
    local m = main
 | 
			
		||||
    cback = function (x, y)
 | 
			
		||||
        cx, cy = x, y
 | 
			
		||||
        m:moverect()
 | 
			
		||||
    end
 | 
			
		||||
local screen = {
 | 
			
		||||
    x = 0, y = inventory.height,
 | 
			
		||||
    width = inventory.width,
 | 
			
		||||
    height = HEIGHT - inventory.height,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
    btn = button.new('Move', cback, 10, 10, 50, 50)
 | 
			
		||||
 | 
			
		||||
    main.draw = window.draw(function(self)
 | 
			
		||||
        love.graphics.rectangle('fill', self.rx, self.ry, 50, 50)
 | 
			
		||||
        love.graphics.print(string.format("x %d", self.rx), 50, 100)
 | 
			
		||||
        btn:draw()
 | 
			
		||||
    end)
 | 
			
		||||
screen.draw = window.draw(function(self)
 | 
			
		||||
    window.draw_border(self.width, self.height)
 | 
			
		||||
end)
 | 
			
		||||
 | 
			
		||||
    main.mousepressed = window.mousepressed(function(self, x, y, button)
 | 
			
		||||
        btn:mousepressed(x, y, button)
 | 
			
		||||
    end)
 | 
			
		||||
local log = {
 | 
			
		||||
    x = inventory.width , y = 0,
 | 
			
		||||
    width = WIDTH*0.3,
 | 
			
		||||
    height = HEIGHT,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
log.draw = window.draw(function(self)
 | 
			
		||||
    window.draw_border(self.width, self.height)
 | 
			
		||||
end)
 | 
			
		||||
 | 
			
		||||
function love.load()
 | 
			
		||||
    timer = 0
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function love.mousepressed(x, y, button)
 | 
			
		||||
    local x, y = x / MULTIPLIER, y / MULTIPLIER
 | 
			
		||||
    bx, by = x, y
 | 
			
		||||
    main:mousepressed(x, y, button)
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function love.update(dt)
 | 
			
		||||
| 
						 | 
				
			
			@ -50,11 +50,9 @@ function love.draw()
 | 
			
		|||
    love.graphics.push()
 | 
			
		||||
    love.graphics.scale(MULTIPLIER)
 | 
			
		||||
 | 
			
		||||
    love.graphics.print(string.format("t: %d", timer), 0, 0)
 | 
			
		||||
    love.graphics.print(string.format("%d %d", bx, by), 0, 20)
 | 
			
		||||
    love.graphics.print(string.format("%d %d", cx, cy), 0, 40)
 | 
			
		||||
 | 
			
		||||
    main:draw()
 | 
			
		||||
    screen:draw()
 | 
			
		||||
    inventory:draw()
 | 
			
		||||
    log:draw()
 | 
			
		||||
 | 
			
		||||
    love.graphics.pop()
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue