Skip to content

Instantly share code, notes, and snippets.

View KeyMaster-'s full-sized avatar

Tilman Schmidt KeyMaster-

View GitHub Profile
@KeyMaster-
KeyMaster- / integrator_lab.rs
Last active March 28, 2020 23:59
A simple harmonic oscillator simulation for testing out different numerical integration methods. Logs state at each step in CSV format.
// Just position and velocity along one dimension. We're assuming the particle has a mass of 1.
#[derive(Clone)]
struct State {
x: f64,
v: f64,
}
trait Integrator {
fn step(&mut self, state: State, sim: &Simulation, dt: f64) -> State;
import luxe.GameConfig;
import luxe.Input;
import luxe.Vector;
class Main extends luxe.Game {
//--- The actual important stuff --
var verts:Array<Vector>; //Holds the '3D model' vertices, i.e. actual 3D coordinates
@KeyMaster-
KeyMaster- / RotatingPyramid.hx
Last active October 19, 2016 12:00
A quick luxe program to demonstrate manual perspective projection of a rotating pyramid.
import luxe.GameConfig;
import luxe.Input;
import luxe.Vector;
class Main extends luxe.Game {
//--- The actual important stuff --
var verts:Array<Vector>; //Holds the '3D model' vertices, i.e. actual 3D coordinates
@KeyMaster-
KeyMaster- / to_hex.p8
Created September 24, 2016 13:45
Pico8 number-to-hex function
hex_abc = '0123456789abcdef'
function to_hex(num)
local str = ''
for i=0,7 do --8 packs of 4 bits for 32 bit number
local digit = num
local shift = (i - 4)*4
if shift < 0 then digit = shl(digit, -shift)
else digit = shr(digit, shift) end
@KeyMaster-
KeyMaster- / FunctionFinder.hx
Created February 12, 2016 23:26
A macro that extracts all static methods from a class that conform to a certain function signature, and returns an array with those functions.
import haxe.macro.Expr;
import haxe.macro.Context;
import haxe.macro.Type;
import haxe.macro.TypeTools;
import haxe.macro.MacroStringTools;
class FunctionFinder {
macro public static function get_functions(e:Expr, fun_signature:Expr) {
var function_type:Type = switch(fun_signature.expr) {
case EConst(c):
@KeyMaster-
KeyMaster- / InputSystem.hx
Created July 17, 2015 14:42
Old OpenFL input system for an entity component system framework
/*
* Author: Richard Lord
* Copyright (c) Big Room Ventures Ltd. 2007
* Version: 1.0.2
* Modified and extended by Tilman Schmidt (@KeyMaster_)
* - Fixed key buffer size to contain enough bits for all keys
* - Added buffering for entity component system framework
* - Added keyUp and keyDown lookups
*
* Licence Agreement
@KeyMaster-
KeyMaster- / ScreenfluidExample.hx
Created April 26, 2015 20:21
Example use of a screen-wide fluid to create global drag for nape bodies
var screenShape = new Polygon(Polygon.rect(0, 0, Luxe.screen.w, Luxe.screen.h, true));
screenShape.fluidEnabled = true;
//Density of 0.3, Viscosity of 3. These are values you just have to experiment with until it feels right
screenShape.fluidProperties = new FluidProperties(0.3, 3);
//It's important to set the collisionMask (second parameter) to 0 here,
//so the shape doesn't collide with anything (we want everything to just move through it)
screenShape.filter = new InteractionFilter(1, 0);
//Set up a body holding the shape and add it to the space
var screenBody = new Body(BodyType.STATIC);
@KeyMaster-
KeyMaster- / WavePhys.hx
Created April 16, 2015 10:12
Code sample for doing wave spring physics
//Note: This does _not_ compile, it's just to demonstrate the relevant physics bits
class Main extends luxe.Game {
var fieldWidth:Int = 60;
var fieldDepth:Int = 60;
var physTimeStep:Float = 1 / 60;
var physTimeCounter:Float = 0;
var springK:Float = 100;
var springDampening:Float = 0.00;
@KeyMaster-
KeyMaster- / PhysBody.hx
Created April 4, 2015 22:16
Luxe rectangles physics engine (WIP, and very basic)
package ;
import luxe.Component;
import luxe.Rectangle;
import luxe.Vector;
class PhysBody {
public var rect:Rectangle;
public var vel:Vector;
public var acc:Vector;
@KeyMaster-
KeyMaster- / polarWarp.glsl
Last active November 20, 2019 15:00
Luxe polar warp shader
//The source texture that will be transformed
uniform sampler2D tex0;
//The texture coordinate passed in from the vertex shader (the default luxe vertex shader is suffice)
varying vec2 tcoord;
//x: width of the texture divided by the radius that represents the top of the image (normally screen width / radius)
//y: height of the texture divided by the radius representing the top of the image (normally screen height / radius)
uniform vec2 sizeOverRadius;