Skip to content

Commit

Permalink
Merge pull request #1837 from hawkthorne/master
Browse files Browse the repository at this point in the history
Bugfix 0.3.2
  • Loading branch information
kyleconroy committed Oct 29, 2013
2 parents 55cf77d + a57fe65 commit 11fd1a1
Show file tree
Hide file tree
Showing 41 changed files with 1,283 additions and 860 deletions.
7 changes: 3 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,10 @@ bin/tmx2lua:

bin/love.app/Contents/MacOS/love:
mkdir -p bin
$(wget) https://bitbucket.org/kyleconroy/love/downloads/love-sparkle.zip
unzip -q love-sparkle.zip
rm -f love-sparkle.zip
$(wget) https://bitbucket.org/kyleconroy/love/downloads/love-osx-mavericks-fixed.zip
unzip -q love-osx-mavericks-fixed.zip
rm -f love-osx-mavericks-fixed.zip
mv love.app bin
cp osx/dsa_pub.pem bin/love.app/Contents/Resources
cp osx/Info.plist bin/love.app/Contents

/usr/bin/love:
Expand Down
4 changes: 0 additions & 4 deletions osx/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,5 @@
<string>2006-2012 Hawkthorne Development Team</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>SUFeedURL</key>
<string>http://example.com</string>
<key>SUPublicDSAKeyFile</key>
<string>dsa_pub.pem</string>
</dict>
</plist>
Binary file modified src/audio/sfx/fire_thrown.ogg
Binary file not shown.
305 changes: 177 additions & 128 deletions src/character.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,172 +4,221 @@ local Timer = require 'vendor/timer'
local sound = require 'vendor/TEsound'
local utils = require 'utils'

local contents, _ = love.filesystem.read('character_map.json')
local sprite_map = json.decode(contents)
local module = {}

local characters = {}
-- Just for backwards compat
module.name = 'abed'

for i,p in pairs( love.filesystem.enumerate( 'characters' ) ) do

-- bring in the data from the character file
local contents, _ = love.filesystem.read('characters/' .. p)
local character = json.decode(contents)

if character.animations then --merge
local base = utils.deepcopy(character.animations)
character.animations = utils.deepcopy(sprite_map)
for k,v in pairs(base) do
character.animations[k] = v
end
else
character.animations = utils.deepcopy(sprite_map)
end

-- build the character
character.beam = love.graphics.newImage( 'images/characters/' .. character.name .. '/beam.png')
character.beam:setFilter('nearest', 'nearest')

character.count = 1

character.sheets = {}
character.sheets.base = love.graphics.newImage( 'images/characters/' .. character.name .. '/base.png')
character.sheets.base:setFilter('nearest', 'nearest')

character.mask = love.graphics.newQuad(0, character.offset, 48, 35, character.sheets.base:getWidth(), character.sheets.base:getHeight())

character.positions = require( 'positions/' .. character.name )

character._grid = anim8.newGrid( 48, 48, character.sheets.base:getWidth(), character.sheets.base:getHeight() )
character._warp = anim8.newGrid( 36, 300, character.beam:getWidth(), character.beam:getHeight() )

for state, _ in pairs( character.animations ) do
local data = character.animations[ state ]
if state == 'warp' then
character.animations[ state ] = anim8.newAnimation(data[1], character._warp(unpack(data[2])), data[3])
else
if type( data[1] ) == 'string' then
-- positionless
character.animations[ state ] = anim8.newAnimation(data[1], character._grid(unpack(data[2])), data[3])
else
-- positioned
for i, _ in pairs( data ) do
character.animations[ state ][i] = anim8.newAnimation(data[i][1], character._grid(unpack(data[i][2])), data[i][3])
end
end
end
end

character.costumemap = {}
character.categorytocostumes = {}
for _,c in pairs( character.costumes ) do
character.costumemap[ c.sheet ] = c
character.categorytocostumes[ c.category ] = character.categorytocostumes[ c.category ] or {}
table.insert( character.categorytocostumes[ c.category ], c )
end

