Skip to content

Instantly share code, notes, and snippets.

🐈
Catpants everywhere.

David Hayes drhayes

🐈
Catpants everywhere.
Block or report user

Report or block drhayes

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@drhayes
drhayes / rexpaint.lua
Last active May 15, 2019
A lightweight REXPaint .xp file reader for LOVE2D.
View rexpaint.lua
--
-- A lightweight REXPaint .xp reader for LOVE2D.
-- By Vriska Serket / @arachonteur
-- Adapted by drhayes to not use self, make constants uppercase,
-- and updated to work with love 11.2.
-- From https://gist.github.com/vriska-serket/334bfcfa7dfe7265ddbe089e4a51e522
--
-- Output table looks like this.
--[[
{
@drhayes
drhayes / brain.lua
Created Mar 22, 2019
An old, busted version of coroutine-based AI
View brain.lua
local Brain = {}
local currentTime = 0
local timeWaits = {}
local animWaits = {}
local yields = {}
local function yield()
local co = coroutine.running()
yields[co] = true
return coroutine.yield(co)
@drhayes
drhayes / brain.lua
Created Mar 22, 2019
An old coroutine-based AI
View brain.lua
local lume = require 'lib/lume'
local Brain = {}
local currentTime = 0
local timeWaits = {}
local animWaits = {}
local function waitSeconds(secs)
local co = coroutine.running()
timeWaits[co] = currentTime + secs
@drhayes
drhayes / syncFacingSchemes.lua
Last active Aug 27, 2018
Slerp between rotations without doing the flippy thing.
View syncFacingSchemes.lua
local ax, ay = math.cos(fov.angle), math.sin(fov.angle)
local gx, gy = math.cos(goalAngle), math.sin(goalAngle)
ax, ay = ax + gx * 5 * dt, ay + gy * 5 * dt
fov.angle = math.atan2(ay, ax)
@drhayes
drhayes / camera.lua
Created Mar 9, 2018
LÖVE camera shake
View camera.lua
self.noiseFactor = self.noiseFactor + dt
-- self.trauma = math.min(1, self.trauma) - dt * config.camera.traumaFactor
self.trauma = math.max(0, self.trauma - dt * config.camera.traumaFactor)
if self.cameraTarget then
self.x = self.x + (self.cameraTarget.pos.x - self.x) * dt * self.slideFactor
self.y = self.y + (self.cameraTarget.pos.y - self.y) * dt * self.slideFactor
end
-- Shake based on trauma
local shake = self.trauma ^ 2
local maxOffset, maxAngle = config.camera.shake.maxOffset, config.camera.shake.maxAngle
View camera.lua
function Camera:resize(w, h)
local dw, dh = config.graphics.width, config.graphics.height
local x, y = w / dw, h / dh
local scale = math.min(x, y)
local width, height = dw * scale, dh * scale
self.camera:setScale(scale)
local wPadding, hPadding = (w - width) / 2, (h - height) / 2
self.padding = {
x = wPadding, y = hPadding
}
@drhayes
drhayes / drawSystem.lua
Created Feb 22, 2018
An ECS draw system I wrote.
View drawSystem.lua
local tiny = require 'lib.tiny'
local spriteAtlas = require 'core.spriteAtlas'
local lume = require 'lib.lume'
local physicsSystem = require 'systems.physics'
local config = require 'gameConfig'
function drawSystem(groupName)
groupName = groupName or 'default'
local drawSystem = tiny.processingSystem({ isDraw = true })
@drhayes
drhayes / drone.lua
Created Feb 15, 2018
The onDead method from drone enemies
View drone.lua
local function onDead(world, drone)
Signal.emit('enemyKilled', drone)
local viralAmount = (drone.health.damage.viral or 0) / drone.health.max
if viralAmount >= 0.5 then
drone.animation.currentName = 'dead'
drone.body.fx = 50
drone.invoke = {
onInvoke = 'doLoot'
}
particles:viralSparks(drone)
View gist:8a2b9fac37b2ce72d651a881369688d1
Verifying my Blockstack ID is secured with the address 1M1QN2SWzH4ecxeDgAjFDii1F6hSrGswLj https://explorer.blockstack.org/address/1M1QN2SWzH4ecxeDgAjFDii1F6hSrGswLj
You can’t perform that action at this time.