Skip to content

Instantly share code, notes, and snippets.

@bucketh3ad
bucketh3ad / gameover.lua
Created November 15, 2012 08:18
Gameover to select
...
-- From splash to select
function state:keypressed( button )
Gamestate.switch("select")
end
...
@bucketh3ad
bucketh3ad / gist:4562481
Last active December 11, 2015 06:58
Possible Konami Code Fixes
Possibility 1:
self.konami = { 'UP', 'UP', 'DOWN', 'DOWN', 'LEFT', 'RIGHT', 'LEFT', 'RIGHT', 'JUMP', 'ATTACK' }
TO
self.konami = { 'UP', 'UP', 'DOWN', 'DOWN', 'LEFT', 'RIGHT', 'LEFT', 'RIGHT', 'SELECT', 'ATTACK' }
Possibilty 2:
if self.konami[self.konami_idx + 1] == button then
self.konami_idx = self.konami_idx + 1
@bucketh3ad
bucketh3ad / InventoryRefactorB&A
Last active December 17, 2015 06:39
A small part of the inventory refactor for journey to hawkthorne -bucketh3ad
BEFORE:
function Inventory:keypressed( button )
if self:isOpen() then
if button == 'SELECT' then
self:close()
end
if button == 'RIGHT' then
self:right()
end
if button == 'LEFT' then
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
@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
@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 / 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 / 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 / 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 / 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