Skip to content

Instantly share code, notes, and snippets.

package com.ludamix.entity;
class Entity
{
public var id(default, null) : Int;
public var properties : Dynamic;
public function new(id, properties)
{
@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.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); }
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);
[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
{
/*
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.
@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 / ExampleEventSys.hx
Created December 20, 2014 11:55
Example event system
class Eventsys
{
public var entities = new Map<Int, IEntity>();
public function new(){}
/* raw spawning tools. instantiate and assign parameters to entities with your own configuration mechanism. */
public function spawn(e : IEntity, id : Int) { if (entities.exists(id)) { throw "overlapping entity id"; } e.id = id; entities.set(id, e); }
public function despawn(e : IEntity) { entities.remove(e.id); }
# Generate and playback a sine tone
import sdl2
import sdl2/audio
import math
# Audio settings:
const Channels = 1
const RQSizeInSamples = 4096 * Channels
type Uniforms = object
faefar:GLint # fade factor
tee:array[0..1,GLint] # textures
type Attributes = object
pon:GLint # position
type Resources = object
vexbur, eltbur:GLuint # vertex, element buffers
tee:array[0..1,GLuint] # textures
vexshr, frtshr:GLuint # vertex, element shaders
prm:GLuint # program