2014-10-17 19:28:17 +00:00
|
|
|
Gamestate = require 'hump.gamestate'
|
2014-10-19 10:54:54 +00:00
|
|
|
require 'level_state'
|
|
|
|
require 'settings'
|
2014-10-23 18:42:30 +00:00
|
|
|
require 'entities/label'
|
|
|
|
require 'entities/valuecontroller'
|
2014-10-17 19:28:17 +00:00
|
|
|
|
|
|
|
menu_state = {}
|
|
|
|
|
|
|
|
local font = love.graphics.newFont(18)
|
2014-10-23 18:42:30 +00:00
|
|
|
local midfont = love.graphics.newFont(40)
|
2014-10-19 10:54:54 +00:00
|
|
|
local titlefont = love.graphics.newFont(72)
|
|
|
|
local background = love.graphics.newImage('resources/graphics/sky.png')
|
2014-10-17 19:28:17 +00:00
|
|
|
|
2014-10-23 18:42:30 +00:00
|
|
|
local menuTime = 0
|
|
|
|
|
|
|
|
local currentlyChosen = nil
|
|
|
|
|
|
|
|
local bindingName = {
|
|
|
|
ccw = "Turn CW",
|
|
|
|
cw = "Turn CCW",
|
|
|
|
shoot = "Shoot",
|
|
|
|
accelerate = "Engine power up",
|
|
|
|
decelerate = "Engine power down",
|
|
|
|
flip = "Flip"
|
|
|
|
}
|
|
|
|
|
|
|
|
local bindingOrder = { "ccw", "cw", "shoot", "accelerate", "decelerate", "flip" }
|
|
|
|
|
2014-10-17 19:28:17 +00:00
|
|
|
function menu_state:enter()
|
2014-10-23 18:42:30 +00:00
|
|
|
menu_state.entity_list = {}
|
2014-10-17 19:28:17 +00:00
|
|
|
love.graphics.setBackgroundColor(0, 0, 0, 0)
|
2014-10-23 18:42:30 +00:00
|
|
|
|
|
|
|
local x = 40
|
|
|
|
for player = 1, 2, 1 do
|
|
|
|
local y = 300
|
|
|
|
Label(string.format("Player %d", player), midfont, { 255, 255, 255, 255 }, "left", 500, 0, x, y, menu_state)
|
|
|
|
y = y + 60
|
|
|
|
for idx, key in ipairs(bindingOrder) do
|
2014-10-24 06:05:00 +00:00
|
|
|
Label(bindingName[key], font, { 255, 255, 255, 255 }, "left", 190, 25, x, y, menu_state)
|
|
|
|
for bindingIdx, binding in ipairs(KEYMAP[player][key]) do
|
|
|
|
local label = Label(binding, font, { 255, 255, 255, 255 }, "left", 50, 25, x + 200 + 20 * (bindingIdx - 1), y, menu_state)
|
|
|
|
label:onClick(function()
|
|
|
|
menu_state:adjustBindings(label, bindingIdx, player, key)
|
|
|
|
end)
|
2014-10-23 18:42:30 +00:00
|
|
|
end
|
|
|
|
y = y + 30
|
|
|
|
end
|
|
|
|
x = x + 400
|
|
|
|
end
|
2014-10-17 19:28:17 +00:00
|
|
|
end
|
|
|
|
|
2014-10-23 18:42:30 +00:00
|
|
|
local blinkColor = function(t)
|
|
|
|
local seconds, subseconds = math.modf(menuTime)
|
|
|
|
return 255 * ((math.sin(math.pow((math.log(subseconds + 1) / math.log(2)), 2) * math.pi * 2) * 0.5 + 0.5));
|
|
|
|
end
|
|
|
|
|
2014-10-24 06:05:00 +00:00
|
|
|
function menu_state:adjustBindings(label, bindingIdx, player, key)
|
2014-10-23 18:42:30 +00:00
|
|
|
if currentlyChosen ~= nil then
|
|
|
|
currentlyChosen:delete()
|
|
|
|
end
|
|
|
|
|
|
|
|
currentlyChosen = ValueController(function ()
|
2014-10-24 06:05:00 +00:00
|
|
|
label.color[4] = blinkColor();
|
2014-10-23 18:42:30 +00:00
|
|
|
end, menu_state)
|
2014-10-24 06:05:00 +00:00
|
|
|
currentlyChosen.data = { bindingIdx = bindingIdx, player = player, key = key, label = label }
|
2014-10-23 18:42:30 +00:00
|
|
|
currentlyChosen.onDelete = function()
|
2014-10-24 06:05:00 +00:00
|
|
|
label.color[4] = 255;
|
2014-10-23 18:42:30 +00:00
|
|
|
end
|
|
|
|
end
|
2014-10-17 19:28:17 +00:00
|
|
|
|
|
|
|
function menu_state:draw()
|
2014-10-19 10:54:54 +00:00
|
|
|
love.graphics.setColor(128, 128, 128, 255)
|
|
|
|
love.graphics.draw(background)
|
|
|
|
|
2014-10-23 18:42:30 +00:00
|
|
|
local seconds, subseconds = math.modf(menuTime)
|
|
|
|
|
2014-10-17 19:28:17 +00:00
|
|
|
love.graphics.setColor(255,255,255,255)
|
2014-10-19 10:54:54 +00:00
|
|
|
love.graphics.setFont(titlefont)
|
|
|
|
|
|
|
|
love.graphics.printf("FYSPLANE", 0, 100, love.window.getWidth(), "center")
|
|
|
|
|
|
|
|
love.graphics.printf("PRESS ANY KEY TO BEGIN…", 0, 700, love.window.getWidth(), "center")
|
2014-10-23 18:42:30 +00:00
|
|
|
|
|
|
|
for key, entity in pairs(menu_state.entity_list) do
|
|
|
|
entity:draw()
|
|
|
|
end
|
|
|
|
|
2014-10-17 19:28:17 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function menu_state:update(dt)
|
2014-10-23 18:42:30 +00:00
|
|
|
menuTime = menuTime + dt
|
2014-10-17 19:28:17 +00:00
|
|
|
|
2014-10-23 18:42:30 +00:00
|
|
|
for key, entity in pairs(menu_state.entity_list) do
|
|
|
|
if entity.update then
|
|
|
|
entity:update(dt)
|
|
|
|
end
|
|
|
|
end
|
2014-10-17 19:28:17 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function menu_state:focus(bool)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function menu_state:keypressed(key, unicode)
|
2014-10-23 18:42:30 +00:00
|
|
|
if currentlyChosen == nil then
|
|
|
|
if key == "1" then
|
|
|
|
level_state.mode = "solo"
|
|
|
|
Gamestate.switch(level_state)
|
|
|
|
elseif key == "c" then
|
|
|
|
level_state.mode = "computer"
|
|
|
|
Gamestate.switch(level_state)
|
|
|
|
elseif key == "escape" then
|
|
|
|
love.event.quit()
|
|
|
|
else
|
|
|
|
level_state.computer = "2player"
|
|
|
|
Gamestate.switch(level_state)
|
|
|
|
end
|
2014-10-22 18:44:51 +00:00
|
|
|
elseif key == "escape" then
|
2014-10-23 18:42:30 +00:00
|
|
|
currentlyChosen:delete()
|
|
|
|
currentlyChosen = nil
|
2014-10-19 11:02:32 +00:00
|
|
|
else
|
2014-10-24 06:27:17 +00:00
|
|
|
if key == "backspace" then
|
|
|
|
key = "none"
|
|
|
|
end
|
2014-10-24 06:05:00 +00:00
|
|
|
KEYMAP[currentlyChosen.data.player][currentlyChosen.data.key][currentlyChosen.data.bindingIdx] = key
|
2014-10-23 18:42:30 +00:00
|
|
|
currentlyChosen.data.label.label = key
|
|
|
|
currentlyChosen:delete()
|
|
|
|
currentlyChosen = nil
|
2014-10-23 18:55:57 +00:00
|
|
|
save_settings()
|
2014-10-19 11:02:32 +00:00
|
|
|
end
|
2014-10-17 19:28:17 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function menu_state:keyreleased(key, unicode)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2014-10-24 06:14:09 +00:00
|
|
|
function menu_state:joystickpressed(key, button)
|
|
|
|
if currentlyChosen == nil then
|
|
|
|
else
|
|
|
|
local key = string.format("button%d", button)
|
|
|
|
KEYMAP[currentlyChosen.data.player][currentlyChosen.data.key][currentlyChosen.data.bindingIdx] = key
|
|
|
|
currentlyChosen.data.label.label = key
|
|
|
|
currentlyChosen:delete()
|
|
|
|
currentlyChosen = nil
|
|
|
|
save_settings()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-10-17 19:28:17 +00:00
|
|
|
|
|
|
|
function menu_state:mousepressed(x, y, button)
|
2014-10-23 18:42:30 +00:00
|
|
|
for key, entity in pairs(menu_state.entity_list) do
|
|
|
|
if entity.mousePressed then
|
|
|
|
entity:mousePressed(x, y, button)
|
|
|
|
end
|
|
|
|
end
|
2014-10-17 19:28:17 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function menu_state:mousereleased(x, y, button)
|
|
|
|
|
|
|
|
end
|