Skip to content

Commit

Permalink
improve controller handling, added intro
Browse files Browse the repository at this point in the history
  • Loading branch information
thomashope committed Feb 6, 2017
1 parent e621914 commit 48bd59a
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 22 deletions.
7 changes: 7 additions & 0 deletions main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require 'src.main_menu_state'
require 'src.pause_menu_state'
require 'src.options_menu_state'
require 'src.level_select_state'
require 'src.credits_screen_state'
require 'src.playing_state'
require 'src.console_state'
require 'src.input_device'
Expand All @@ -25,6 +26,12 @@ require 'src.player'
require 'src.zombie'
require 'src.wall'

-- TODO: improve the Timer.tween functions by
-- When additional arguments are given they are passed as arguments
-- to the 'after' function (they are currently passed to the tweening funciton)
-- replace the tweening function string with a string or table value to pass
-- additional arguments when required

function love.load()
-- Application setup
Physics:init()
Expand Down
34 changes: 34 additions & 0 deletions src/credits_screen_state.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
credits_screen_state = State()

function credits_screen_state:init()
self.credits_string =
[[Originally created for the GGJ2017
Concept/Programming: Tom
@HopeThomasj
Audio: Chris
linkedin.com/in/christopher-quinn-sound
More levels by Bogdan, Sam A. and Sam C.
And thanks to Dundee Makerspace for the awesome jam site!]]
end

function credits_screen_state:update()
if controller_1:button_pressed_any() then
Gamestate.switch(main_menu_state)
end
end

function credits_screen_state:draw()
love.graphics.setBackgroundColor(0, 0, 0)
love.graphics.setColor(255,255,255)
love.graphics.print(self.credits_string, 20, 20)
end

function credits_screen_state:keypressed( keycode, scancode, isrepeat )
if scancode == 'space' then
Gamestate.switch(main_menu_state)
end
end
1 change: 1 addition & 0 deletions src/level_select_state.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ end

function level_select_state:draw()
love.graphics.setBackgroundColor(self.bg)
love.graphics.setColor(255,255,255)
love.graphics.print('level select...', 20, 20)

-- Iterate over the list of menu items
Expand Down
103 changes: 88 additions & 15 deletions src/main_menu_state.lua
Original file line number Diff line number Diff line change
@@ -1,34 +1,104 @@
main_menu_state = MenuState()

-- TODO: allow the intro to be skipped by pressing start on the controller

