Usually I do my set of tools for myself but I thought it was interesting enough to be shared, so I put it on github
https://github.com/NicMagnier/mob.lua
Before, I was always creating tons of objects all over the place and all in different tables to easily loop through them (looping through enemies, through particles, and so on). It was working but it always make some horrible looking codes. So here the idea is to query the entities you want with a simply syntax so it very easy to read the source code and also to quickly query the entities you want.
So for example with mob.lua I can randomly pick a npc in a special state that is close by
Code: Select all
mob.get("type_npc @about_to_explode")
:filter(function(e)
local dx = e.x - love.mouse.getX()
local dy = e.y - love.mouse.getY()
return (dx*dx+dy*dy)<150*150
end)
:random()
Code: Select all
mob.get("on_ground")
:sort(function(a,b) return a.y<b.y end)
:draw()
-- draw all the cloud and output how many cloud are drawn
love.graphics.setColor(255,255,255,100)
mob.get("cloud"):draw()