DefRS - A collection of useful resources

Repo: https://github.com/subsoap/defrs

DefRS

A collection of useful general resources made ready to be used with the Defold game engine

The purpose of this resource collection is to help speed up workflows for new projects, and help new users to learn useful techniques.

The license for the files included are CC0 1.0 Universal unless otherwise noted.

Installation

You can use DefRS in your own project by adding this project as a Defold library dependency. Open your game.project file and in the dependencies field under project add:

https://github.com/subsoap/defrs/archive/master.zip

Once installed, you can use the resources you wish to use from their associated folders much like you would builtin resources. When you make builds Defold will only package the files you actually use so do not worry about the extra files included. Check your build folder to see for yourself.

Check the source files and examples for full usage.

9 Likes

This is sort of a continuation of Pro Tips plus a bunch of other resources I’ve prepared in the past. I’ll be updating it over time with lots of useful goodies! Like usual if you would like to be a contributor just ask and I’ll add you, if you want to contribute something send me a zip and I’ll add what works or do a pull request.

2 Likes

Added example to handle Alt+F4 on Windows.

Also an example showing how to make aura type effects in orthographic projection games.

https://www.pkeod.com/defrs/auras/

The shimmering and apparent lengthening of the attachments when they become flat isn’t intentional, not sure the cause but I vaguely remember that kind of thing happening in a past dev project with a different engine. But also may be a Defold bug.

Edit: shimmering was caused by the attachments not having a material set with a sampler. This version is fixed.

https://www.pkeod.com/defrs/auras_fixed/

4 Likes

Added a colors library module! With it getting and setting colors in your scripts is a little more convenient. It also has a random color function, and a # hex color to rgba normalized function built into it.

Example usage

local colors = require("defrs.utils.colors")

function init(self)
	pprint(colors.red)
	pprint(colors.get_random_color())
	
	self.timer = 0
	self.step = 1
end

function update(self, dt)
	self.timer = self.timer + dt
	if self.timer > 1 then
		self.timer = self.timer - 1
		self.step = self.step + 1
		if self.step == 4 then
			self.step = 1
		end
	end
	if self.step == 1 then
		go.set("#label","color",colors.red)
	elseif self.step == 2 then
		go.set("#label","color",colors.magenta)
	elseif self.step == 3 then
		go.set("#label","color",colors.get_random_color())
	end
end

I’ll add more color names to it over time so you can reasonably give any common name for a color and get its vec4 values formatted correctly for use.

4 Likes

Added a hue shift function that will take any vec4 color and shift it by a amount so you can shift over time or for whatever reason you might have. It’s possible to do things such as fade between two nearby hues.

colors.hue_shift(color, amount)

4 Likes

Added 864 more colors from a batch process and realized I probably shouldn’t make so many vmath.vector4s? Todo will be to make it a meta table and return the vec4s as they are needed.

2 Likes

Added identicons generation example. This example shows

  • Dealing with certain Random Number Generator issues such as bad early data
  • Initializing your global RNG once so that it is based on OS time
  • Creating groups of objects from factories
  • Updating the list of objects you previously created on some event
  • Generating data in a repeatable way over time based on seed + step method
  • Setting up tilemaps and updating tilemap data

https://www.pkeod.com/defrs/identicons/

Identicons can be used as temporary avatars. You could increase the number of layers, and have some layers with transparent shapes to generate more detailed avatars.

Using an RNG method such as Mersenne Twister would be in improvement.

4 Likes

! Is this really useful? Having 10-20 predefined colors might be, but 864? I don’t think anyone goes “Hmm, I think I want international_orange_golden_gate_bridge for this text” (and yes, that’s actually one of the colors generated in the file).

1 Like

You’re right - I’ll prune it down to a reasonable amount! The idea was more that you could type any common word for a color and actually get a match but many of them have non-intuitive names. Also going to make an html page that can be opened for a quick color key.

Do bmfonts work for you in editor 2? I tried making some and couldn’t get them to work

1 Like

Added example showing detection of the Konami Code!

https://www.pkeod.com/defrs/konami_code/

It could be adapted to detect any typed cheat code. A gesture version could be added too. A problem with it is that unless you have all keys added to your input file then it’s easier to not mess up the cheat codes you do detect.

3 Likes

Made Konami Code example a tad more juicy :smiley:

Might have to force refresh to get past cache.

2 Likes

Working on this example right now. Meant to show moving by vectors, and with a gameplay idea of a space shooter with gravity. So you must survive, shoot things, and fly against the pull of the sun.

https://www.pkeod.com/defrs/orbit/

Going to test making ad turn and ws forward/backward impulse.

4 Likes

Alternative version where ws moves forward and back based on direction and ad rotate direction.

https://www.pkeod.com/defrs/orbit_alt/

Could be made into a fun game where all you are doing is trying to survive as long as possible while avoiding the sun / other things floating through space.

6 Likes

@Pkeod, this is super awesome! Great community resource :slight_smile:

4 Likes

I hope eventually some people get inspired to take the basic ideas and iterate them into full games! I’ll add q and e for strafing sometime soon. Later today I’ll make some examples working with bezier curves.

3 Likes

Today working on making a shooter example with autotiles. So you draw the tiles with a solid tile and when the game loads it automatically sets the correct tile based on neighbors.

Example will also show collision detection without using built in box2d. And probably some basic state based AIs / action list based AIs.

5 Likes

Autotiling is great feature for an engine!
I am waiting for Editor 2 plugins - and want to try to make it in the editor.

3 Likes

I’m really looking forward to user plugins too! There are so many kinds of plugins other tools have which would be super useful for Defold to have…

Working on random level generation at the moment. This is where in engine autotile will be really useful for procedurally generated and destructible level layouts!


4 Likes

Demo for random level. Click to get another random layout. At this size, it takes a moment. The method is very brute force and not optimized! Interesting that on Windows build it is much faster than HTML5 build. Probably modifying a table and then applying it to a tilemap would be much faster too rather than doing a ton of tilemap lookups? Probably would want to use fewer steps with this method, and then do multiple passes of multiplying the scale of the generated map and adding random changes to it such as making certain areas in to rooms / placing premade chunks / detecting features you don’t want to appear and changing them / adding doodads and loot / mobs …

https://www.pkeod.com/defrs/random_level/

1 Like

Basics for classic tile based RPG movement with simple collision detection.

https://www.pkeod.com/defrs/rpg_movement/

6 Likes