Skip to content
Browse files

Sound resource fix, transition submodule, game stack removed

  • Loading branch information...
1 parent 5901555 commit 94048bdb034d2a986b168cc08d9a028df97b4cb0 @opatut opatut committed Aug 5, 2012
View
3 .gitmodules
@@ -4,3 +4,6 @@
[submodule "BGJ02/src/externals/HardonCollider"]
path = BGJ02/src/externals/HardonCollider
url = git://github.com/vrld/HardonCollider.git
+[submodule "BGJ02/src/externals/tween"]
+ path = BGJ02/src/externals/tween
+ url = https://github.com/kikito/tween.lua
View
2 BGJ02/Makefile
@@ -6,7 +6,7 @@ clean:
build:
@zip -0r game.love data/
- @cd src/ && zip -0r ../game.love *
+ @cd src/ && find . -iname '*.lua' | xargs zip -0r ../game.love
run:
@love game.love
View
BIN BGJ02/data/sound/swipe.ogg
Binary file not shown.
View
BIN BGJ02/data/sound/swipe.sfs
Binary file not shown.
1 BGJ02/src/externals/tween
@@ -0,0 +1 @@
+Subproject commit 7cc356bc808674b226936ae58009bdaba63c0120
View
6 BGJ02/src/game.lua
@@ -122,7 +122,11 @@ end
function Game:keypressed(k, u)
if k == "escape" then
- stack:pop()
+ if debug then
+ currentState = nil
+ else
+ currentState = menu
+ end
elseif k == "1" then
self.selectedAsteroid = 1
elseif k == "2" then
View
3 BGJ02/src/intro.lua
@@ -33,8 +33,7 @@ function Intro:draw()
end
function Intro:skip()
- stack:pop()
- stack:push(menu)
+ currentState = menu
end
function Intro:keypressed(k, u)
View
28 BGJ02/src/main.lua
@@ -1,22 +1,21 @@
require("game")
require("intro")
require("menu")
-require("util/gamestack")
require("util/resources")
resources = Resources("data/")
+currentState = nil
function reset()
-- start game
intro = Intro()
menu = Menu()
game = Game()
- stack = GameStack()
if debug then
- stack:push(game)
+ currentState = game
else
- stack:push(intro)
+ currentState = intro
end
end
@@ -33,8 +32,8 @@ function love.load()
resources:addFont("normal", "DejaVuSans.ttf", 20)
resources:addFont("huge", "DejaVuSans.ttf", 30)
- -- load music
- -- resources:addMusic("background", "background.mp3")
+ -- load music / sounds
+ resources:addAudio("swipe", "sound/swipe.ogg", false) -- no stream
-- load shaders
resources:addShader("pixelate", "shader/pixelate.glsl")
@@ -45,27 +44,28 @@ function love.load()
end
function love.update(dt)
- stack:update(dt)
+ if currentState then
+ currentState:update(dt)
+ else
+ love.event.quit()
+ end
end
function love.draw()
- stack:draw()
+ if currentState then currentState:draw() end
-- love.graphics.setFont(resources.fonts.tiny)
-- love.graphics.print("FPS: " .. love.timer.getFPS(), 5, 5)
end
function love.keypressed(k, u)
- stack:keypressed(k, u)
+ if currentState then currentState:keypressed(k, u) end
end
function love.mousepressed(x, y, mb)
- stack:mousepressed(x, y, mb)
+ if currentState then currentState:mousepressed(x, y, mb) end
end
function love.keypressed(k, u)
- stack:keypressed(k, u)
-end
-
-function love.quit()
+ if currentState then currentState:keypressed(k, u) end
end
View
6 BGJ02/src/menu.lua
@@ -13,9 +13,9 @@ function Menu:__init()
self.menu.callback = function(index, text)
if index == 1 then
- stack:push(game)
+ currentState = game
elseif index == 3 then
- stack:pop()
+ currentState = nil
end
end
end
@@ -31,7 +31,7 @@ function Menu:keypressed(k, u)
self.menu:keypressed(k, u)
if k == "escape" then
- stack:pop()
+ currentState = nil
end
end
View
50 BGJ02/src/util/gamestack.lua
@@ -1,50 +0,0 @@
--- gamestack
-
-require("util/helper")
-
-GameStack = class("GameStack")
-
-function GameStack:__init()
- self.states = {}
-end
-
-function GameStack:current()
- if #self.states > 0 then
- return self.states[#self.states]
- else
- return nil
- end
-end
-
-function GameStack:push(state)
- if self:current() then self:current():stop() end
- table.insert(self.states, state)
- self:current():start()
-end
-
-function GameStack:pop()
- if not self:current() then return end
- self:current():stop()
- table.remove(self.states, #self.states)
- if self:current() then self:current():start() end
-end
-
-function GameStack:update(dt)
- if self:current() then
- self:current():update(dt)
- else
- love.event.quit()
- end
-end
-
-function GameStack:draw()
- if self:current() then self:current():draw() end
-end
-
-function GameStack:keypressed(k, u)
- if self:current() then self:current():keypressed(k, u) end
-end
-
-function GameStack:mousepressed(x, y, mb)
- if self:current() then self:current():mousepressed(x, y, mb) end
-end
View
8 BGJ02/src/util/gamestate.lua
@@ -1,6 +1,7 @@
-- game state
require("util/helper")
+local tween = require("externals/tween/tween")
GameState = class("GameState")
@@ -12,3 +13,10 @@ function GameState:start()end
function GameState:stop()end
function GameState:keypressed(k, u)end
function GameState:mousepressed(x, y, mb)end
+
+--function GameState:transitionTo(mode, state, duration)
+-- -- transitions to another game state
+--
+-- self.transition = -1
+-- tween(duration or 1, self, { transition = 1 })
+--end
View
16 BGJ02/src/util/resources.lua
@@ -7,12 +7,12 @@ Resources = class("Resources")
function Resources:__init(prefix)
self.prefix = prefix
self.imageQueue = {}
- self.musicQueue = {}
+ self.audioQueue = {}
self.fontQueue = {}
self.shaderQueue = {}
self.images = {}
- self.music = {}
+ self.audio = {}
self.fonts = {}
self.shaders = {}
end
@@ -25,8 +25,8 @@ function Resources:addImage(name, src)
self.imageQueue[name] = src
end
-function Resources:addMusic(name, src)
- self.musicQueue[name] = src
+function Resources:addAudio(name, src, stream)
+ self.audioQueue[name] = {src, stream}
end
function Resources:addShader(name, src)
@@ -44,9 +44,11 @@ function Resources:load(threaded)
self.imageQueue[name] = nil
end
- for name, src in pairs(self.musicQueue) do
- self.music[name] = love.audio.newSource(self.prefix .. src)
- self.musicQueue[name] = nil
+ for name, src in pairs(self.audioQueue) do
+ local mode = "static"
+ if src[2] then mode = "stream" end
+ self.audio[name] = love.audio.newSource(self.prefix .. src[1], mode)
+ self.audioQueue[name] = nil
end
for name, src in pairs(self.shaderQueue) do

0 comments on commit 94048bd

Please sign in to comment.
Something went wrong with that request. Please try again.