Skip to content

Instantly share code, notes, and snippets.

View wilbefast's full-sized avatar

William Dyce wilbefast

View GitHub Profile
@wilbefast
wilbefast / android_deploy.sh
Created March 11, 2014 10:14
Deploy Löve-SDL on Android
#! /bin/bash
# replace this line with the root-directory of your android project
LOVE_ANDROID=/home/Documents/Programming/ANDROID/love-android-sdl2/
# build a .love file
cd src/
zip -r game.love * -x *.git*
# move it to the android project, package and deploy
@wilbefast
wilbefast / Soul.lua
Last active August 29, 2015 13:57
Make shiny souls move towards and orbit around the an object.
function Soul:update(dt)
local target_x, target_y = self.target_x, self.target_y
-- do we already have a target?
if (not target_x) and (not target_y) then
-- figure out the hook position
local hook_angle = math.pi*2/(#self.master.souls)*self.index + love.timer.getTime()*3
target_x = self.master.x + math.cos(hook_angle)*32
target_y = self.master.y + math.sin(hook_angle)*32
@wilbefast
wilbefast / useful.lua
Created May 20, 2014 20:34
Push and pop canvas object in Löve 2D.
useful.canvasStack = {}
function useful.pushCanvas(newCanvas)
table.insert(useful.canvasStack, love.graphics.getCanvas())
love.graphics.push()
love.graphics.origin()
love.graphics.setCanvas(newCanvas)
end
function useful.popCanvas()
@wilbefast
wilbefast / trycatch.lua
Last active August 29, 2015 14:01
Skip updates rather than showing Löve 2D's blue screen of death
local __unsafeUpdate = function()
local dt = math.min(MAX_DT, love.timer.getDelta())
-- do your update here
end
function love.update()
local success, err = xpcall(__unsafeUpdate, debug.traceback) -- use debug.debug for interactive debugging
if not success then
print(err)
end
@wilbefast
wilbefast / Resources.lua
Created June 1, 2014 11:18
File which defines all the resources to load into Soul Harvest
--[[------------------------------------------------------------
IMPORTS
--]]------------------------------------------------------------
local Animation = require("unrequited/Animation")
--[[------------------------------------------------------------
ALL RESOURCES
--]]------------------------------------------------------------
@wilbefast
wilbefast / Singleton.cs
Last active August 29, 2015 14:02
How to do Singleton scripts in Unity
public class Singleton : Monobehaviour
{
private static Singleton _instance = null;
public static Singleton instance
{
get
{
if (_instance == null)
{
// First try to find an instance already in the scene
@wilbefast
wilbefast / AbstractSkeletonTrackingDevice.cs
Last active August 29, 2015 14:02
Fun with lambdas and scoping in C#
public abstract class AbstractSkeletonTrackingDevice : AbstractControlDevice
{
// ...
protected void registerExerciseInput(SkeletonExercise new_exercise)
{
// ...
foreach(string axis_name in new_exercise.axisNames)
{
@wilbefast
wilbefast / tetrominoes.lua
Last active August 29, 2015 14:05
Tetrominoes in Lua, for use with some kind of parser
-- O shape
local tetro_O = "**--"..
"**--"..
"----"..
"----"
-- J shape
local tetro_J1 = "-*--"..
"-*--"..
"**--"..
@wilbefast
wilbefast / Sacrifice.lua
Last active August 29, 2015 14:05
Matching Tetrominos using the Zen of Lua...
function Sacrifice:matchTetros(tetros, col, row)
for _, t in ipairs(tetros) do
local i = 1
local matches = {}
for c = col, col + 3 do
for r = row, row + 3 do
local char = t:sub(i,i)
local limb, core = (char == '*'), (char == '@')
if (limb or core) then
if self:match(c, r) then
@wilbefast
wilbefast / shuffle.lua
Last active August 29, 2015 14:06
Shuffling tables and iterating them in a random order
--[[
What if you want to pick a random option but you're not sure if that random option will be valid?
Instead of doing a while loop and hoping that you'll eventually land on a valid option
try shuffling the list of options and trying each one in this random order ;)
W.
--]]
local shuffle = function(table) -- standard Fisher-Yates implementation
for i = #table, 2, -1 do