This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- https://github.com/vrld/hump/blob/master/vector.lua | |
-- http://nova-fusion.com/2011/06/30/lua-metatables-tutorial/ | |
local assert = assert | |
local sqrt, cos, sin, atan = math.sqrt, math.cos, math.sin, math.atan2 | |
Vector = {} | |
Vector.__index = Vector | |
function Vector.new(x, y) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- The problem: | |
-- Lua has a problem whenever you want to define a C-like struct. | |
-- For instance, when I want to define a point structure without having | |
-- to define a new class I can create a table like so: | |
-- | |
-- {x = number, y = number} | |
-- | |
-- And a function that does something to points can use them like this: | |
-- | |
-- function dist(p1, p2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- There are some timing related constructs that appear very often | |
-- while developing games. One such construct is as follows: | |
-- | |
-- function update(dt) | |
-- counter = counter + dt | |
-- if counter >= action_delay then | |
-- counter = 0 | |
-- action() | |
-- end | |
-- end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getPSO(filename) | |
local templates = loadstring("return " .. love.filesystem.read(filename))() | |
local pss = {} | |
local degToRad = function(d) return d*math.pi/180 end | |
local getPS = function(template) | |
local sprite = love.graphics.newImage('your_default_sprite_here.png') | |
local ps = love.graphics.newParticleSystem(sprite, template.buffer_size) | |
ps:setBufferSize(template.buffer_size) | |
local colors = {} | |
for i = 1, 8 do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Graph = {} | |
Graph.__index = Graph | |
function Graph.new() | |
return setmetatable({adjacency_list = {}}, Graph) | |
end | |
function Graph:__tostring() | |
local str = "" | |
for node, list in pairs(self.adjacency_list) do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Graph = {} | |
Graph.__index = Graph | |
function Graph.new() | |
return setmetatable({adjacency_list = {}, nodes = {}, edges = {}, floyd_dists = {}}, Graph) | |
end | |
function Graph:__tostring() | |
local str = "----\nAdjacency List: \n" | |
for node, list in pairs(self.adjacency_list) do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local async = require('async') | |
function love.load(args) | |
async.load() | |
async.ensure.atLeast(2) | |
local version = nil | |
local version_request = async.define("version_request", function() | |
local request = require('luajit-request') | |
local response = request.send(link to the version file) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export Object | |
class Object | |
new: (level, x, y, opts) => | |
for k, v in pairs(opts) do self[k] = v | |
@id = uuid! | |
@dead = false | |
@creation_time = love.timer.getTime! | |
@depth = 50 | |
@level = level |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function love.load() | |
-- Setup necessary to make the screen have a pixelated look | |
window_width, window_height = 1280, 720 | |
game_width, game_height = 480, 270 | |
love.window.setMode(window_width, window_height) | |
love.graphics.setDefaultFilter('nearest') | |
love.graphics.setLineStyle('rough') | |
canvas = love.graphics.newCanvas(game_width, game_height) | |
physics_step() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
timers = {} | |
function after(delay, action, repeatable, after, tag) | |
local tag = tag or uid() -- uid returns a unique id every time it's called, "or" will resolve the expression to the result of uid() if tag is nil (the same as if not tag then tag = uid() end) | |
timers[tag] = {type = 'after', current_time = 0, delay = delay, action = action, repeatable = repeatable, after = after, tag = tag} | |
end | |
function tween(delay, target, source, method, after, tag) | |
local tag = tag or uid() | |
local initial_values = {} |
OlderNewer