Skip to content

Instantly share code, notes, and snippets.

@bucketh3ad
bucketh3ad / elm-runtime-global.js
Created June 1, 2014 00:05
Elm Runtime Global Wrapper
Elm = (function (){
//Begin elm-runtime.js
'use strict';
var Elm = ...
};
//End elm-runtime.js
Elm.MeteorHelpers = [A2,A3,A4,A5,A6,A7,A8,A9,F2,F3,F4,F5,F6,F7,F8,F9];
@bucketh3ad
bucketh3ad / fractalzoom.elm
Last active August 29, 2015 14:01
Elm Fractal Zoom Toy
import Math.Vector2 (Vec2)
import Math.Vector3 (..)
import Math.Matrix4 (..)
import Graphics.WebGL (..)
import Mouse
import Keyboard
-- Define the mesh for a crate
crate : [Triangle { pos:Vec3, coord:Vec3 }]
crate = concatMap rotatedFace [ (0,0), (90,0), (180,0), (270,0), (0,90), (0,-90) ]
@bucketh3ad
bucketh3ad / scenes.elm
Last active August 29, 2015 14:01
Elm Scenes Example
import Keyboard
import Mouse
mpos : Signal (Int,Int)
mpos = Mouse.position
kpos : Signal {x:Int,y:Int}
kpos = Keyboard.arrows
draw1 : (Int,Int) -> Element
@bucketh3ad
bucketh3ad / arrayslice.elm
Last active August 29, 2015 14:00
Inclusive vs. Exclusive Array Slicing
-- subArray - Take two Ints, i and l, and an Array and returns an Array with length l starting at index i
subArray : Int -> Int -> Array a -> Array a
subArray i l = slice i (i + l - 1)
-- slice' - Exclusive slicing (breaks negative indices)
slice' i j = slice i (j-1)
subArray' i l = slice' i (i + l)
take' = slice' 0
@bucketh3ad
bucketh3ad / kleinsteroids.elm
Last active August 29, 2015 14:00
Klein Bottle Asteroids: Caffeinated Version
-- Klein Bottle Asteroids: Caffeinated Version
-- By: bucketh3ad
-- MODIFIED AFTER Ludum Dare 29
import Keyboard
--MODELS AND INPUTS
type Input = {space:Bool, dx:Int, dy:Int, dt:Time}
@bucketh3ad
bucketh3ad / klein.elm
Created April 28, 2014 05:10
Klein Bottle Asteroids
-- Klein Bottle Asteroids
-- By: bucketh3ad
-- Ludum Dare 29
import Keyboard
--MODELS AND INPUTS
type Input = {space:Bool, dx:Int, dy:Int, dt:Time}
@bucketh3ad
bucketh3ad / gist:5774569
Last active December 18, 2015 11:18
Currently broken drop function
---
-- Drops the currently selected item and destroys it TODO: Prompt for confirmation and/or create a node.
-- @return nil
function Inventory:drop()
if self.craftingState == 'open' then return end --Ignore dropping in the crafting annex
local slotIndex = self:slotIndex(self.cursorPos)
if self.pages[self.currentPageName][slotIndex] then
local level = GS.currentState()
local itemNode = self.pages[self.currentPageName][slotIndex].props
local NodeClass = require('/nodes/' .. itemNode.type)
@bucketh3ad
bucketh3ad / inventoryswitch
Created May 15, 2013 01:41
New Inventory Switching
function Inventory.new()
...
inventory.pageList = {
weapons = {'keys', 'consumables'},
keys = {'materials', 'weapons'},
materials = {'consumables', 'keys'},
consumables = {'weapons', 'materials'}
} --Each key's value is a table with this format: {nextpage, previouspage}
...
end
@bucketh3ad
bucketh3ad / inventoryopenclose
Created May 13, 2013 19:25
Inventory Open/Close Code
This is the relevant code in its current form.
These two functions are responsible for closing the inventory, and should be consolidated somehow:
---
-- Begins closing the players inventory
-- @return nil
function Inventory:close()
self.player.controlState:standard()
self:craftingClose()
self.pageNext = self.state
inventory.pageList = {
weapons = 'keys',
keys = 'materials',
materials = 'consumables',
consumables = 'weapons'
} --Each key's value is the subsequent page name
inventory.pageNext = 'consumables' --Initial inventory page
inventory.pageLength = 13 --With 0 index, pages have a capacity of 14
inventory.pages = {}
for i in pairs(inventory.pageList) do --Creates a new blank table for each key in pageList