characters[ character.name ] = character
end
local _loaded_character = nil
local _character = 'abed'
local _costume = 'base'

local Character = {}
Character.__index = Character
Character.characters = characters

Character.name = 'abed'
Character.costume = 'base'

Character.warpin = false

function Character:reset()
self.state = 'idle'
self.direction = 'right'
self.state = 'idle'
self.direction = 'right'
end

function Character:setCharacter( name )
if character == self.name then return end
-- FIXME: Needed for the taco meat item
-- If a character doesn't have this costume, no effect takes place
function Character:setCostume(costume)
if costume == self.costume then
return
end

if self.characters[name] then
self.name = name
self.costume = 'base'
return
end
-- Stuff for magic
end

error( "Invalid character ( " .. name .. " ) requested!" )
function Character:sheet()
return self:getSheet(self.costume)
end

function Character:setCostume( costume )
if costume == self.costume then return end
function Character:getSheet(costume)
local path = 'images/characters/' .. self.name .. '/' .. costume .. '.png'

if self:hasCostume(costume) then
self.costume = costume
return
end
error( "Undefined costume ( " .. costume .. " ) requested for character ( " .. self.name .. " )" )
if not self.sheets[costume] then
self.sheets[costume] = love.graphics.newImage(path)
self.sheets[costume]:setFilter('nearest', 'nearest')
end

return self.sheets[costume]
end

function Character:hasCostume( costume )
for _,c in pairs( self:current().costumes ) do
if c.sheet == costume then
return true
end
end
return false
function Character:update(dt)
self:animation():update(dt)
end

function Character:current()
return self.characters[self.name]
function Character:animation()
return self.animations[self.state][self.direction]
end

function Character:sheet()
return self:getSheet( self.name, self.costume )
function Character:warpUpdate(dt)
self.animations.warp:update(dt)
end

function Character:getSheet(char,costume)
if not self.characters[char].sheets[costume] then
self.characters[char].sheets[costume] = love.graphics.newImage( 'images/characters/' .. char .. '/' .. costume .. '.png')
self.characters[char].sheets[costume]:setFilter('nearest', 'nearest')
end
return self.characters[char].sheets[costume]
function Character:respawn()
self.warpin = true
self.animations.warp:gotoFrame(1)
self.animations.warp:resume()
sound.playSfx( "respawn" )
Timer.add(0.30, function() self.warpin = false end)
end

function Character:updateAnimation(dt)
self:animation():update(dt)
function Character:draw(x, y)
self:animation():draw(self:sheet(), x, y)
end

function Character:animation()
return self.characters[self.name].animations[self.state][self.direction]
function Character:getCategory()
return self.costumemap[self.costume].category
end

function Character:warpUpdate(dt)
self:current().animations.warp:update(dt)
function Character:getOverworld()
return self.costumemap[self.costume].ow
end

function Character:respawn()
self.warpin = true
self:current().animations.warp:gotoFrame(1)
self:current().animations.warp:resume()
sound.playSfx( "respawn" )
Timer.add(0.30, function() self.warpin = false end)
function module.pick(name, costume)
if not love.filesystem.exists("characters/" .. name .. ".json") then
error("Unknown character " .. name)
end

if not love.filesystem.exists("images/characters/" .. name .. "/" .. costume .. ".png") then
error("Unknown costume " .. costume .. " for character " .. name)
end

_character = name
_costume = costume
_loaded_character = nil
end

function module.load(character)
if not love.filesystem.exists("characters/" .. character .. ".json") then
error("Unknown character " .. character)
end

local contents, _ = love.filesystem.read('characters/' .. character .. ".json")
return json.decode(contents)
end

function Character:draw()
-- Load the current character. Do all the crazy stuff too
function module.current()
if _loaded_character then
return _loaded_character
end

local beamPath = 'images/characters/' .. _character .. '/beam.png'
local basePath = 'images/characters/' .. _character .. '/base.png'
local characterPath = "characters/" .. _character .. ".json"

