Skip to content

Commit

Permalink
volume slider in options menu
Browse files Browse the repository at this point in the history
  • Loading branch information
thomashope committed Jan 31, 2017
1 parent 52b3b5f commit 49ecbfd
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.DS_Store
lib/*/docs/*
lib/*/spec/*
*.zip
*.app
*.love
4 changes: 3 additions & 1 deletion main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ require 'src.wall'
function love.load()
-- Application setup
Physics:init()
love.math.setRandomSeed(love.timer.getTime())
love.mouse.setVisible(false)
love.graphics.setNewFont(18)
love.audio.setVolume(0.75)
love.math.setRandomSeed(love.timer.getTime())

-- Set globals
window_width, window_height = love.graphics.getDimensions()
Expand Down
2 changes: 1 addition & 1 deletion src/level_select_state.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,6 @@ function level_select_state:draw()
item = '> '..item
end

love.graphics.print(item, 20, 60 + 20 * i)
love.graphics.print(item, 20, 80 + 30 * i)
end
end
4 changes: 2 additions & 2 deletions src/main_menu_state.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ function main_menu_state:draw()
for i = 1, #self.items do
local string = self.items[i]
if i == self.index then string = "> "..string end
love.graphics.print(string, 20, 60 + 20 * i)
love.graphics.print(string, 20, 80 + 30 * i)
end

if self.items[self.index] == 'credits' or self.index ==3 then
love.graphics.print(main_menu_state.credits_string, 20, 200)
love.graphics.print(main_menu_state.credits_string, 20, 280)
end
end

Expand Down
23 changes: 20 additions & 3 deletions src/options_menu_state.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
options_menu_state = MenuState()

function options_menu_state:init()
self.items = {'fullscreen', 'vsync', 'back to main menu'}
self.items = {'volume', 'fullscreen', 'vsync', 'back to main menu'}
self:get_window_mode()
self.test_sound = love.audio.newSource('res/audio/player/sonar/Sonar_Player_01.wav', 'static')
end

function options_menu_state:enter()
self:get_window_mode()
self.index = 1
end

function options_menu_state:draw()
Expand All @@ -17,18 +19,33 @@ function options_menu_state:draw()
for i = 1, #self.items do
local string = self.items[i]

if string == 'fullscreen' then
if string == 'volume' then
string = string..': '..string.format('%d%%', love.audio.getVolume()*100)
elseif string == 'fullscreen' then
if self.window_mode.fullscreen then string = string..': [ON] off' else string = string..': on [OFF]' end
elseif string == 'vsync' then
if self.window_mode.vsync then string = string..': [ON] off' else string = string..': on [OFF]' end
end

-- prepend a '>' to the selected item
if i == self.index then string = "> "..string end

love.graphics.print(string, 20, 60 + 20 * i)
love.graphics.print(string, 20, 80 + 30 * i)
end
end

options_menu_state['volume'] = function(self, keycode, scancode, isrepeat)
if scancode == 'left' then
love.audio.setVolume( math.max(love.audio.getVolume() - 0.05, 0) )
elseif scancode == 'right' then
love.audio.setVolume( math.min(love.audio.getVolume() + 0.05, 1) )
end

self.test_sound:setPosition( love.audio.getPosition() )
self.test_sound:stop()
self.test_sound:play()
end

options_menu_state['fullscreen'] = function(self, keycode, scancode, isrepeat)
if scancode == 'space' or scancode == 'return' then
if not self.window_mode.fullscreen then
Expand Down
4 changes: 2 additions & 2 deletions src/pause_menu_state.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ function pause_menu_state:draw()
for i = 1, #self.items do
local string = self.items[i]
if i == self.index then string = "> "..string end
love.graphics.print(string, 20, 60 + 20 * i)
love.graphics.print(string, 20, 80 + 30 * i)
end

-- Display time take
if Level.won then
local time = string.format('Time: %.2fs', Level.finish_time - Level.start_time)

love.graphics.print(time, 20, 150)
love.graphics.print(time, 20, 220)
end
end

Expand Down

0 comments on commit 49ecbfd

Please sign in to comment.