Skip to content

Instantly share code, notes, and snippets.

@The0x539
The0x539 / poof.lua
Last active January 2, 2017 03:50
A one-by-one layer toggle library for SMBX
local poof = {}
--Version 0.2a
--By The0x539
--To poof a layer, use poof.startPoof(layer, frames, freeze) in your LunaLua file after loading the API.
--layer specifies which layer gets poof'd
--frames specifies the number of frames (give or take one or two, somebody teach The0x539 some computer science) between poofing each thing.
--freeze specifies whether time should be frozen starting when the camera moves, and ending when it's back at the player.
--If freeze == true, time is frozen. If freeze == false, player input is locked instead.
@The0x539
The0x539 / viewport.lua
Created July 17, 2017 15:18
Make SMBX's screen smaller
local viewport = {}
viewport.width, viewport.height = 640,480
local cam = Camera.get()[1]
local buffer = Graphics.CaptureBuffer(cam.width,cam.height)
function viewport.onInitAPI()
registerEvent(viewport,"onCameraUpdate")
end
@The0x539
The0x539 / _X.lua
Last active September 7, 2017 17:31
The LunaLua meta-API, now with metatables
local _X = {}
local names = {}
--Resolves a file. Can be expanded to include directories like graphics or resources or what have you.
function _X.loadFile(name)
return Misc.resolveFile(name)
end
--Loads an API into _X, such that it can be accessed as a global from any code using _x
@The0x539
The0x539 / browse.go
Created December 14, 2017 23:14
CADDY BROWSE VIDEO THINGY
// Copyright 2015 Light Code Labs, LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
@The0x539
The0x539 / checksums.lua
Created January 31, 2018 23:53
Recursively generate checksums of all videos in a directory on Windows
--Run an OS command, returning its output rather than its exit status.
local function run(cmd,mode)
local prog = io.popen(cmd)
local output
if mode == 1 then --String of full output
output = prog:read("*all"):sub(1,-2)
prog:close()
elseif mode == 2 then --Table of each line
output = {}
for line in prog:lines() do
@The0x539
The0x539 / foo.lua
Created March 5, 2018 23:16
SMBX deceleration logic
if player.speedX ~= 0 then
local direction = (player.speedX > 0 and 1 or -1)
local amt = 0
local fwd, back = player.rightKeyPressing, player.leftKeyPressing
if direction < 0 then
fwd, back = back, fwd
end
local run = player.runKeyPressing
local gnd = player:isGroundTouching()
local memo_mt = {__mode = "k"}
-- Memoize a function with one argument.
local function memoize(func)
local t = {}
setmetatable(t, memo_mt)
return function(x)
if t[x] then
return table.unpack(t[x])
else
local blocks = {}
local function tris(x, y, w, h)
return {
x, y,
x+w, y,
x+w, y+h,
x, y,
x, y+h,
x+w, y+h
#include <stdlib.h>
#include <string.h>
typedef unsigned int uint;
static void split_array(int array[], uint len, int **left, uint *llen, int **right, uint *rlen) {
*llen = *rlen = len / 2;
if (*llen + *rlen < len) {
*llen = *llen + 1;
}
size_t lsize = *llen * sizeof (int);
@The0x539
The0x539 / merge.c
Created September 25, 2018 01:22
now featuring arbitrary value support
#include <stdlib.h>
#include <string.h>
typedef unsigned int uint;
static void split_array(void *array[], uint len, void ***left, uint *llen, void ***right, uint *rlen) {
*llen = *rlen = len / 2;
if (*llen + *rlen < len) {
*llen = *llen + 1;
}
size_t lsize = *llen * sizeof (void *);