function main_menu_state:init()
self.items = {'play', 'options', 'credits', 'quit'}
self.credits_string =
[[Originally created for the GGJ2017
self.title_colour = {0,0,0}
self.menu_colour = {0,0,0}
self.title_is_done = false
self.allow_input = false

Concept/Programming: Tom
@HopeThomasj
-- Tutorial text to fade when playing is highlighted
self.tut_str = {
{text="Something is moving,", colour={0,0,0}, target={255,255,255}, fade=1.5},
{text="out there,", colour={0,0,0}, target={255,255,255}, fade=1.5},
{text="in the darkness...", colour={0,0,0}, target={255,255,255}, fade=1.5},
{text="", colour={0,0,0}, target={255,255,255}, fade=1},
{text="Zombies will kill you.", colour={0,0,0}, target={100,255,100}, fade=2},
{text="Sounds attracted zombies.", colour={0,0,0}, target={100,100,255}, fade=2},
{text="Lava kill everything.", colour={0,0,0}, target={255,100,100}, fade=2}
}
self.tut_str_index = 1

Audio: Chris
linkedin.com/in/christopher-quinn-sound
-- Init is run just before entering the state for the first time
-- The following is run to give us a nice intro sequence when we reach the main menu

More levels by Bogdan, Sam A. and Sam C.
local function fade_in_title()
Timer.tween(3, main_menu_state.title_colour, {255,255,255}, 'in-out-quad')
main_menu_state.title_is_done = true
end
local function fade_in_menu()
Timer.tween(1, main_menu_state.menu_colour, {255,255,255}, 'in-out-quad')
Timer.after(0.5, function() self.allow_input = true end)
end

And thanks to Dundee Makerspace for the awesome jam site!]]
-- Fade in each line in the tutorial string (actually it's a table of strings)
Timer.every( 1, function()
local self = main_menu_state
Timer.tween(
self.tut_str[self.tut_str_index].fade, -- Time to fade in
self.tut_str[self.tut_str_index].colour, -- initial colour
self.tut_str[self.tut_str_index].target, -- end colour
'in-out-quad')
self.tut_str_index = self.tut_str_index + 1
end, #self.tut_str )

-- Then fade in the title
Timer.after( #self.tut_str+1, fade_in_title )
-- Then fade in th menu
Timer.after( #self.tut_str+4, fade_in_menu )
end

function main_menu_state:enter()
self.index = 1
end

function main_menu_state:leave()
self.allow_input = true
self.title_is_done = true
end

function main_menu_state:update()
-- Only allow the user to interact with the menu when the intro is done
if self.allow_input then
self:navigate_menu()
end
end

function main_menu_state:draw()
love.graphics.setBackgroundColor(self.bg)
love.graphics.setColor(self.title_colour)
love.graphics.print("Sounds in a Dark Room", 20, 20, 0, 3, 3)

love.graphics.setColor(255,255,255)
for i = 1, #self.items do
local string = self.items[i]
if i == self.index then string = "> "..string end
love.graphics.print(string, 20, 80 + 30 * i)
-- Only draw the menu when the intro is done
if self.title_is_done then
love.graphics.setColor(self.menu_colour)
for i = 1, #self.items do
local string = self.items[i]
if i == self.index then string = "> "..string end
love.graphics.print(string, 20, 80 + 30 * i)
end
end

-- Draw the tutorial stings
for i = 1, #self.tut_str do
love.graphics.setColor(self.tut_str[i].colour)
love.graphics.print(self.tut_str[i].text, 220, 80 + 30 * i)
end
end

if self.items[self.index] == 'credits' or self.index ==3 then
love.graphics.print(main_menu_state.credits_string, 20, 280)
function main_menu_state:keypressed( keycode, scancode, isrepeat )
-- Allow escape to skip the intro sequence
if scancode == 'escape' and not self.title_is_done then
self.title_is_done = true
self.allow_input = true
self.menu_colour = {255,255,255}
end
-- Since we are overriding the keypressed function we need to
-- explicitly forward inputs
if self.allow_input then
MenuState.keypressed( self, keycode, scancode, isrepeat )
end
end

Expand All @@ -45,6 +115,9 @@ main_menu_state['options'] = function( self, scancode )
end

main_menu_state['credits'] = function( self, scancode )
if scancode == 'space' or controller_1:button_pressed_a() then
Gamestate.switch(credits_screen_state)
end
end

main_menu_state['quit'] = function( self, scancode )
Expand Down
2 changes: 1 addition & 1 deletion src/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ function Player:use_sonar()
Audio.play_random_at(self.sonar_sounds, self.x, self.y)

local p = Pulse(self.x, self.y, 100, 200, 1.5)
p.color = {0, 255, 100}
p.color = {100,100,255}
end
end

Expand Down
7 changes: 2 additions & 5 deletions src/splash_screen_state.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ function splash_screen_state:finish()
end

function splash_screen_state:update(dt)
if controller_1:button_pressed_any() then
if controller_1:button_pressed_any() or
(controller_1.device ~= 'keyboard' and controller_1:button_down_a_keyboard()) then
self:finish()
end
end
Expand All @@ -28,8 +29,4 @@ function splash_screen_state:draw()

love.graphics.setColor(255, 255, 255)
love.graphics.printf("Sounds in a Dark Room", 0, window_height/3, window_width/4, "center", 0, 4)
end

function splash_screen_state:keypressed( keycode, scancode, isrepeat )
self:finish()
end
2 changes: 1 addition & 1 deletion src/zombie.lua
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ function Zombie:update(dt)

-- Create footstep pulse
local p = Pulse(self.x, self.y, 100, 16, 0.2, {1,2})
p.color = {255,0,0}
p.color = {100,255,100}
p.name = 'zombie step'

self.left_foot = not self.left_foot
Expand Down

0 comments on commit 48bd59a

Please sign in to comment.