parent
0a71f140dd
commit
8730b38444
|
@ -7,10 +7,10 @@ local SOME_TABLE = {}
|
||||||
|
|
||||||
---@alias AnyComponent any
|
---@alias AnyComponent any
|
||||||
---@alias BitMask number
|
---@alias BitMask number
|
||||||
---@alias ButtonState { receivedInputThisFrame: boolean, aJustPressed: boolean, bJustPressed: boolean, upJustPressed: boolean, downJustPressed: boolean, leftJustPressed: boolean, rightJustPressed: boolean }
|
|
||||||
---@alias Collision { collisionBetween: Entity[] }
|
---@alias Collision { collisionBetween: Entity[] }
|
||||||
---@alias Entity table
|
---@alias Entity table
|
||||||
---@alias FontData love.FontData
|
---@alias FontData love.FontData
|
||||||
|
---@alias KeyState table<string, boolean>
|
||||||
---@alias XyPair { x: number, y: number }
|
---@alias XyPair { x: number, y: number }
|
||||||
|
|
||||||
T = {
|
T = {
|
||||||
|
@ -28,9 +28,6 @@ T = {
|
||||||
---@type BitMask
|
---@type BitMask
|
||||||
BitMask = 0,
|
BitMask = 0,
|
||||||
|
|
||||||
---@type ButtonState
|
|
||||||
ButtonState = SOME_TABLE,
|
|
||||||
|
|
||||||
---@type Collision
|
---@type Collision
|
||||||
Collision = SOME_TABLE,
|
Collision = SOME_TABLE,
|
||||||
|
|
||||||
|
@ -40,6 +37,9 @@ T = {
|
||||||
---@type FontData
|
---@type FontData
|
||||||
FontData = SOME_TABLE,
|
FontData = SOME_TABLE,
|
||||||
|
|
||||||
|
---@type KeyState
|
||||||
|
KeyState = SOME_TABLE,
|
||||||
|
|
||||||
---@type XyPair
|
---@type XyPair
|
||||||
XyPair = SOME_TABLE,
|
XyPair = SOME_TABLE,
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,7 @@ local SOME_TABLE = {}
|
||||||
Collision = "{ collisionBetween: Entity[] }",
|
Collision = "{ collisionBetween: Entity[] }",
|
||||||
BitMask = "number",
|
BitMask = "number",
|
||||||
FontData = "love.FontData",
|
FontData = "love.FontData",
|
||||||
ButtonState = "{ receivedInputThisFrame: boolean, aJustPressed: boolean, bJustPressed: boolean, upJustPressed: boolean, downJustPressed: boolean, leftJustPressed: boolean, rightJustPressed: boolean }",
|
KeyState = "table<string, boolean>",
|
||||||
}))
|
}))
|
||||||
T = {
|
T = {
|
||||||
bool = true,
|
bool = true,
|
||||||
|
|
11
main.lua
11
main.lua
|
@ -33,7 +33,6 @@ local delta
|
||||||
|
|
||||||
function love.load()
|
function love.load()
|
||||||
currentScenario()
|
currentScenario()
|
||||||
World:setSystemIndex(LiveForNFrames, 1)
|
|
||||||
love.graphics.setBackgroundColor(1, 1, 1)
|
love.graphics.setBackgroundColor(1, 1, 1)
|
||||||
love.graphics.setFont(EtBt7001Z0xa(32))
|
love.graphics.setFont(EtBt7001Z0xa(32))
|
||||||
end
|
end
|
||||||
|
@ -55,12 +54,22 @@ function love.update(dt)
|
||||||
end
|
end
|
||||||
|
|
||||||
World:update(delta, function(_, system)
|
World:update(delta, function(_, system)
|
||||||
|
if system.deferToEnd then
|
||||||
|
return false
|
||||||
|
end
|
||||||
return not system.isDrawSystem
|
return not system.isDrawSystem
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.draw()
|
function love.draw()
|
||||||
World:update(delta, function(_, system)
|
World:update(delta, function(_, system)
|
||||||
|
if system.deferToEnd then
|
||||||
|
return false
|
||||||
|
end
|
||||||
return system.isDrawSystem
|
return system.isDrawSystem
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
World:update(delta, function(_, system)
|
||||||
|
return system.deferToEnd
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,3 +12,4 @@ LiveForNFrames = filteredSystem("liveForNFrames", { liveForNFrames = T.number },
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
LiveForNFrames.deferToEnd = true
|
|
@ -1,13 +1,58 @@
|
||||||
---@type ButtonState
|
---@type KeyState
|
||||||
local buttonState = {}
|
local keyState = {}
|
||||||
|
|
||||||
buttonInputSystem = filteredSystem("buttonInput", { canReceiveButtons = T.marker }, function(e, _, system)
|
local keyInputSystem = filteredSystem("keyInput", { canReceiveKeys = T.marker }, function(e, _, system)
|
||||||
e.buttonState = buttonState
|
e.keyState = keyState
|
||||||
system.world:addEntity(e)
|
system.world:addEntity(e)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
function buttonInputSystem:preProcess()
|
function keyInputSystem:preProcess()
|
||||||
if #self.entities == 0 then
|
if #self.entities == 0 then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function love.keypressed(key, _, _)
|
||||||
|
keyState[key] = true
|
||||||
|
end
|
||||||
|
|
||||||
|
function ClearKeyState()
|
||||||
|
for key in pairs(keyState) do
|
||||||
|
keyState[key] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local mouse = filteredSystem("mouse", { mouseKeyPress = { position = T.XyPair, key = T.number } })
|
||||||
|
|
||||||
|
function MouseJustPressed(key, clear)
|
||||||
|
clear = clear ~= nil and clear or true
|
||||||
|
for _, event in pairs(mouse.entities) do
|
||||||
|
if event.mouseKeyPress and event.mouseKeyPress.key == key then
|
||||||
|
if clear then
|
||||||
|
event.mouseKeyPress = nil
|
||||||
|
World:removeEntity(event)
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
local mouseX, mouseY = -9999, -9999
|
||||||
|
|
||||||
|
function love.mousemoved(x, y)
|
||||||
|
mouseX, mouseY = x, y
|
||||||
|
end
|
||||||
|
|
||||||
|
function love.mousepressed(x, y, key)
|
||||||
|
World:addEntity({
|
||||||
|
mouseKeyPress = {
|
||||||
|
position = {
|
||||||
|
x = x,
|
||||||
|
y = y,
|
||||||
|
},
|
||||||
|
key = key,
|
||||||
|
},
|
||||||
|
liveForNFrames = 1,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in New Issue