I'd like to present you Wire, a simple lib for reactive programming in LÖVE:
https://github.com/italonascimento/wire
It's still in early stage of development, but is already usable and documented, so I'd be happy to know what the community thinks of it.
For those who enjoy reactive programming, like myself, this lib aims to be a simple way to develop games in a reactive and declarative way, separating the logics from the side effects.
On the other hand, for those who are not familiarized with the reactive paradigm, it may seem overcomplicated at first, but hey, don't be scared!
Basicaly, a Wire powered game is written as a pure fuction, which receives sources and returns sinks. The sources table contains reactive streams of the user's intents, while the sinks table contains streams of side effects to be performed.
A basic example:
Code: Select all
local function game(sources)
return {
reducer = rx.Observable.merge(
-- initial state
rx.Observable.of(function()
return {
text = 'Hello World'
})
end),
-- update state on key press
sources.events.keypressed
:filter(function(key)
return key == 'space'
end)
:map(function()
return function(prevState)
return wire.assign(prevState, {
text = 'Hello Interactive World :)'
})
end
end)
),
-- emit render on state update
render = sources.state
:map(function(state)
return function()
love.graphics.print(state.text, 8, 8)
end
end)
}
end
- a reducer stream, which is a merge of two streams: one that emits right away, setting the game initial state to { text = 'Hello World' }, and a second one that emits everytime the user hits the space key, which sets the game state to { text = 'Hello Interactive World ' };
- and a render key, which emits a new render function everytime the game state is updated.
Want to know more about Wire's concept and usage? Take a look at the documentation:
https://italonascimento1.gitbooks.io/wire/content/
Feel free to make comments or to ask any questions!