1. Danny Fritz
  2. blank LOVE

Commits

Danny Fritz  committed 455bddc

Splash screen and gamestate manager included in blank love file now.

  • Participants
  • Parent commits bbb3ae7
  • Branches default

Comments (0)

Files changed (22)

File conf.lua

View file
 
 function love.conf(t)
-  t.title = "Blank LOVE"  -- The title of the window the game is in (string)
-  t.author = "Danny Fritz \"TechnoCat\" dannyfritz@gmail.com"  -- The author of the game (string)
-  t.identity = nil  -- The name of the save directory (string)
-  t.version = 072  -- The LÖVE version this game was made for (number)
-  t.console = true  -- Attach a console (boolean, Windows only)
-  t.screen.width = 800  -- The window width (number)
-  t.screen.height = 600  -- The window height (number)
-  t.screen.fullscreen = false  -- Enable fullscreen (boolean)
-  t.screen.vsync = false  -- Enable vertical sync (boolean)
-  t.screen.fsaa = 0  -- The number of FSAA-buffers (number)
-  t.modules.joystick = true  -- Enable the joystick module (boolean)
-  t.modules.audio = true  -- Enable the audio module (boolean)
-  t.modules.keyboard = true  -- Enable the keyboard module (boolean)
-  t.modules.event = true  -- Enable the event module (boolean)
-  t.modules.image = true  -- Enable the image module (boolean)
-  t.modules.graphics = true  -- Enable the graphics module (boolean)
-  t.modules.timer = true  -- Enable the timer module (boolean)
-  t.modules.mouse = true  -- Enable the mouse module (boolean)
-  t.modules.sound = true  -- Enable the sound module (boolean)
-  t.modules.physics = false  -- Enable the physics module (boolean)
+  t.title = 'Splash'
+  t.author = 'Danny \'TechnoCat\' Fritz dannyfritz@gmail.com'
+  t.identity = nil
+  t.release = false
+  t.version = '0.8.0'
+  t.console = false
+  t.screen.width = 800
+  t.screen.height = 600
+  t.screen.fullscreen = false
+  t.screen.vsync = true
+  t.screen.fsaa = 0
+  t.modules.joystick = true
+  t.modules.audio = true
+  t.modules.keyboard = true
+  t.modules.event = true
+  t.modules.image = true
+  t.modules.graphics = true
+  t.modules.timer = true
+  t.modules.mouse = true
+  t.modules.sound = true
+  t.modules.physics = false 
 end

File lib/middleclass/MIT-LICENSE.txt

View file
+Copyright (c) 2011 Enrique García Cota
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

File lib/middleclass/init.lua

View file
+local _path = ({...})[1]:gsub("%.init", "")
+
+require( _path .. '.middleclass' )

File lib/middleclass/middleclass.lua

View file
+-- middleclass.lua - v2.0 (2011-09)
+-- Copyright (c) 2011 Enrique García Cota
+-- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+-- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+-- Based on YaciCode, from Julien Patte and LuaObject, from Sebastien Rocca-Serra
+
+local _classes = setmetatable({}, {__mode = "k"})
+
+local function _setClassDictionariesMetatables(klass)
+  local dict = klass.__instanceDict
+  dict.__index = dict
+
+  local super = klass.super
+  if super then
+    local superStatic = super.static
+    setmetatable(dict, super.__instanceDict)
+    setmetatable(klass.static, { __index = function(_,k) return dict[k] or superStatic[k] end })
+  else
+    setmetatable(klass.static, { __index = function(_,k) return dict[k] end })
+  end
+end
+
+local function _setClassMetatable(klass)
+  setmetatable(klass, {
+    __tostring = function() return "class " .. klass.name end,
+    __index    = klass.static,
+    __newindex = klass.__instanceDict,
+    __call     = function(self, ...) return self:new(...) end
+  })
+end
+
+local function _createClass(name, super)
+  local klass = { name = name, super = super, static = {}, __mixins = {}, __instanceDict={} }
+  klass.subclasses = setmetatable({}, {__mode = "k"})
+
+  _setClassDictionariesMetatables(klass)
+  _setClassMetatable(klass)
+  _classes[klass] = true
+
+  return klass
+end
+
+local function _createLookupMetamethod(klass, name)
+  return function(...)
+    local method = klass.super[name]
+    assert( type(method)=='function', tostring(klass) .. " doesn't implement metamethod '" .. name .. "'" )
+    return method(...)
+  end
+end
+
+local function _setClassMetamethods(klass)
+  for _,m in ipairs(klass.__metamethods) do
+    klass[m]= _createLookupMetamethod(klass, m)
+  end
+end
+
+local function _setDefaultInitializeMethod(klass, super)
+  klass.initialize = function(instance, ...)
+    return super.initialize(instance, ...)
+  end
+end
+
+local function _includeMixin(klass, mixin)
+  assert(type(mixin)=='table', "mixin must be a table")
+  for name,method in pairs(mixin) do
+    if name ~= "included" and name ~= "static" then klass[name] = method end
+  end
+  if mixin.static then
+    for name,method in pairs(mixin.static) do
+      klass.static[name] = method
+    end
+  end
+  if type(mixin.included)=="function" then mixin:included(klass) end
+  klass.__mixins[mixin] = true
+end
+
+Object = _createClass("Object", nil)
+
+Object.static.__metamethods = { '__add', '__call', '__concat', '__div', '__le', '__lt', 
+                                '__mod', '__mul', '__pow', '__sub', '__tostring', '__unm' }
+
+function Object.static:allocate()
+  assert(_classes[self], "Make sure that you are using 'Class:allocate' instead of 'Class.allocate'")
+  return setmetatable({ class = self }, self.__instanceDict)
+end
+
+function Object.static:new(...)
+  local instance = self:allocate()
+  instance:initialize(...)
+  return instance
+end
+
+function Object.static:subclass(name)
+  assert(_classes[self], "Make sure that you are using 'Class:subclass' instead of 'Class.subclass'")
+  assert(type(name) == "string", "You must provide a name(string) for your class")
+
+  local subclass = _createClass(name, self)
+  _setClassMetamethods(subclass)
+  _setDefaultInitializeMethod(subclass, self)
+  self.subclasses[subclass] = true
+  self:subclassed(subclass)
+
+  return subclass
+end
+
+function Object.static:subclassed(other) end
+
+function Object.static:include( ... )
+  assert(_classes[self], "Make sure you that you are using 'Class:include' instead of 'Class.include'")
+  for _,mixin in ipairs({...}) do _includeMixin(self, mixin) end
+  return self
+end
+
+function Object:initialize() end
+
+function Object:__tostring() return "instance of " .. tostring(self.class) end
+
+function class(name, super, ...)
+  super = super or Object
+  return super:subclass(name, ...)
+end
+
+function instanceOf(aClass, obj)
+  if not _classes[aClass] or type(obj) ~= 'table' or not _classes[obj.class] then return false end
+  if obj.class == aClass then return true end
+  return subclassOf(aClass, obj.class)
+end
+
+function subclassOf(other, aClass)
+  if not _classes[aClass] or not _classes[other] or aClass.super == nil then return false end
+  return aClass.super == other or subclassOf(other, aClass.super)
+end
+
+function includes(mixin, aClass)
+  if not _classes[aClass] then return false end
+  if aClass.__mixins[mixin] then return true end
+  return includes(mixin, aClass.super)
+end

