Difference between revisions of "Pölygamy"

(v 0.4.0)
 
m (Added: Other Languages)
 
(13 intermediate revisions by 3 users not shown)
Line 1: Line 1:
'''Pölygamy''' is a set of libraries design to simplify the organization of a LÖVE game.
+
'''Pölygamy''' is a small [[LÖVE]] [[framework]].
  
Currently, a state and a keyboard lib are available, and a timer lib is in the works.
+
Currently, a state and a keyboard modules are available, and a timer module is in the works. Each module can be used in isolation, but they are designed to be complementary.
  
'''Polygamy.keyboard'''  
+
 
* allows to bind keys to callbacks in a declarative fashion,
+
'''Modules:'''
* supports multiple, switchable configurations
+
 
* supports configuration (single) inheritance.
+
''Polygamy.keyboard''
 +
* allows to [[keybinding|bind keys]] to [[callback]]s in a [[declarative]] fashion,
 +
* supports multiple, switchable [[configuration]]s
 +
* supports configuration (single) [[inheritance]].
 
* supports useful ranges ([f-j] is expanded to f, g, h, j) and other patterns inspired by the Lua patterns library.
 
* supports useful ranges ([f-j] is expanded to f, g, h, j) and other patterns inspired by the Lua patterns library.
* allows to treat the keyboard as a key matrix (full support for US qwerty keyboards only at the moment, but the common subset of qwerty, azerty and qwertz can be used iniversally (sorry, dvorak users))
+
* allows to treat the keyboard as a key matrix (full support for US qwerty keyboards only at the moment, but the common subset of [[qwerty]], [[azerty]] and [[qwertz]] can be used universally (sorry, dvorak users))
* is freindly with both imperative and OO coding styles.
+
* is freindly with both [[imperative]] and [[OO]] coding styles.
  
'''Polygamy.state'''  
+
''Polygamy.state''
 
* allows to design each game state as if it were a full LÖVE app (custom update and draw callbacks),
 
* allows to design each game state as if it were a full LÖVE app (custom update and draw callbacks),
 
* supports state transitions (through before( from, to, ... ) and after( from, to, ... ) callbacks)
 
* supports state transitions (through before( from, to, ... ) and after( from, to, ... ) callbacks)
  
