diff --git a/collision.lua b/collision.lua index 735c70d..976001a 100644 --- a/collision.lua +++ b/collision.lua @@ -19,8 +19,11 @@ function Rectangle:new(x, y, width, height, xoff, yoff) end --checks to see if this rectangle intersects with a given point -function Rectangle:containspoint(x, y) - return x >= self.x and x <= self.x + self.width and y >= self.y and y <= self.y + self.height +function Rectangle:containspoint(x, y, mode) + mode = mode or "relative" + local xoff = mode == "relative" and 0 or mode == "absolute" and camera.fx + local yoff = mode == "relative" and 0 or mode == "absolute" and camera.fy + return x >= self.x + xoff and x <= self.x + self.width + xoff and y >= self.y + yoff and y <= self.y + self.height + yoff end --checks to see if this rectangle intersects with another rectangle, with an optional offset applied to this diff --git a/drawing.lua b/drawing.lua index 8f16f7e..e737236 100644 --- a/drawing.lua +++ b/drawing.lua @@ -5,6 +5,7 @@ function drawobject(o) if drawmode == "absolute" then love.graphics.push() love.graphics.origin() + love.graphics.scale(window.scale) end o:draw() diff --git a/input.lua b/input.lua index 538da57..71acd0d 100644 --- a/input.lua +++ b/input.lua @@ -2,8 +2,6 @@ mouse = { x = 0, y = 0, p = false, op = false, held = false } function updatemouse() mouse.x, mouse.y = love.mouse.getPosition() - --mouse.x = mouse.x - camera.fx * window.scale * -1 - --mouse.y = mouse.y - camera.fy * window.scale * -1 mouse.x = (mouse.x / window.scale) + camera.fx mouse.y = (mouse.y / window.scale) + camera.fy diff --git a/main.lua b/main.lua index 21c1e5b..1bb00e7 100644 --- a/main.lua +++ b/main.lua @@ -15,7 +15,7 @@ require "drawing" sti = require "lib/sti" moonshine = require "lib/moonshine" -window = { width = 1050, height = 600, scale = 1.3 } +window = { width = 800, height = 460, scale = 1.5 } speed = { target = 1 / 60, multiplier = 1 } @@ -26,6 +26,9 @@ physics = { gravity = 100, friction = 20 } p = {} function love.load() + window.width = window.width * window.scale + window.height = window.height * window.scale + love.window.setMode(window.width, window.height, { vsync = false }) love.window.setTitle("Love2D Project Template") love.graphics.setDefaultFilter("nearest", "nearest") @@ -39,7 +42,8 @@ function love.load() if v.user == "player" then player = v break end end - Button:add(300, 2900, "button", function() showdebug = not showdebug end) + Button:add(50, 100, "button", function() showdebug = not showdebug end) + --Button:add(250, 2200, "button", function() showdebug = not showdebug end) Textbox:add(500, 290, "debug button", { scroll = false }) end diff --git a/ui.lua b/ui.lua index 9182dcb..bded714 100644 --- a/ui.lua +++ b/ui.lua @@ -1,6 +1,7 @@ --button class Button = inherits(AnimatedSprite, { - state = 1 + state = 1, + drawmode = "absolute" }) local button_mt = class(Button) @@ -26,7 +27,7 @@ function Button:add(x, y, anim, action) end function Button:update(dt) - if self.bounds:containspoint(mouse.x, mouse.y) then + if self.bounds:containspoint(mouse.x, mouse.y, self.drawmode) then self.state = 2 if mouse.p or mouse.held then self.state = 3