Skip to content

Instantly share code, notes, and snippets.

@triplefox
triplefox / Main.hx
Created December 20, 2014 08:49
demo for Slactuate
import flash.Lib;
import flash.display.Shape;
class Main
{
public static var sp : Shape;
public static var slac : Slactuate;
static function main()
@triplefox
triplefox / Slactuate.hx
Created December 20, 2014 08:43
Slactuate, a one file tween library for Haxe
class Slactuate
{
/* how to use: build your own abstraction on m() and p() to ease the setting of properties. call u() each frame you update, then call c() to cleanup. */
public var td /*tween datas*/ = new Array<SlacTween>();
public function new(){}
public function u/*update to the given time*/(t : Float) { for (n in td) n.u(t); }
public function c/*clear tweens updated to past their end time, and return the removed ones*/() {
var i = td.length - 1; var r = new Array<SlacTween>(); if (td.length < 1) return r;
while (i >= 0) { var n = td[i]; if (n.ci > 1.) {r.push(td.splice(i, 1)[0]); } i -= 1; }
return r; }
package com.ludamix.ds;
class Deli
{
/*
Deli - "Better than your usual hashmap"
A syntax that maps text data to lists of numbers and strings by declaration,
vs. by position and context as in most textual formats.
[header one]
a$[]thing
a$[]other thing
b[,]1,2,3,4
[header two]
a[]thing
a[]other thing
b[,]1,2,3,4
package com.ludamix.ds;
class Deli
{
public static function parse(s : String) {
var m = new Map<String, Array<Array<String>>>();
for (l /*line*/ in s.split("\n")) {
var i0 = l.indexOf("["); var i1 = l.indexOf("]");
var k /*key*/ = l.substr(0, i0);
var d /*delimiter*/ = l.substr(i0 + 1, i1 - i0 - 1);
package com.ludamix.ds;
class Deli
{
public static function parse(s : String) {
var m = new Map<String, Array<String>>();
for (l /*line*/ in s.split("\n")) {
var i0 = l.indexOf("["); var i1 = l.indexOf("]");
var k /*key*/ = l.substr(0, i0); var d /*delimiter*/ = l.substr(i0 + 1, i1 - i0 - 1); var v /*value*/ = l.substr(i1 + 1);
var r /*value results*/ : Array<String>; /*get result array*/ if (m.exists(k)) r = m.get(k); else { r = new Array(); m.set(k, r); }
@triplefox
triplefox / mech.py
Created October 17, 2014 04:53
example of staticmethod
import random
class Mech(object):
def __str__(self):
return "Name: %s\n\tweight: %s\n\tslots: %s\n\tmax heat: %s" % (self.name, self.max_weight, self.slots, self.max_heat)
@staticmethod
def generator():
obj = Mech()
obj.name = 'Random Mech '+str(random.randint(0,9999))
obj.weight = random.randint(1,10)
package com.ludamix.entity;
class Entity
{
public var id(default, null) : Int;
public var properties : Dynamic;
public function new(id, properties)
{
package com.ludamix.heart;
/**
* Tilemap which turns abstract metatiles into groups of four subtiles via
* an algorithm that checks a collision mask.
*/
class AutoTilemap<T : (AutoTileDef)> implements Tilemap<TypedGrid<T>>
{
public var width (getWidth, null) : Int;
@triplefox
triplefox / AlphaTrie.hx
Created September 23, 2012 01:08
AlphaTrie
class AlphaTrie
{
// an implementation of a trie specifically for storing and looking up english dictionary words
public var chars : Hash<AlphaTrie>;
public var ending : Bool;
public function new()
{