if not love.filesystem.exists(characterPath) then
error("Unknown character " .. _character)
end

local contents, _ = love.filesystem.read('character_map.json')
local sprite_map = json.decode(contents)

local contents, _ = love.filesystem.read(characterPath)

local character = json.decode(contents)
setmetatable(character, Character)

character.name = _character
character.costume = _costume
character.warpin = false

if character.animations then --merge
local base = utils.deepcopy(character.animations)
character.animations = utils.deepcopy(sprite_map)
for k,v in pairs(base) do
character.animations[k] = v
end
else
character.animations = utils.deepcopy(sprite_map)
end

-- build the character
character.beam = love.graphics.newImage(beamPath)
character.beam:setFilter('nearest', 'nearest')

character.count = 1

character.sheets = {}
character.sheets.base = love.graphics.newImage(basePath)
character.sheets.base:setFilter('nearest', 'nearest')

character.mask = love.graphics.newQuad(0, character.offset, 48, 35,
character.sheets.base:getWidth(),
character.sheets.base:getHeight())

character.positions = utils.require('positions/' .. character.name)

character._grid = anim8.newGrid(48, 48,
character.sheets.base:getWidth(),
character.sheets.base:getHeight())

character._warp = anim8.newGrid(36, 300, character.beam:getWidth(), character.beam:getHeight())

for state, _ in pairs(character.animations) do
local data = character.animations[state]
if state == 'warp' then
character.animations[state] = anim8.newAnimation(data[1], character._warp(unpack(data[2])), data[3])
else
if type( data[1] ) == 'string' then
-- positionless
character.animations[state] = anim8.newAnimation(data[1], character._grid(unpack(data[2])), data[3])
else
-- positioned
for i, _ in pairs( data ) do
character.animations[state][i] = anim8.newAnimation(data[i][1], character._grid(unpack(data[i][2])), data[i][3])
end
end
end
end

character.costumemap = {}
character.categorytocostumes = {}

for _,c in pairs(character.costumes) do
character.costumemap[c.sheet] = c
character.categorytocostumes[c.category] = character.categorytocostumes[c.category] or {}
table.insert(character.categorytocostumes[c.category], c)
end

_loaded_character = character
return character
end

function Character:getCategory()
return self:current().costumemap[ self.costume ].category

function module.getCostumeImage(character, costume)
local path = "images/characters/" .. character .. "/" .. costume .. ".png"
return love.graphics.newImage(path)
end

function Character:getOverworld()
return self:current().costumemap[ self.costume ].ow

function module.characters()
local list = {}

for _, filename in pairs(love.filesystem.enumerate('characters')) do
local name, _ = filename:gsub(".json", "")
table.insert(list, name)
end

return list
end

function Character:findRelatedCostume( char )
--returns the requested character's costume that is most similar to the current character
local costumes = self.characters[ char ].categorytocostumes[ self:getCategory() ]
if costumes then return costumes[math.random(#costumes)].sheet end
return 'base'
--returns the requested character's costume that is most similar to the current character
function module.findRelatedCostume(name, category)
local char = module.load(name)

for _, costume in pairs(char.costumes) do
if costume.category == category then
return costume.sheet
end
end

return 'base'
end

Character:reset()

return Character
return module
2 changes: 1 addition & 1 deletion src/characterstrip.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
-- A single colored strip, on which a character appears for selection.
-- Created by tjvezina
----------------------------------------------------------------------
local window = require 'window'

local CharacterStrip = {}
CharacterStrip.__index = CharacterStrip

local window = require 'window'

local stripSize = 35 -- Thickness of the strip
local moveSize = 300 -- Pixels travelled from ratio 0 to 1
Expand Down
1 change: 1 addition & 0 deletions src/credits.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ end
state.credits = {
app.i18n('credits'),
'6sutters',
'8bitgentleman',
'a8252359',
'aaronpetykowski',
'academania',
Expand Down
Loading

0 comments on commit 11fd1a1

Please sign in to comment.