Skip to content

Instantly share code, notes, and snippets.

@Uradamus
Uradamus / shuffle.lua
Last active April 20, 2025 18:27
A simple array shuffle function for Lua implementing the Fisher-Yates shuffle.
function shuffle(tbl)
for i = #tbl, 2, -1 do
local j = math.random(i)
tbl[i], tbl[j] = tbl[j], tbl[i]
end
return tbl
end
@Uradamus
Uradamus / class_test.lua
Last active August 29, 2015 13:58
Simple example of a combination class definition / construction function in Lua.
function Class (arg1, arg2, arg3)
local obj = {}
obj.var1 = arg1
obj.var2 = arg2
obj.var3 = arg3
function obj:out (arg)
print(self[arg])
end
@Uradamus
Uradamus / links
Created April 5, 2014 13:28
Useful game math links
@Uradamus
Uradamus / main.lua
Created March 20, 2014 15:28
Simple example of normalized delta x and y values.
function love.load()
local start_x = 0
local start_y = 0
local end_x = 10
local end_y = 5
dx = (end_x - start_x)
dy = (end_y - start_y)
local distance = math.sqrt(dx^2 + dy^2)