Skip to content

New Entity Guide

EntranceJew edited this page Oct 11, 2014 · 3 revisions

Important Codepoints

If you're adding custom entities you'll need to know the following parts of the code to put everything in the right spots.

  • /main.lua:love.load() Add a require somewhere with the rest of them.
require "entityclassname"
  • /main.lua:love.load():entityclassnamequads{} Define the quads of your entity with the rest of the quads.
  • /main.lua:love.load():imagelist{} Insert a string here that corresponds to the entityclassname, it will automatically be processed into the global defaultentityclassnameimg that is an Image loaded from /graphics/DEFAULT/entityclassname.png. This will then be assigned to entityclassnameimg, which is the one you should reference in your entity.
  • /game.lua:game_draw():scenedraw() Inside scenedraw, which is a function declared inside game_draw, you'll need to manually invoke your draw method:
--Orgates
for i, v in pairs(objects["orgate"]) do
	v:draw()
end
  • /game.lua:loadlevel():objects You'll need to instantiate your class in here, like this:
objects["entityclassname"] = {}
  • /game.lua:loadmap() If the game doesn't know how to read your entity from a written file, you're in for some trouble. Just throw the following snippet in with the rest of the elseif block. Make sure you use the same signature as you do with the function's init method. You could also simply alter the map if you made the correct changes elsewhere with the info documented about the r variable.
elseif t == "entityclassname" then
	table.insert(objects["entityclassname"], entityclassname:new(x, y, r))
  • /entity.lua:entitylist{} If your entity isn't listed, then it won't be usable, example listing:
    • t the class of the entity
    • category where it will be listed, try to use existing categories if possible
    • output whether or not the entity is linkable
    • description shows up at the bottom
    • iconauthor whoever made the neat icon
{t="entityclassname", category="smb stuff", output=true, description="it does fun things", iconauthor="you"},
  • /graphics/entitytooltips/entityclassname.png If there is a graphic here, it will be used as a tooltip. The image size is 64x64.
  • /entity.lua:rightclickmenues{} Add an index that corresponds to the t value in the entitylist, example class listing all the control types:
    • WARNING: If you use t="submenu" with actualvalue=true, default should be the string value because when the object is placed by the editor it pulls the default and does not translate indexes to values.
rightclickmenues.entityclassname = {
	{t="text", value="direction:"},
	{t="directionbuttons", down=true, left=true, right=true, up=true, default="right"},
	{t="checkbox", text="default off", default="false"},
	{t="text", value="width:"},
	{t="scrollbar", min=0.5, max=15, step=0.5, default=3},
	{t="linkbutton", value="link power", link="power"},
	{t="submenu", entries={"blue", "orange", "white", "purple"}, default=1, width=6},
	{t="submenu", entries=function() local t = {} for i, v in pairs(musiclist) do table.insert(t, v) end return t end, actualvalue=true, default=1, width=15},
	{t="input", default="text", max=50},
	{t="regionselect", value="select region", region="region", default="region:0:0:1:1"},
	{t="directionbuttons", hor=true, ver=true, default="ver"}, 
}
  • /entityclassname.lua:init(x, y, r) When loadmap is happening, it calls entityclassname:new() which wraps this. You need to have at least x and y for its position and r for any additional data that is given to it from the rightclick menu in the editor. Here is an example of how r is handled in code:
--Input list
self.r = {unpack(r)}
--r == the map data at map[x][y]
table.remove(self.r, 1) --r[1] == tile index, can be used to look up properties in tilequads{}
table.remove(self.r, 1) --r[2] == entity index, can be used to look up generic base entity in entitylist{}
-- all indexes of r after this point are those that you defined by the rightclick menu.
--DIRECTION
if #self.r > 0 and self.r[1] ~= "link" then
	-- I'm not certain why we're using
	self.dir = self.r[1]
	table.remove(self.r, 1)
end
--BASE
if #self.r > 0 and self.r[1] ~= "link" then
	self.base = self.r[1]
	table.remove(self.r, 1)
end
Clone this wiki locally