File lib/middleclass/stateful/MIT-LICENSE.txt

View file
+Copyright (c) 2011 Enrique García Cota
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

File lib/middleclass/stateful/stateful.lua

View file
+local Stateful = { static = {} }
+
+local _callbacks = {
+  enteredState = 1,
+  exitedState = 1,
+  pushedState = 1,
+  poppedState = 1,
+  pausedState = 1,
+  continuedState = 1
+}
+
+local _BaseState = {}
+
+for callbackName,_ in pairs(_callbacks) do
+  _BaseState[callbackName] = function() end
+end
+
+local function _addStatesToClass(klass, superStates)
+  klass.static.states = {}
+  for stateName, state in pairs(superStates or {}) do
+    klass.static.states[stateName] = setmetatable({}, { __index = state })
+  end
+end
+
+local function _getStatefulMethod(instance, name)
+  if not _callbacks[name] then
+    local stack = rawget(instance, '__stateStack')
+    if not stack then return end
+    for i = #stack, 1, -1 do
+      if stack[i][name] then return stack[i][name] end
+    end
+  end
+end
+
+local function _getNewInstanceIndex(prevIndex)
+  if type(prevIndex) == 'function' then
+    return function(instance, name) return _getStatefulMethod(instance, name) or prevIndex(instance, name) end
+  end
+  return function(instance, name) return _getStatefulMethod(instance, name) or prevIndex[name] end
+end
+
+local function _getNewAllocateMethod(oldAllocateMethod)
+  return function(klass, ...)
+    local instance = oldAllocateMethod(klass, ...)
+    instance.__stateStack = {}
+    return instance
+  end
+end
+
+local function _modifyInstanceIndex(klass)
+  klass.__instanceDict.__index = _getNewInstanceIndex(klass.__instanceDict.__index)
+end
+
+local function _getNewSubclassMethod(prevSubclass)
+  return function(klass, name)
+    local subclass = prevSubclass(klass, name)
+    _addStatesToClass(subclass, klass.states)
+    _modifyInstanceIndex(subclass)
+    return subclass
+  end
+end
+
+local function _modifySubclassMethod(klass)
+  klass.static.subclass = _getNewSubclassMethod(klass.static.subclass)
+end
+
+local function _modifyAllocateMethod(klass)
+  klass.static.allocate = _getNewAllocateMethod(klass.static.allocate)
+end
+
+local function _assertType(val, name, expected_type, type_to_s)
+  assert(type(val) == expected_type, "Expected " .. name .. " to be of type " .. (type_to_s or expected_type) .. ". Was " .. tostring(val) .. "(" .. type(val) .. ")")
+end
+
+local function _assertInexistingState(klass, stateName)
+  assert(klass.states[stateName] == nil, "State " .. tostring(stateName) .. " already exists on " .. tostring(klass) )
+end
+
+local function _assertExistingState(self, state, stateName)
+  assert(state, "The state" .. stateName .. " was not found in class " .. tostring(self.class) )
+end
+
+local function _invokeCallback(self, state, callbackName)
+  if state then state[callbackName](self) end
+end
+
+local function _getCurrentState(self)
+  return self.__stateStack[#self.__stateStack]
+end
+
+local function _getStateFromClassByName(self, stateName)
+  local state = self.class.static.states[stateName]
+  _assertExistingState(self, state, stateName)
+  return state
+end
+local function _getStateIndexFromStackByName(self, stateName)
+  if stateName == nil then return #self.__stateStack end
+  local target = _getStateFromClassByName(self, stateName)
+  for i = #self.__stateStack, 1, -1 do
+    if self.__stateStack[i] == target then return i end
+  end
+  return 0
+end
+
+function Stateful:included(klass)
+  _addStatesToClass(klass)
+  _modifyInstanceIndex(klass)
+  _modifySubclassMethod(klass)
+  _modifyAllocateMethod(klass)
+end
+
+function Stateful.static:addState(stateName)
+  _assertType(stateName, 'stateName', 'string')
+  _assertInexistingState(self, stateName)
+  self.static.states[stateName] = setmetatable({}, { __index = _BaseState })
+  return self.static.states[stateName]
+end
+
+function Stateful:gotoState(stateName)
+
+  _invokeCallback(self, _getCurrentState(self), 'exitedState')
+
+  if stateName == nil then
+    self.__stateStack = { }
+  else
+    _assertType(stateName, 'stateName', 'string', 'string or nil')
+
+    local newState = _getStateFromClassByName(self, stateName)
+    _invokeCallback(self, newState, 'enteredState')
+    self.__stateStack = { newState }
+  end
+
+end
+
+function Stateful:pushState(stateName)
+  local oldState = _getCurrentState(self)
+  _invokeCallback(self, oldState, 'pausedState')
+  _invokeCallback(self, oldState, 'exitedState')
+
+  local newState = _getStateFromClassByName(self, stateName)
+  _invokeCallback(self, newState, 'pushedState')
+  _invokeCallback(self, newState, 'enteredState')
+  table.insert(self.__stateStack, newState)
+end
+
+function Stateful:popState(stateName)
+  local oldStateIndex = _getStateIndexFromStackByName(self, stateName)
+  local oldState = self.__stateStack[oldStateIndex]
+
+  _invokeCallback(self, oldState, 'poppedState')
+  _invokeCallback(self, oldState, 'exitedState')
+
+  table.remove(self.__stateStack, oldStateIndex)
+
+  local newState = _getCurrentState(self)
+
+  if oldState ~= newState then
+    _invokeCallback(self, newState, 'continuedState')
+  end
+end
+
+function Stateful:popAllStates()
+  self.__stateStack = {}
+end
+
+return Stateful

File lib/tween/LICENSE.txt

View file
+Copyright (c) 2011, Enrique García Cota
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification, 
+are permitted provided that the following conditions are met:
+
+  1. Redistributions of source code must retain the above copyright notice, 
+     this list of conditions and the following disclaimer.
+  2. Redistributions in binary form must reproduce the above copyright notice, 
+     this list of conditions and the following disclaimer in the documentation 
+     and/or other materials provided with the distribution.
+  3. Neither the name of tween.lua nor the names of its contributors 
+     may be used to endorse or promote products derived from this software 
+     without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+OF THE POSSIBILITY OF SUCH DAMAGE.
+
+=====================================================================================
+
+The easing functions were taken from emmanuelOga's easing functions
+(https://github.com/EmmanuelOga/easing).
+
+Here's its license:
+
+Tweener authors,
+Yuichi Tateno,
+Emmanuel Oga
+
+The MIT License
+--------
+Copyright (c) 2010, Emmanuel Oga.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+
+=====================================================================================
+
+Emmanuel Oga's functions, in turn, were adapted from Penner's Easing Equations 
+and http://code.google.com/p/tweener/ (jstweener javascript version)
+
+Disclaimer for Robert Penner's Easing Equations license:
+
+TERMS OF USE - EASING EQUATIONS
+
+Open source under the BSD License.
+
+Copyright © 2001 Robert Penner
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+    * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+    * Neither the name of the author nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+

File lib/tween/README.textile

View file
+h1. tween.lua
+
+Small sets of functions for performing tweening in Lua. Based on "jQuery's animate function":http://api.jquery.com/animate/
+
+h1. Examples
+
+<pre>
+local tween = require 'tween'
+
+-- increase the volume of music from 0 to 5 in 10 seconds
+local music = { volume = 0, path = "path/to/file.mp3" }
+tween(10, music, { volume = 5 })
+
+-- make some text fall from the top of the screen, bouncing on y=300, in 4 seconds
+local label = { x=200, y=0, text = "hello" }
+tween(4, label, { y=300 }, 'outBounce')
+
+-- fade background to black in 2 seconds, and then print a message on the terminal
+local backgroundColor = {255,255,255}
+tween(2, backgroundColor, {0,0,0}, 'linear', print, "hello!")
+</pre>
+
+You will need to put @tween.update@ somewhere in your game loop update function:
+
+<pre>
+
+function your_game_loop_update(dt)
+  ...
+  tween.update(dt)
+  ...
+end
+</pre>
+
+h1. Interface
+
+* @tween.start(time, subject, target, [easing], [callback], ...)@. By default it Returns an identifier (@id@)
+** @time@ will specify how much time must the change will take.
+** @subject@ and @target@ must both be tables. @tween.start@ will gradually alter @subject@'s properties until they look like in @target@. Properties not mentioned in @target@ will be ignored.
+** @easing@ can be either a function or a function name (see the easing section below). It's default value is @'linear'@
+** @callback@ is a function to be called when the tween is over. Only callable objects such as functions are acceptable here. Can be nil.
+** Any other parameters are passed to the @callback@ as additional parameters.
+* @tween(time, subject, target, [easing], [callback])@ redirect to @tween.start@
+* @tween.stop([id])@ stops the animation identified by @id@. It does *not* reset the animation to its initial state.
+* @tween.stopAll()@ stops all animations, without resetting any values
+* @tween.reset(id)@ stops the animation identified by @id@, and resets its @subject@ to the initial values it had at the start of the animation.
+* @tween.resetAll()@ resetd all currently playing animations to their initial state.
+* @tween.update(dt)@ is needed to be executed on the main program loop. @dt@ is the amount of time that has passed since the last iteration. When @tween.update@ is executed, the values of very @subject@ are slightly modified so they resemble a bit more their @target@s. It is also the time in which the callbacks are invoked, if they exist.
+
+h1. Gotchas / Warnings
+
+* @tween@ does *not* implement any hardware or software clock; you will have to provide it with the access to the hardware timers, in the form of periodic calls to @cron.update@
+* @tween@ does not have any defined time units (seconds, milliseconds, etc). You define the units it uses by passing it a @dt@ on @tween.update@. If @dt@ is in seconds, then @tween@ will work in seconds. If @dt@ is in milliseconds, then @tween@ will work in milliseconds.
+* @tween@ can work on deeply-nested subtables (the "leaf" values have to be numbers in both the subject and the target)
+
+<pre>
+local trafficLight = { color1 = {255,0,0}, color2 = {0,0,0}, color3 = {0,0,0} }
+tween(3, trafficLight, { color1 = {0,0,0}, color2 = {255,255,0}, color3 = {0,0,0} }, 'linear', function()
+  tween(1, trafficLight, { color1 = {0,0,0}, color2 = {0,0,0}, color3 = {0,255,0} }
+end)
+for i=1, 4 do
+  tween.update(1) -- In 3 iterations the lights will change from red to yellow. The last iteration will change them to green
+end
+</pre>
+
+h1. Installation
+
+Just copy the tween.lua file somewhere in your projects (maybe inside a /lib/ folder) and require it accordingly.
+
+Remember to store the value returned by require somewhere! (I suggest a local variable named tween)
+
+<pre>
+local tween = require 'tween'
+</pre>
+
+The second step is making sure that your "game loop" calls @tween.update@ with a proper @dt@. Where to put this call depends greatly on your game loop architecture. It will probably go into an "update" function:
+
+<pre>
+function update(dt)
+  ...
+  tween.update(dt)
+end
+</pre>
+
+Also, make sure to read the license file; the text of that license file must appear somewhere in your projects' files.
+
+h1. Easing functions
+
+Easing functions are functions that express how slow/fast the interpolation happens in tween.
+
+tween.lua comes with a lot of easing functions already built-in (adapted from "Emmanuel Oga's easing library":https://github.com/EmmanuelOga/easing
+
+They can be divided into several big families:
+
+* @linear@ is the default interpolation. It's the simplest easing function.
+* @quad@, @cubic@, @quart@, @quint@, @expo@, @sine@ and @circle@ are all "smooth" curves that will make transitions look natural.
+* The @back@ family starts by moving the interpolation slightly "backwards" before moving it forward.
+* The @bounce@ family simulates the motion of an object bouncing.
+* The @elastic@ family simulates inertia in the easing, like an elastic gum.
+
+Each family (except @linear@ has 4 variants):
+* @in@ starts slow, and accelerates at the end
+* @out@ starts fast, and decelerates at the end
+* @inOut@ starts and ends slow, but it's fast in the middle
+* @outIn@ starts and ends fast, but it's slow in the middle
+
+|_. family |_. in    |_. out     |_. inOut    |_. outIn    |
+|_. linear |linear   |linear     |linear      |linear      |
+|_. quad   |inQuad   |outQuad    |inOutQuad   |outInQuad   |
+|_. cubic  |inCubic  |outCubic   |inOutCubic  |outInCubic  |
+|_. quart  |inQuart  |outQuart   |inOutQuart  |outInQuart  |
+|_. quint  |inQuint  |outQuint   |inOutQuint  |outInQuint  |
+|_. expo   |inExpo   |outExpo    |inOutExpo   |outInExpo   |
+|_. sine   |inSine   |outSine    |inOutSine   |outInSine   |
+|_. circle |inCircle |outCircle  |inOutCircle |outInCircle |
+|_. back   |inBack   |outBack    |inOutBack   |outInBack   |
+|_. bounce |inBounce |outBounce  |inOutBounce |outInBounce |
+|_. elastic|inElastic|outElastic |inOutElastic|outInElascit|
+
+You may want to give a look to the graphs folder on this repository to get a better idea of what I'm talking about.
+
+When you specify an easing fucntion, you can either give the function name as a string. The following two are equivalent:
+
+<pre>
+tween(10, subject, {x=10}, tween.easing.linear)
+tween(10, subject, {x=10}, 'linear')
+</pre>
+
+Well, actually, since 'linear' is the default, you can also do this:
+<pre>
+tween(10, subject, {x=10})
+</pre>
+
+You can of course specify your own easing function. Just make sure you respect the parameter format.
+
+
+h1. Specs
+
+This project uses "telescope":https://github.com/norman/telescope for its specs. If you want to run the specs, you will have to install telescope first. Then just enter the spec folder and execute run.lua:
+
+<pre>
+cd path/to/tween.lua/specs
+lua run.lua
+</pre>
+
+h1. Credits
+
+The easing functions have been copied from EmmanuelOga's project in
+
+https://github.com/emmanueloga/easing
+
+See the LICENSE.txt file for details.
+

File lib/tween/tween.lua

View file
+-----------------------------------------------------------------------------------------------------------------------
+-- tween.lua - v1.0 (2011-05)
+-- Enrique García Cota - enrique.garcia.cota [AT] gmail [DOT] com
+-- tweening functions for lua
+-- inspired by jquery's animate function
+-----------------------------------------------------------------------------------------------------------------------
+local tween = {}
+
+-- private stuff
+
+local tweens = setmetatable({}, {__mode = "k"})
+
+local function isCallable(f)
+  local tf = type(f)
+  if tf == 'function' then return true end
+  if tf == 'table' then
+    local mt = getmetatable(f)
+    return (type(mt) == 'table' and type(mt.__call) == 'function')
+  end
+  return false
+end
+
+local function copyTables(destination, keysTable, valuesTable)
+  valuesTable = valuesTable or keysTable
+  for k,v in pairs(keysTable) do
+    if type(v) == 'table' then
+      destination[k] = copyTables({}, v, valuesTable[k])
+    else
+      destination[k] = valuesTable[k]
+    end
+  end
+  return destination
+end
+
+local function checkSubjectAndTargetRecursively(subject, target, path)
+  path = path or {}
+  local targetType, newPath
+  for k,targetValue in pairs(target) do
+    targetType, newPath = type(targetValue), copyTables({}, path)
+    table.insert(newPath, tostring(k))
+    if targetType == 'number' then
+      assert(type(subject[k]) == 'number', "Parameter '" .. table.concat(newPath,'/') .. "' is missing from subject or isn't a number")
+    elseif targetType == 'table' then
+      checkSubjectAndTargetRecursively(subject[k], targetValue, newPath)
+    else
+      assert(targetType == 'number', "Parameter '" .. table.concat(newPath,'/') .. "' must be a number or table of numbers")
+    end
+  end
+end
+
+local function checkStartParams(time, subject, target, easing, callback)
+  assert(type(time) == 'number' and time > 0, "time must be a positive number. Was " .. tostring(time))
+  assert(type(subject) == 'table', "subject must be a table. Was " .. tostring(subject))
+  assert(type(target)== 'table', "target must be a table. Was " .. tostring(target))
+  assert(isCallable(easing), "easing must be a function or functable. Was " .. tostring(easing))
+  assert(callback==nil or isCallable(callback), "callback must be nil, a function or functable. Was " .. tostring(time))
+  checkSubjectAndTargetRecursively(subject, target)
+
+end
+
+local function getEasingFunction(easing)
+  easing = easing or "linear"
+  if type(easing) == 'string' then
+    local name = easing
+    easing = tween.easing[name]
+    assert(type(easing) == 'function', "The easing function name '" .. name .. "' is invalid")
+  end
+  return easing
+end
+
+local function newTween(time, subject, target, easing, callback, args)
+  local self = {
+    time = time,
+    subject = subject,
+    target = target,
+    easing = easing,
+    callback = callback,
+    args = args,
+    initial = copyTables({}, target, subject),
+    running = 0
+  }
+  tweens[self] = self
+  return self
+end
+
+local function easeWithTween(self, subject, target, initial)
+  local t,b,c,d
+  for k,v in pairs(target) do
+    if type(v)=='table' then
+      easeWithTween(self, subject[k], v, initial[k])
+    else
+      t,b,c,d = self.running, initial[k], v - initial[k], self.time
+      subject[k] = self.easing(t,b,c,d)
+    end
+  end
+end
+
+local function updateTween(self, dt)
+  self.running = self.running + dt
+  easeWithTween(self, self.subject, self.target, self.initial)
+end
+
+local function hasExpiredTween(self)
+  return self.running >= self.time
+end
+
+local function finishTween(self)
+  copyTables(self.subject, self.target)
+  if self.callback then self.callback(unpack(self.args)) end
+  tween.stop(self)
+end
+
+local function resetTween(self)
+  copyTables(self.subject, self.initial)
+end
+
+-- easing
+
+-- Adapted from https://github.com/EmmanuelOga/easing. See LICENSE.txt for credits.
+-- For all easing functions:
+-- t = time == how much time has to pass for the tweening to complete
+-- b = begin == starting property value
+-- c = change == ending - beginning
+-- d = duration == running time. How much time has passed *right now*
+
+local pow, sin, cos, pi, sqrt, abs, asin = math.pow, math.sin, math.cos, math.pi, math.sqrt, math.abs, math.asin
+
+-- linear
+local function linear(t, b, c, d) return c * t / d + b end
+
+-- quad
+local function inQuad(t, b, c, d) return c * pow(t / d, 2) + b end
+local function outQuad(t, b, c, d)
+  t = t / d
+  return -c * t * (t - 2) + b
+end
+local function inOutQuad(t, b, c, d)
+  t = t / d * 2
+  if t < 1 then return c / 2 * pow(t, 2) + b end
+  return -c / 2 * ((t - 1) * (t - 3) - 1) + b
+end
+local function outInQuad(t, b, c, d)
+  if t < d / 2 then return outQuad(t * 2, b, c / 2, d) end
+  return inQuad((t * 2) - d, b + c / 2, c / 2, d)
+end
+
+-- cubic
+local function inCubic (t, b, c, d) return c * pow(t / d, 3) + b end
+local function outCubic(t, b, c, d) return c * (pow(t / d - 1, 3) + 1) + b end
+local function inOutCubic(t, b, c, d)
+  t = t / d * 2
+  if t < 1 then return c / 2 * t * t * t + b end
+  t = t - 2
+  return c / 2 * (t * t * t + 2) + b
+end
+local function outInCubic(t, b, c, d)
+  if t < d / 2 then return outCubic(t * 2, b, c / 2, d) end
+  return inCubic((t * 2) - d, b + c / 2, c / 2, d)
+end
+
+-- quart
+local function inQuart(t, b, c, d) return c * pow(t / d, 4) + b end
+local function outQuart(t, b, c, d) return -c * (pow(t / d - 1, 4) - 1) + b end
+local function inOutQuart(t, b, c, d)
+  t = t / d * 2
+  if t < 1 then return c / 2 * pow(t, 4) + b end
+  return -c / 2 * (pow(t - 2, 4) - 2) + b
+end
+local function outInQuart(t, b, c, d)
+  if t < d / 2 then return outQuart(t * 2, b, c / 2, d) end
+  return inQuart((t * 2) - d, b + c / 2, c / 2, d)
+end
+
+-- quint
+local function inQuint(t, b, c, d) return c * pow(t / d, 5) + b end
+local function outQuint(t, b, c, d) return c * (pow(t / d - 1, 5) + 1) + b end
+local function inOutQuint(t, b, c, d)
+  t = t / d * 2
+  if t < 1 then return c / 2 * pow(t, 5) + b end
+  return c / 2 * (pow(t - 2, 5) + 2) + b
+end
+local function outInQuint(t, b, c, d)
+  if t < d / 2 then return outQuint(t * 2, b, c / 2, d) end
+  return inQuint((t * 2) - d, b + c / 2, c / 2, d)
+end
+
+-- sine
+local function inSine(t, b, c, d) return -c * cos(t / d * (pi / 2)) + c + b end
+local function outSine(t, b, c, d) return c * sin(t / d * (pi / 2)) + b end
+local function inOutSine(t, b, c, d) return -c / 2 * (cos(pi * t / d) - 1) + b end
+local function outInSine(t, b, c, d)
+  if t < d / 2 then return outSine(t * 2, b, c / 2, d) end
+  return inSine((t * 2) -d, b + c / 2, c / 2, d)
+end
+
+-- expo
+local function inExpo(t, b, c, d)
+  if t == 0 then return b end
+  return c * pow(2, 10 * (t / d - 1)) + b - c * 0.001
+end
+local function outExpo(t, b, c, d)
+  if t == d then return b + c end
+  return c * 1.001 * (-pow(2, -10 * t / d) + 1) + b
+end
+local function inOutExpo(t, b, c, d)
+  if t == 0 then return b end
+  if t == d then return b + c end
+  t = t / d * 2
+  if t < 1 then return c / 2 * pow(2, 10 * (t - 1)) + b - c * 0.0005 end
+  return c / 2 * 1.0005 * (-pow(2, -10 * (t - 1)) + 2) + b
+end
+local function outInExpo(t, b, c, d)
+  if t < d / 2 then return outExpo(t * 2, b, c / 2, d) end
+  return inExpo((t * 2) - d, b + c / 2, c / 2, d)
+end
+
+-- circ
+local function inCirc(t, b, c, d) return(-c * (sqrt(1 - pow(t / d, 2)) - 1) + b) end
+local function outCirc(t, b, c, d)  return(c * sqrt(1 - pow(t / d - 1, 2)) + b) end
+local function inOutCirc(t, b, c, d)
+  t = t / d * 2
+  if t < 1 then return -c / 2 * (sqrt(1 - t * t) - 1) + b end
+  t = t - 2
+  return c / 2 * (sqrt(1 - t * t) + 1) + b
+end
+local function outInCirc(t, b, c, d)
+  if t < d / 2 then return outCirc(t * 2, b, c / 2, d) end
+  return inCirc((t * 2) - d, b + c / 2, c / 2, d)
+end
+
+-- elastic
+local function calculatePAS(p,a,c,d)
+  p, a = p or d * 0.3, a or 0
+  if a < abs(c) then return p, c, p / 4 end -- p, a, s
+  return p, a, p / (2 * pi) * asin(c/a) -- p,a,s
+end
+local function inElastic(t, b, c, d, a, p)
+  local s
+  if t == 0 then return b end
+  t = t / d
+  if t == 1  then return b + c end
+  p,a,s = calculatePAS(p,a,c,d)
+  t = t - 1
+  return -(a * pow(2, 10 * t) * sin((t * d - s) * (2 * pi) / p)) + b
+end
+local function outElastic(t, b, c, d, a, p)
+  local s
+  if t == 0 then return b end
+  t = t / d
+  if t == 1 then return b + c end
+  p,a,s = calculatePAS(p,a,c,d)
+  return a * pow(2, -10 * t) * sin((t * d - s) * (2 * pi) / p) + c + b
+end
+local function inOutElastic(t, b, c, d, a, p)
+  local s
+  if t == 0 then return b end
+  t = t / d * 2
+  if t == 2 then return b + c end
+  p,a,s = calculatePAS(p,a,c,d)
+  t = t - 1
+  if t < 0 then return -0.5 * (a * pow(2, 10 * t) * sin((t * d - s) * (2 * pi) / p)) + b end
+  return a * pow(2, -10 * t) * sin((t * d - s) * (2 * pi) / p ) * 0.5 + c + b
+end
+local function outInElastic(t, b, c, d, a, p)
+  if t < d / 2 then return outElastic(t * 2, b, c / 2, d, a, p) end
+  return inElastic((t * 2) - d, b + c / 2, c / 2, d, a, p)
+end
+
+-- back
+local function inBack(t, b, c, d, s)
+  s = s or 1.70158
+  t = t / d
+  return c * t * t * ((s + 1) * t - s) + b
+end
+local function outBack(t, b, c, d, s)
+  s = s or 1.70158
+  t = t / d - 1
+  return c * (t * t * ((s + 1) * t + s) + 1) + b
+end
+local function inOutBack(t, b, c, d, s)
+  s = (s or 1.70158) * 1.525
+  t = t / d * 2
+  if t < 1 then return c / 2 * (t * t * ((s + 1) * t - s)) + b end
+  t = t - 2
+  return c / 2 * (t * t * ((s + 1) * t + s) + 2) + b
+end
+local function outInBack(t, b, c, d, s)
+  if t < d / 2 then return outBack(t * 2, b, c / 2, d, s) end
+  return inBack((t * 2) - d, b + c / 2, c / 2, d, s)
+end
+
+-- bounce
+local function outBounce(t, b, c, d)
+  t = t / d
+  if t < 1 / 2.75 then return c * (7.5625 * t * t) + b end
+  if t < 2 / 2.75 then
+    t = t - (1.5 / 2.75)
+    return c * (7.5625 * t * t + 0.75) + b
+  elseif t < 2.5 / 2.75 then
+    t = t - (2.25 / 2.75)
+    return c * (7.5625 * t * t + 0.9375) + b
+  end
+  t = t - (2.625 / 2.75)
+  return c * (7.5625 * t * t + 0.984375) + b
+end
+local function inBounce(t, b, c, d) return c - outBounce(d - t, 0, c, d) + b end
+local function inOutBounce(t, b, c, d)
+  if t < d / 2 then return inBounce(t * 2, 0, c, d) * 0.5 + b end
+  return outBounce(t * 2 - d, 0, c, d) * 0.5 + c * .5 + b
+end
+local function outInBounce(t, b, c, d)
+  if t < d / 2 then return outBounce(t * 2, b, c / 2, d) end
+  return inBounce((t * 2) - d, b + c / 2, c / 2, d)
+end
+
+tween.easing = {
+  linear = linear,
+  inQuad    = inQuad,    outQuad    = outQuad,    inOutQuad    = inOutQuad,    outInQuad    = outInQuad,
+  inCubic   = inCubic,   outCubic   = outCubic,   inOutCubic   = inOutCubic,   outInCubic   = outInCubic,
+  inQuart   = inQuart,   outQuart   = outQuart,   inOutQuart   = inOutQuart,   outInQuart   = outInQuart,
+  inQuint   = inQuint,   outQuint   = outQuint,   inOutQuint   = inOutQuint,   outInQuint   = outInQuint,
+  inSine    = inSine,    outSine    = outSine,    inOutSine    = inOutSine,    outInSine    = outInSine,
+  inExpo    = inExpo,    outExpo    = outExpo,    inOutExpo    = inOutExpo,    outInExpo    = outInExpo,
+  inCirc    = inCirc,    outCirc    = outCirc,    inOutCirc    = inOutCirc,    outInCirc    = outInCirc,
+  inElastic = inElastic, outElastic = outElastic, inOutElastic = inOutElastic, outInElastic = outInElastic,
+  inBack    = inBack,    outBack    = outBack,    inOutBack    = inOutBack,    outInBack    = outInBack,
+  inBounce  = inBounce,  outBounce  = outBounce,  inOutBounce  = inOutBounce,  outInBounce  = outInBounce,
+}
+
+
+-- public functions
+
+function tween.start(time, subject, target, easing, callback, ...)
+  easing = getEasingFunction(easing)
+  checkStartParams(time, subject, target, easing, callback)
+  return newTween(time, subject, target, easing, callback, {...})
+end
+
+setmetatable(tween, { __call = function(t, ...) return tween.start(...) end })
+
+function tween.reset(id)
+  local tw = tweens[id]
+  if tw then
+    resetTween(tw)
+    tween.stop(tw)
+  end
+end
+
+function tween.resetAll(id)
+  for _,tw in pairs(tweens) do copyTables(tw.subject, tw.initial) end
+  tween.stopAll()
+end
+
+function tween.stop(id)
+  if id~=nil then tweens[id]=nil end
+end
+
+function tween.stopAll()
+  tweens = setmetatable({}, {__mode = "k"})
+end
+
+function tween.update(dt)
+  assert(type(dt) == 'number' and dt > 0, "dt must be a positive number")
+  local expired = {}
+  for _,t in pairs(tweens) do
+    updateTween(t, dt)
+    if hasExpiredTween(t) then table.insert(expired, t) end
+  end
+  for i=1, #expired do finishTween(expired[i]) end
+end
+
+
+
+return tween
+

File lua/Gamestate.lua

View file
+--[[----------------------------------------------------------------------------
+Copyright (c) 2011, Danny Fritz <dannyfritz@gmail.com>
+http://creativecommons.org/licenses/by/3.0/
+Licensed under the Creative Commons Attribution 3.0 Unported License.
+--]]----------------------------------------------------------------------------
+
+Gamestate = class('Gamestate'):include(Stateful)
+
+--------------------------------------------------------------------------------
+function Gamestate:initialize()
+end
+
+--------------------------------------------------------------------------------
+function Gamestate:update(dt)
+end
+
+--------------------------------------------------------------------------------
+function Gamestate:draw()
+end
+
+--------------------------------------------------------------------------------
+function Gamestate:focus(f)
+end
+
+--------------------------------------------------------------------------------
+function Gamestate:joystickpressed(joystick, button)
+end
+
+--------------------------------------------------------------------------------
+function Gamestate:joystickreleased(joystick, button)
+end
+
+--------------------------------------------------------------------------------
+function Gamestate:keypressed(key, unicode)
+end
+
+--------------------------------------------------------------------------------
+function Gamestate:keyreleased(key)
+end
+
+--------------------------------------------------------------------------------
+function Gamestate:mousepressed(x, y, button)
+end
+
+--------------------------------------------------------------------------------
+function Gamestate:mousereleased(x, y, button)
+end
+
+--------------------------------------------------------------------------------
+function Gamestate:quit()
+end

File lua/Menu.lua

View file
+--[[----------------------------------------------------------------------------
+Copyright (c) 2011, Danny Fritz <dannyfritz@gmail.com>
+http://creativecommons.org/licenses/by/3.0/
+Licensed under the Creative Commons Attribution 3.0 Unported License.
+--]]----------------------------------------------------------------------------
+
+local Menu = Gamestate:addState('Menu')
+
+
+--------------------------------------------------------------------------------
+function Menu:enteredState()
+	love.event.push('q')
+end
+
+--------------------------------------------------------------------------------
+function Menu:exitedState()
+end

File lua/Splash.lua

View file
+--[[----------------------------------------------------------------------------
+Copyright (c) 2011, Danny Fritz <dannyfritz@gmail.com>
+http://creativecommons.org/licenses/by/3.0/
+Licensed under the Creative Commons Attribution 3.0 Unported License.
+--]]----------------------------------------------------------------------------
+
+local Tween = require 'lib.tween.tween'
+
+
+local Splash = Gamestate:addState('Splash')
+
+local NEXTSTATE = 'Menu'
+local WIDTH = 800
+local HEIGHT = 600
+
+local leaf
+local face
+local text
+local pixel_effect
+local old_background_color
+
+--------------------------------------------------------------------------------
+function Splash:enteredState()
+	old_background_color = love.graphics.getBackgroundColor()
+	print("background color")
+	love.graphics.setBackgroundColor(254, 153, 0)
+	local leaf_image = love.graphics.newImage('leaf.png')
+	leaf = Object:new(leaf_image)
+end
+
+--------------------------------------------------------------------------------
+function Splash:exitedState()
+	love.graphics.setBackgroundColor(old_background_color)
+end
+
+--------------------------------------------------------------------------------
+function Splash:update(dt)
+
+end
+
+--------------------------------------------------------------------------------
+function Splash:draw()
+	leaf:draw()
+end
+
+--------------------------------------------------------------------------------
+function Splash:keypressed(key, unicode)
+	if key == ' ' or key == 'enter' or key == 'kpenter' or key == 'escape' then
+		gamestate:gotoState(NEXTSTATE)
+	end
+end
+
+--------------------------------------------------------------------------------
+function Splash:mousepressed(x, y, button)
+	gamestate:gotoState(NEXTSTATE)
+	--Let the player press things for animations!
+end
+
+--------------------------------------------------------------------------------
+function Splash:joystickpressed(joystick, button)
+	gamestate:gotoState(NEXTSTATE)
+end

File main.lua

View file
+--[[----------------------------------------------------------------------------
+Copyright (c) 2011, Danny Fritz <dannyfritz@gmail.com>
+http://creativecommons.org/licenses/by/3.0/
+Licensed under the Creative Commons Attribution 3.0 Unported License.
+--]]----------------------------------------------------------------------------
 
+require 'lib.middleclass'
+Stateful = require 'lib.middleclass.stateful.stateful'
+
+require 'lua.Gamestate'
+require 'splash.Splash'
+require 'lua.Menu'
+
+
+--------------------------------------------------------------------------------
 function love.load()
-  
+	gamestate = Gamestate:new()
+	gamestate:gotoState('Splash')
 end
 
+--------------------------------------------------------------------------------
 function love.update(dt)
-  
+	gamestate:update(dt)
 end
 
+--------------------------------------------------------------------------------
 function love.draw()
-  
+	gamestate:draw()
 end
+
+--------------------------------------------------------------------------------
+function love.focus(f)
+	gamestate:focus(f)
+end
+
+--------------------------------------------------------------------------------
+function love.joystickpressed(joystick, button)
+	gamestate:joystickpressed(joystick, button)
+end
+
+--------------------------------------------------------------------------------
+function love.joystickreleased(joystick, button)
+	gamestate:joystickreleased(joystick, button)
+end
+
+--------------------------------------------------------------------------------
+function love.keypressed(key, unicode)
+	gamestate:keypressed(key, unicode)
+end
+
+--------------------------------------------------------------------------------
+function love.keyreleased(key)
+	gamestate:keyreleased(key)
+end
+
+--------------------------------------------------------------------------------
+function love.mousepressed(x, y, button)
+	gamestate:mousepressed(x, y, button)
+end
+
+--------------------------------------------------------------------------------
+function love.mousereleased(x, y, button)
+	gamestate:mousereleased(x, y, button)
+end
+
+--------------------------------------------------------------------------------
+function love.quit()
+	gamestate:quit()
+end

File splash/Object.lua

View file
+--[[----------------------------------------------------------------------------
+Copyright (c) 2011, Danny Fritz <dannyfritz@gmail.com>
+http://creativecommons.org/licenses/by/3.0/
+Licensed under the Creative Commons Attribution 3.0 Unported License.
+--]]----------------------------------------------------------------------------
+
+local Object = class('Object')
+
+--------------------------------------------------------------------------------
+function Object:initialize(image, attributes)
+	local attributes = attributes or {}
+	self.image = image
+	self.x = attributes.x or 0
+	self.y = attributes.y or 0
+	self.angle = attributes.angle or 0
+	self.scale_x = attributes.scale_x or 1
+	self.scale_y = attributes.scale_y or 1
+	self.offset_x = attributes.offset_x or 0
+	self.offset_y = attributes.offset_y or 0
+	self.alpha = attributes.alpha or 255
+end
+
+--------------------------------------------------------------------------------
+function Object:draw()
+	love.graphics.setColor(255,255,255,self.alpha)
+	love.graphics.draw(self.image, self.x, self.y,
+			self.angle, self.scale_x, self.scale_y,
+			self.offset_x, self.offset_y)
+	love.graphics.setColor(255,255,255,255)
+end
+
+return Object

File splash/Splash.lua

View file
+--[[----------------------------------------------------------------------------
+Copyright (c) 2011, Danny Fritz <dannyfritz@gmail.com>
+http://creativecommons.org/licenses/by/3.0/
+Licensed under the Creative Commons Attribution 3.0 Unported License.
+--]]----------------------------------------------------------------------------
+
+local Splash = Gamestate:addState('Splash')
+
+local Tween = require 'lib.tween.tween'
+local Object = require 'splash.Object'
+
+local NEXTSTATE = 'Menu'
+local WIDTH = 800
+local HEIGHT = 600
+
+local leaf
+local face
+local text
+local pixel_effect
+local old_background_color
+local music
+
+--------------------------------------------------------------------------------
+function Splash:enteredState()
+	old_background_color = {love.graphics.getBackgroundColor()}
+	love.graphics.setBackgroundColor(254, 153, 0)
+
+	music = love.audio.newSource('splash/music.ogg')
+	music:play()
+
+	local leaf_image = love.graphics.newImage('splash/leaf.png')
+	leaf = Object:new(leaf_image, {x=800, y=-120})
+	Tween(5, leaf, {x=100}, 'inOutSine',
+			Tween, 4, leaf, {x=520}, 'inOutSine')
+	Tween(5, leaf, {y=-40}, 'outInSine',
+			Tween, 4, leaf, {y=10}, 'outInSine')
+	Tween(5, leaf, {angle=-0.5}, 'inOutSine',
+			Tween, 4, leaf, {angle=0}, 'inOutSine')
+
+	local face_image = love.graphics.newImage('splash/face.png')
+	face = Object:new(face_image,
+			{x=390, y=300, scale_x=0.75, scale_y=0.75, alpha=0, offset_x=159, offset_y=175})
+	Tween(7.5, face, {}, 'linear',
+			Tween, 1.5, face, {scale_x=1, scale_y=1}, 'linear')
+	Tween(8, face, {}, 'linear',
+			Tween, 1.5, face, {alpha=255}, 'linear')
+
+	local text_image = love.graphics.newImage('splash/TechnoCat.png')
+	text = Object:new(text_image, {x=90, y=490, alpha=0})
+	Tween(8, text, {}, 'linear',
+			Tween, 1, text, {alpha=255}, 'linear')
+	
+	Tween(12, leaf, {}, 'linear',
+			Tween, 2, leaf, {alpha=0}, 'linear',
+			gamestate.gotoState, gamestate, NEXTSTATE)
+	
+	Tween(12, face, {}, 'linear',
+			Tween, 2, face, {alpha=0}, 'linear')
+	
+	Tween(12, text, {}, 'linear',
+			Tween, 2, text, {alpha=0}, 'linear')
+	
+end
+
+--------------------------------------------------------------------------------
+function Splash:exitedState()
+	love.graphics.setBackgroundColor(unpack(old_background_color))
+end
+
+--------------------------------------------------------------------------------
+function Splash:update(dt)
+	Tween.update(dt)
+end
+
+--------------------------------------------------------------------------------
+function Splash:draw()
+	leaf:draw()
+	face:draw()
+	text:draw()
+end
+
+--------------------------------------------------------------------------------
+function Splash:keypressed(key, unicode)
+	if key == ' ' or key == 'return' or key == 'kpenter' or key == 'escape' then
+		gamestate:gotoState(NEXTSTATE)
+	end
+end
+
+--------------------------------------------------------------------------------
+function Splash:mousepressed(x, y, button)
+	gamestate:gotoState(NEXTSTATE)
+	--Let the player press things for animations!
+end
+
+--------------------------------------------------------------------------------
+function Splash:joystickpressed(joystick, button)
+	gamestate:gotoState(NEXTSTATE)
+end

File splash/TechnoCat.png

Added
New image

File splash/face.png

Added
New image

File splash/leaf.png

Added
New image

File splash/music.ogg

Binary file added.

File splash/splash.glsl

Empty file added.

File splash/splash.png

Added
New image

File splash/splash.psd

Added
New image