List of files and modified variables / functions:
- graphics/SMB/entities.png - New row of icons added.
- graphics/SMB/spikeydispenser.png - Sprite for the new entity to use.
- entity.lua - Information about the entity while in the editor.
- array entitylist - Internal names of entities.
- array entitydescriptions - Descriptions shown on the editor bottom line.
- variables.lua - A global variable is necessary to get our entity to work.
- float spikeydispensertime - The timer for making spikeys appear.
- game.lua - Important to include draw and initialization code so we can see and use the entity.
- function game_load - Loads the game with the data it needs.
- array inputs - The names of all the entities that accept inputs.
- array inputsi - The ID of entities that accept inputs based on their position on entities.png.
- function game_draw - Draws all the objects on the screen every frame.
- function loadmap - Loads information from map files and feeds it to the engine.
- function startlevel - Actually begins the level, blank initializes all arrays as necessary.
- function game_load - Loads the game with the data it needs.
- spikeydispenser.lua - The code our entity is going to use.
- main.lua - Include the entity code and image location.
- function love.load - The function that (re)initializes love2d.
First I added a icon to entities.png so that the entity editor knows what icon to use. I had to add a new row because if I added a new column then item IDs would have broken and that would have been terrible (unless I wanted to relocate all the icons properly). I padded the empty spaces with icons. It's important to remember that the grid size is 17x17.
graphics/SMB/spikeydispenser.png
I also added an upside down cube dispenser because it felt more natural to have spineys pop out the top.
entity.lua entitylist
Code: Select all
"spikeytube",
"",
"",
"",
"",
"",
"",
"",
"",
""
Code: Select all
"place on empty tile - will drop a spikey and remove previous one - use link tool", --"spikeytube"
"place nowhere - unused",
"place nowhere - unused",
"place nowhere - unused",
"place nowhere - unused",
"place nowhere - unused",
"place nowhere - unused",
"place nowhere - unused",
"place nowhere - unused",
"place nowhere - unused"
game.lua game_load
Code: Select all
inputs = { "door", "groundlight", "wallindicator", "cubedispenser", "walltimer", "notgate", "laser", "lightbridge", "spikeydispenser"}
inputsi = {28, 29, 30, 43, 44, 45, 46, 47, 48, 67, 74, 84, 52, 53, 54, 55, 36, 37, 38, 39, 101}
For the next batch of code I mostly searched for the terms:
- cubedispenser
- boxtube
- spikeydispenser
- spikeytube
Code: Select all
--spikeydispensers
for j, w in pairs(objects["spikeydispenser"]) do
w:draw()
end
Code: Select all
elseif t == "spikeytube" then
table.insert(objects["spikeydispenser"], spikeydispenser:new(x, y, r))
Code: Select all
objects["spikeydispenser"] = {}
variables.lua spikeydispensertime
Code: Select all
spikeydispensertime = 1
main.lua love.load
Code: Select all
require "spikeydispenser"
Code: Select all
spikeydispenserimg = love.graphics.newImage("graphics/" .. graphicspack .. "/spikeydispenser.png")
spikeydispenser.lua
spikeydispenser.lua - this is mostly re-purposed code from cubedispenser and a mishmash of stuff from lakitu.lua and goomba.lua (because that's where spikey's code is, hiding in there). I will outline the code in this later when I have more time.
The message Maurice originally replied to was:
EntranceJew wrote:I'm working on a custom entity but for some reason the game both runs painfully slow after I rebuild it, also I can't find where to give it an icon in the entity menu and it crashes the game when I try to place one.