See [http://love2d.org/forum/viewtopic.php?f=5&t=1240&p=12081#p12081 | this forum post] for the latest version and the (extensive) documentation.
+
See {{forumlink|forum=5|topic=1240|title=this forum post}} for the latest version and the (extensive) documentation.
  
Here's an Dummy app written with Pölygamy:
+
Here's an dummy app written with Pölygamy:
  
 
<source lang="lua">
 
<source lang="lua">
Line 51: Line 54:
 
if from == "Title Screen" then --[[Game.state.reset()]] end
 
if from == "Title Screen" then --[[Game.state.reset()]] end
 
Polygamy.timer:resume()
 
Polygamy.timer:resume()
pkeyboard.use( to ) -- selfhandle == "In game" in this case
+
pkeyboard.use( to ) -- to == "In game" in this case
 
print "In Game"
 
print "In Game"
 
end
 
end
Line 79: Line 82:
 
----------------------------------------------------------------------------------
 
----------------------------------------------------------------------------------
  
pauseState = state( "Pause Screen" )
+
pause = state( "Pause Screen" )
                  --============--
+
              --============--
function pauseState.before() pkeyboard.use( "pause" ); print"Pause" end
+
function pause.before() pkeyboard.use( "pause" ); print"Pause" end
function pauseState.update(dt) end -- if you don't define it, the previous callback remains active.
+
function pause.update(dt) end -- if you don't define it, the previous callback remains active.
function pauseState.draw() --[[ display "Paused" on top of the screenshot.]] end
+
function pause.draw() --[[ display "Paused" on top of the screenshot.]] end
  
  
Line 100: Line 103:
 
</source>
 
</source>
  
{{#set:LOVE Version=0.6.1}}
+
{{#set:LOVE Version=0.6.x}}
{{#set:Description=State, Keyboard and Timer libraries that fit well together.}}
+
{{#set:Description=Game State, Keyboard and Timer helpers}}
 +
{{#set:Keyword=Framework}}
 
[[Category:Libraries]]
 
[[Category:Libraries]]
 +
 +
== Other Languages ==
 +
{{i18n|Pölygamy}}

Latest revision as of 15:50, 15 December 2019

Pölygamy is a small LÖVE framework.

Currently, a state and a keyboard modules are available, and a timer module is in the works. Each module can be used in isolation, but they are designed to be complementary.


Modules:

Polygamy.keyboard

  • allows to bind keys to callbacks in a declarative fashion,
  • supports multiple, switchable configurations
  • supports configuration (single) inheritance.
  • supports useful ranges ([f-j] is expanded to f, g, h, j) and other patterns inspired by the Lua patterns library.
  • allows to treat the keyboard as a key matrix (full support for US qwerty keyboards only at the moment, but the common subset of qwerty, azerty and qwertz can be used universally (sorry, dvorak users))
  • is freindly with both imperative and OO coding styles.

Polygamy.state

  • allows to design each game state as if it were a full LÖVE app (custom update and draw callbacks),
  • supports state transitions (through before( from, to, ... ) and after( from, to, ... ) callbacks)

See this forum post for the latest version and the (extensive) documentation.

Here's an dummy app written with Pölygamy:

love.filesystem.load("library/Polygamy/init.lua")("library/Polygamy/") -- must be outside the load callback.
                                                -- since it creates a custom love.run loop

local state, goto, pkeyboard = Polygamy.state, Polygamy.state.goto, Polygamy.keyboard   -- for convenience
-- load your ressources, initialize your code... then : 


--------------------------------------------------------------------------------

title = state( "Title Screen" )
              --============--

function title.before() pkeyboard.use( "title" ); print"menu" end
function title.update(dt)  --[[ your title update callback ]] end
function title.draw()      --[[ draw your fine title here  ]] end

pkeyboard( "title" ):setConfig( "pressed", {
	[{" ", "return"}] = function() goto("In Game")       end,
	escape            = function() love.event.push('q') end,
	[Polygamy.default] = print
})


---------------------------------------------------------------------------------

ingame = state( "In Game" )
               --=======--

function ingame.before( from, to, ... )
	if from == "Title Screen" then --[[Game.state.reset()]] end
	Polygamy.timer:resume()
	pkeyboard.use( to ) -- to == "In game" in this case
	print "In Game"
end

function ingame.update( dt ) --[[ instill life in your game world ]] end

function ingame.draw()   --[[ and render it in its full glory ]] end

function ingame.after( from, to, ... )
	Polygamy.timer:pause()	
	if to == "Pause Screen" then
		-- dim the screen, take a screenshot
	end
end



pkeyboard("In Game"):setConfig("pressed", {
	
	[" %arrows "] = { held = function(key,_,_,dt) Hero:move(key,dt); end },
	[" "]  = function() Hero:shoot()           end,
	escape = function() goto( "Title Screen" ) end,
	p      = function() goto( "Pause Screen" ) end
})


----------------------------------------------------------------------------------

pause = state( "Pause Screen" )
              --============--
function pause.before() pkeyboard.use( "pause" ); print"Pause" end
function pause.update(dt) end -- if you don't define it, the previous callback remains active.
function pause.draw() --[[ display "Paused" on top of the screenshot.]] end


pkeyboard( "pause" ):setConfig( "pressed", {
	escape = function() goto( "Title Screen" ) end,
	p      = function() goto( "In Game" )      end
})

-- then get the ball rolling :-)

function love.load() 
    print"Start" 
    goto("Title Screen") 
end

Other Languages