Page 1 of 15

HUMP - yet another set of helpers

Posted: Mon Aug 09, 2010 5:42 pm
by vrld
There are quite a number of helper libraries out there, ranging from vector classes to complete frameworks like Pölygamy, but I decided to release the byproducts of projects anyway.

And thus hump - LÖVE Helper Utilities for Massive Progression - was born.
Currently it features a matured vector class, a simple and easy class system, a gamestate system, timers and tweens, signals and slots, and a camera with locking and movement smoothing
I may add other things like some time in the future.

Hump differs from other libraries in that every component is independent of the remaining ones (well, apart from camera.lua, which needs the vector class), meaning that you can pick and choose what you need and what you don't. Hump's footprint is very small and it should fit nicely into your projects.

Sourcecode and documentation are available on github and readthedocs:

Documentation: http://hump.readthedocs.org
Sourcecode: http://github.com/vrld/hump

Re: HUMP - yet another set of helpers

Posted: Mon Aug 09, 2010 6:07 pm
by nevon
Nice! That's great, and I will most likely use this in upcoming projects. What license is it under?

Re: HUMP - yet another set of helpers

Posted: Mon Aug 09, 2010 8:54 pm
by vrld
I knew i forgot something, so, ahem:
Helper Utilities for a Multitude of Problems is free software under the (modified) MIT license. Do whatever you want with it :D

Re: HUMP - yet another set of helpers

Posted: Mon Aug 09, 2010 9:09 pm
by Chief
Lövely! Gotta love the open source!

Re: HUMP - yet another set of helpers

Posted: Wed Aug 11, 2010 3:39 pm
by nevon
So, I wanted to use the gamestate lib and the class lib. The documentation for the class one is great, but there isn't any for the other one. It seems straightforward enough for the most part; the only thing I'm wondering about is how to use the enter and leave states. Got an example to show?

Re: HUMP - yet another set of helpers

Posted: Wed Aug 11, 2010 4:55 pm
by vrld
The enter and leave functions are called when you use Gamestate.switch(to, ...).

The first argument to the enter function is the previous state, the rest are the remaining arguments passed to Gamestate.switch. The previous-state-as-argument mostly a hack to retrieve state values not passed to Gamestate.switch but also to make the switch call not too verbose.

The leave is called right before the state is switched (and before the enter of the next state). I mostly use this for stopping music or resetting fonts.

An example:

Code: Select all

Gamestate.titlescreen = Gamestate.new()
local st = Gamestate.titlescreen

function st:enter()
    start_music()
    love.graphics.setBackgroundColor(10,20,30)
    love.graphics.setColor(0,0,0)
end

function st:leave()
    stop_music()
end

function st:keyreleased(key)
    if key == 'return' then
        Gamestate.switch(Gamestate.game, self.playerName)
    end
end

[...]

Gamestate.game = Gamestate.new()
local st = Gamestate.game

function st:enter(pre, playerName)
    if pre == Gamestate.pause then return end
    self.playerName = playerName
end
[...]
For a working example see here: http://github.com/vrld/notalone/tree/master/state/

Re: HUMP - yet another set of helpers

Posted: Wed Aug 11, 2010 8:39 pm
by nevon
I'm using the gamestate lib now, and it is incredibly easy to use. Thanks a bunch for making and releasing this.

Re: HUMP - yet another set of helpers

Posted: Thu Aug 12, 2010 6:46 am
by pekka
Good job with the documentation, vrld. You're being a model to all library makers here.

There's a cosmetic mark-up problem after function Gamestate.mousereleased(x,y,btn) that you might want to correct some time.

Re: HUMP - yet another set of helpers

Posted: Fri Aug 13, 2010 9:52 am
by Sslaxx
I'm doing something pretty wrong with the gamestate code, I just don't know what.

http://sslaxx.twu.net/EggTester.love - just started to convert one section of the code so far to use gamestates, but it produces this error:
boot [string "Code/gamestate.lua"]:28: attempt to index field 'current' (a nil value) stack traceback:
[string "boot.lua"]:833: in function 'error_printer'
[string "boot.lua"]:768: in function <[string "boot.lua"]:766>
[string "Code/gamestate.lua"]:28: in function 'update'
[string "boot.lua"]:307: in function <[string "boot.lua"]:295>
[C]: in function 'xpcall'
[string "boot.lua"]:840: in main chunk
Help?

Re: HUMP - yet another set of helpers

Posted: Fri Aug 13, 2010 12:53 pm
by vrld
pekka wrote:There's a cosmetic mark-up problem after function Gamestate.mousereleased(x,y,btn) that you might want to correct some time.
Thanks, I missed that.
I've created a git project page with a more usable documentation: http://vrld.github.com/hump/
Sslaxx wrote:Help?
That error occurs because you did not use Gamestate.switch() to enter your title gamestate.
Rather than calling Gamestate.TitleScreen:enter() you need to do Gamestate.switch(Gamestate.TitleScreen) - preferably in love.load() so you can be sure the state exists.
I pointed that out in the new documentation and also added a dummy initial state to gamestate.lua which will throw errors at you if did not switch to a valid state.