Streaming game development: https://www.twitch.tv/stabyourself Image

[TUTORIAL] How to add custom (linked) entities.

Mods, guides how to use and install mods go right in here.
EntranceJew
User avatar
Posts: 93
Joined: 05 Mar 2012, 05:37
Reputation: 23

Post » 06 Mar 2012, 03:57

The following is a brief guide on how I managed to add a spikey spawner to Mari0 1.3 that highlights the purpose of some files and what was changed in them.

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.
  • 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.

Image
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
Image
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",
   "",
   "",
   "",
   "",
   "",
   "",
   "",
   "",
   ""

entity.lua entitydescriptions

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"

Blank entries are included because I had to make a new row of entities when I made this. When you add your own entities you can put them next to each other in what the blank spaces would be.

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}

Here I added 101 to the end of inputsi and "spikeydispenser" to the end of inputs. Inputs doesn't appear to be used elsewhere but I put it here for good measure. 101 is the tenth row, first icon, thus the spikey icon that got added to entities.png.

For the next batch of code I mostly searched for the terms:
  • cubedispenser
  • boxtube
And copied relevant chunks of code, pasted it beneath it and changed (in the copied code) the terms to:
  • spikeydispenser
  • spikeytube
game.lua game_draw

Code: Select all

      --spikeydispensers
      for j, w in pairs(objects["spikeydispenser"]) do
         w:draw()
      end

game.lua loadmap

Code: Select all

               elseif t == "spikeytube" then
                  table.insert(objects["spikeydispenser"], spikeydispenser:new(x, y, r))

game.lua startlevel

Code: Select all

   objects["spikeydispenser"] = {}

I don't use line numbers because they are subject to change between versions of Mari0 and previous source versions are not listed publicly on the site.

variables.lua spikeydispensertime

Code: Select all

spikeydispensertime = 1

There is no global variable spikeydispensertime like there is cubedispensertime, so we have to make it. This makes it so that spikeydispenser.lua has a global timer to use.

main.lua love.load

Code: Select all

   require "spikeydispenser"

Code: Select all

   spikeydispenserimg = love.graphics.newImage("graphics/" .. graphicspack .. "/spikeydispenser.png")

Here I include in two different sections of the love.load function code to require and load in the spikeydispenser lua code and I define its image.

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.
Last edited by EntranceJew on 07 Mar 2012, 16:57, edited 3 times in total.

Maurice
Stabyourself.net
Posts: 2142
Joined: 01 Feb 2012, 20:19
Reputation: 103

Post » 06 Mar 2012, 04:58

Then you're probably doing something wrong.

EntranceJew
User avatar
Posts: 93
Joined: 05 Mar 2012, 05:37
Reputation: 23

Post » 06 Mar 2012, 05:17

Maurice wrote:Then you're probably doing something wrong.


So I've gathered.

Maurice
Stabyourself.net
Posts: 2142
Joined: 01 Feb 2012, 20:19
Reputation: 103

Post » 06 Mar 2012, 05:32

If I remember correctly, entities need to be in the following places:
main.lua: requires the lua file
entity.lua: adds the string for the entity load (this has to be in the right position!)
game.lua: startlevel needs to create a table for it
loadmap needs to check for the string defined in entity.lua and create a new class object
update needs to update the entity
draw needs to draw it unless it uses my object system (probably not) or doesn't need to be drawn

And you'll need to edit entities.png and add it there.

bambo
User avatar
Posts: 59
Joined: 02 Feb 2012, 21:37
Reputation: 0
Contact:

Post » 06 Mar 2012, 21:41

everything i'm finding out about the code i'm documenting, so eventually i can shove it all in a wiki of some sorts for other people to read.

HateMeh
Posts: 39
Joined: 03 Feb 2012, 12:32
Reputation: 0

Post » 06 Mar 2012, 22:41

bambo wrote:everything i'm finding out about the code i'm documenting, so eventually i can shove it all in a wiki of some sorts for other people to read.

thats brilliant cause for the most part i can´t make head or tails of the code.

EntranceJew
User avatar
Posts: 93
Joined: 05 Mar 2012, 05:37
Reputation: 23

Post » 07 Mar 2012, 00:54

I managed to add a spiney (or, as the engine refers to them, spikey) spawner. Thanks to Maurice for the heads up on some of the file locations and the game itself.
(For those referring to this thread, I ended up modifying far more than just those mentioned to get this in particular complete.)
You could use my code as an example for adding a linked entity if you were to do something like generate a version difference against the mari0 1.2 source.
Here's a download that includes the modified source and a windows executable: MediaFire

EntranceJew
User avatar
Posts: 93
Joined: 05 Mar 2012, 05:37
Reputation: 23

Post » 07 Mar 2012, 06:55

Tutorial moved from here to above.
Forgot to mention: Do whatever with the code, anybody. Implement it into the actual game or pop out a ton of neat mods with it.

Flutter Skye
User avatar
Posts: 1717
Joined: 08 Apr 2012, 17:54
Reputation: 787
Contact:

Post » 06 Jun 2012, 21:49

can you update this to 1.6

SonicStalker
User avatar
Posts: 21
Joined: 30 Jan 2013, 02:33
Reputation: 0

Post » 06 Apr 2013, 09:08

I've been trying to add in what is basicly another weighted cube, but everytime i run it it appears like normal on the entities selection grid, but when played with in the actuall level it just looks like the regular weighted cube. What am i doing wrong?

imgudman4567
User avatar
Posts: 249
Joined: 22 Jun 2015, 23:22
Reputation: 18
Contact:

Post » 02 Nov 2015, 03:50

Geeeeez this is ded, but I have a question.... Does thios method work on later versions than 1.3 or no?

alesan99
User avatar
Posts: 1636
Joined: 30 May 2013, 21:42
Reputation: 265
Contact:

Post » 02 Nov 2015, 03:59

It should because it worked for me.
Just try it and if you run in to problems post them in your mod thread.

Though if you're modding SE you should use http://guegan.de/mari0doc/custom_enemies.php

imgudman4567
User avatar
Posts: 249
Joined: 22 Jun 2015, 23:22
Reputation: 18
Contact:

Post » 03 Nov 2015, 02:50

alesan99 wrote:It should because it worked for me.
Just try it and if you run in to problems post them in your mod thread.

Though if you're modding SE you should use http://guegan.de/mari0doc/custom_enemies.php


Thanks, and I do have a problem, but I'll say so in my mod thread.
Also, not really a question, but I might need a base for an enemy to make in mari0 1.6


Return to “Modding”

Who is online

Users browsing this forum: No registered users and 2 guests

cron