parent
0a71f140dd
commit
8730b38444
|
@ -7,10 +7,10 @@ local SOME_TABLE = {}
|
|||
|
||||
---@alias AnyComponent any
|
||||
---@alias BitMask number
|
||||
---@alias ButtonState { receivedInputThisFrame: boolean, aJustPressed: boolean, bJustPressed: boolean, upJustPressed: boolean, downJustPressed: boolean, leftJustPressed: boolean, rightJustPressed: boolean }
|
||||
---@alias Collision { collisionBetween: Entity[] }
|
||||
---@alias Entity table
|
||||
---@alias FontData love.FontData
|
||||
---@alias KeyState table<string, boolean>
|
||||
---@alias XyPair { x: number, y: number }
|
||||
|
||||
T = {
|
||||
|
@ -28,9 +28,6 @@ T = {
|
|||
---@type BitMask
|
||||
BitMask = 0,
|
||||
|
||||
---@type ButtonState
|
||||
ButtonState = SOME_TABLE,
|
||||
|
||||
---@type Collision
|
||||
Collision = SOME_TABLE,
|
||||
|
||||
|
@ -40,6 +37,9 @@ T = {
|
|||
---@type FontData
|
||||
FontData = SOME_TABLE,
|
||||
|
||||
---@type KeyState
|
||||
KeyState = SOME_TABLE,
|
||||
|
||||
---@type XyPair
|
||||
XyPair = SOME_TABLE,
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ local SOME_TABLE = {}
|
|||
Collision = "{ collisionBetween: Entity[] }",
|
||||
BitMask = "number",
|
||||
FontData = "love.FontData",
|
||||
ButtonState = "{ receivedInputThisFrame: boolean, aJustPressed: boolean, bJustPressed: boolean, upJustPressed: boolean, downJustPressed: boolean, leftJustPressed: boolean, rightJustPressed: boolean }",
|
||||
KeyState = "table<string, boolean>",
|
||||
}))
|
||||
T = {
|
||||
bool = true,
|
||||
|
|
11
main.lua
11
main.lua
|
@ -33,7 +33,6 @@ local delta
|
|||
|
||||
function love.load()
|
||||
currentScenario()
|
||||
World:setSystemIndex(LiveForNFrames, 1)
|
||||
love.graphics.setBackgroundColor(1, 1, 1)
|
||||
love.graphics.setFont(EtBt7001Z0xa(32))
|
||||
end
|
||||
|
@ -55,12 +54,22 @@ function love.update(dt)
|
|||
end
|
||||
|
||||
World:update(delta, function(_, system)
|
||||
if system.deferToEnd then
|
||||
return false
|
||||
end
|
||||
return not system.isDrawSystem
|
||||
end)
|
||||
end
|
||||
|
||||
function love.draw()
|
||||
World:update(delta, function(_, system)
|
||||
if system.deferToEnd then
|
||||
return false
|
||||
end
|
||||
return system.isDrawSystem
|
||||
end)
|
||||
|
||||
World:update(delta, function(_, system)
|
||||
return system.deferToEnd
|
||||
end)
|
||||
end
|
||||
|
|
|
@ -12,3 +12,4 @@ LiveForNFrames = filteredSystem("liveForNFrames", { liveForNFrames = T.number },
|
|||
end
|
||||
end)
|
||||
|
||||
LiveForNFrames.deferToEnd = true
|
|
@ -1,13 +1,58 @@
|
|||
---@type ButtonState
|
||||
local buttonState = {}
|
||||
---@type KeyState
|
||||
local keyState = {}
|
||||
|
||||
buttonInputSystem = filteredSystem("buttonInput", { canReceiveButtons = T.marker }, function(e, _, system)
|
||||
e.buttonState = buttonState
|
||||
local keyInputSystem = filteredSystem("keyInput", { canReceiveKeys = T.marker }, function(e, _, system)
|
||||
e.keyState = keyState
|
||||
system.world:addEntity(e)
|
||||
end)
|
||||
|
||||
function buttonInputSystem:preProcess()
|
||||
function keyInputSystem:preProcess()
|
||||
if #self.entities == 0 then
|
||||
return
|
||||
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