Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Controller Support .... kinda #14

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions code/controller-support.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- Intercept love.keyboard.isDown to also check controller input
local oldKeyIsDown = love.keyboard.isDown
love.keyboard.isDown = function(key)
for i, joystick in ipairs(love.joystick.getJoysticks()) do
if joystick:isGamepadDown(controller_button_to_keys[key]) then
return true
end
end

return oldKeyIsDown(key)
end

-- Forward gamepad inputs to love.keypressed
function love.gamepadpressed(_, joybutton)
love.keypressed(controller_button_to_keys[joybutton]) -- yolo
end
135 changes: 73 additions & 62 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,81 +3,92 @@ settings = {
setting this to true speeds up the scrollSpeed without needing to hold down "lshift"
this can also be set by running the startup command of `love . debug`
]]
debug = false;

music_volume = 20;
sfx_volume = 25;
speech_volume = 5;
text_scroll_speed = 30;
displayModesIndex = 1;
fullscreen_scale = 2;
displayModes = {"Fullscreen", "Windowed-Fullscreen"};

background_directory = "backgrounds/";
character_directory = "characters/";
music_directory = "music/";
sprite_directory = "sprites/";
shouts_directory = "sprites/shouts/";
sfx_directory = "sounds/";

main_logo_path = "main_logo_1024_flipped.png";
power_hour_set_path = "backgrounds/POWER_HOUR_SET_HQ.png";
black_screen_path = "backgrounds/BLACK_SCREEN.png";
lobby_path = "backgrounds/LOBBY.png";
court_path = "sprites/WideShot.png";
saves_path = "saves/";
game_over_path = "scripts/gameover.meta";
jory_trial_1_path = "scripts/jory_trial_1.meta";
jory_trial_2_path = "scripts/jory_trial_2.meta";
jory_trial_3_path = "scripts/jory_trial_3.meta";
jory_trial_4_path = "scripts/jory_trial_4.meta";
jory_trial_5_path = "scripts/jory_trial_5.meta";
jory_trial_6_path = "scripts/jory_trial_6.meta";
posttrial_path = "scripts/posttrial.meta";
credits_path = "scripts/credits.script";
episode_path = "scripts/episode1.meta";
debug = false,
music_volume = 20,
sfx_volume = 25,
speech_volume = 5,
text_scroll_speed = 30,
displayModesIndex = 1,
fullscreen_scale = 2,
displayModes = {"Fullscreen", "Windowed-Fullscreen"},
background_directory = "backgrounds/",
character_directory = "characters/",
music_directory = "music/",
sprite_directory = "sprites/",
shouts_directory = "sprites/shouts/",
sfx_directory = "sounds/",
main_logo_path = "main_logo_1024_flipped.png",
power_hour_set_path = "backgrounds/POWER_HOUR_SET_HQ.png",
black_screen_path = "backgrounds/BLACK_SCREEN.png",
lobby_path = "backgrounds/LOBBY.png",
court_path = "sprites/WideShot.png",
saves_path = "saves/",
game_over_path = "scripts/gameover.meta",
jory_trial_1_path = "scripts/jory_trial_1.meta",
jory_trial_2_path = "scripts/jory_trial_2.meta",
jory_trial_3_path = "scripts/jory_trial_3.meta",
jory_trial_4_path = "scripts/jory_trial_4.meta",
jory_trial_5_path = "scripts/jory_trial_5.meta",
jory_trial_6_path = "scripts/jory_trial_6.meta",
posttrial_path = "scripts/posttrial.meta",
credits_path = "scripts/credits.script",
episode_path = "scripts/episode1.meta"
}

-- Keybindings used by the onKeyPresseds in screens/index
controls = {
start_button = "return";
pause = "escape";
advance_text = "x";
pause_nav_up = "up";
pause_nav_down = "down";
press_confirm = "return";
press_court_record = "z";
press_right = "right";
press_left = "left";
press_toggle_profiles = "down";
start_button = "return",
pause = "escape",
advance_text = "x",
pause_nav_up = "up",
pause_nav_down = "down",
press_confirm = "return",
press_court_record = "z",
press_right = "right",
press_left = "left",
press_toggle_profiles = "down"
}

dimensions = {
graphics_scale = 4;
window_width = 1280;
window_height = 720;
background_scale = settings.fullscreen_scale;
-- Mapping from XBox controller inputs to literal keypresses, we just forward to love.keypressed
-- TODO: What about PlayStation? Will this just work (tm)?
controller_button_to_keys = {
start = "return",
back = "escape", -- "back" is that button we usually think of as "Select" to the left of "Start"
a = "x",
b = "z",
x = "x", -- x -> x, incredible
y = "z",
dpup = "up",
dpdown = "down",
dpleft = "left",
dpright = "right"
}

dimensions = {
graphics_scale = 4,
window_width = 1280,
window_height = 720,
background_scale = settings.fullscreen_scale
}

colors = {
white = {1, 1, 1};
black = {0, 0, 0};
red = {1, 0, 0};
ltblue = {0, 0.75, 1};
green = {0, 1, 0.25};
white = {1, 1, 1},
black = {0, 0, 0},
red = {1, 0, 0},
ltblue = {0, 0.75, 1},
green = {0, 1, 0.25}
}

-- Override default display names for keyboard keys
key_display_names = {
['escape'] = 'Esc';
['backspace'] = 'Back';
['return'] = 'Enter';
['delete'] = 'Del';
['rctrl'] = 'Ctrl (R)';
['lctrl'] = 'Ctrl (L)';
['rshift'] = 'Shift (R)';
['lshift'] = 'Shfit (L)';
["escape"] = "Esc",
["backspace"] = "Back",
["return"] = "Enter",
["delete"] = "Del",
["rctrl"] = "Ctrl (R)",
["lctrl"] = "Ctrl (L)",
["rshift"] = "Shift (R)",
["lshift"] = "Shfit (L)"
}

function InitGlobalConfigVariables()
Expand All @@ -90,4 +101,4 @@ function InitGlobalConfigVariables()
SFXVolume = settings.sfx_volume
SpeechVolume = settings.speech_volume
TextScrollSpeed = settings.text_scroll_speed
end
end
37 changes: 22 additions & 15 deletions main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ require "code/assets"
require "code/episode"
require "code/scene"
require "code/scriptloader"
require "code/controller-support"

local logoOpacity = 1
local drawLogo = true
local logoTimer = 0


function love.load()
InitGlobalConfigVariables()
love.window.setFullscreen(true, "desktop")
Expand Down Expand Up @@ -41,7 +41,7 @@ end
-- transfer the update and draw over to the current game scene
function love.update(dt)
if DtReset then
dt = 1/60
dt = 1 / 60
DtReset = false
end

Expand All @@ -63,7 +63,7 @@ end

function love.keypressed(key)
if drawLogo then
return;
return
end
local currentDisplayedScreen
local nextScreenToDisplay
Expand All @@ -75,8 +75,10 @@ function love.keypressed(key)
currentDisplayedScreen = screenName
end

if screenConfig.displayKey and key == screenConfig.displayKey and
(screenConfig.displayCondition == nil or screenConfig.displayCondition()) then
if
screenConfig.displayKey and key == screenConfig.displayKey and
(screenConfig.displayCondition == nil or screenConfig.displayCondition())
then
if screenName == currentDisplayedScreen then
screenConfig.displayed = false
else
Expand All @@ -85,7 +87,6 @@ function love.keypressed(key)
elseif screenConfig.displayed and screenConfig.onKeyPressed then
screenConfig.onKeyPressed(key)
end

end

if nextScreenToDisplay and currentDisplayedScreen == nil then
Expand All @@ -99,23 +100,29 @@ end
logo = love.graphics.newImage("studioloveliesfinal.png")

function love.draw()

if drawLogo then
love.graphics.setColor(0, 0, 0)
love.graphics.rectangle("fill", 0, 0, dimensions.window_width, dimensions.window_height)
love.graphics.setColor(1, 1, 1, logoOpacity)
love.graphics.draw(logo, dimensions.window_width/2 - logo:getWidth()/5.71, dimensions.window_height/2 - logo:getHeight()/5.71, 0, 0.35, 0.35)
love.graphics.draw(
logo,
dimensions.window_width / 2 - logo:getWidth() / 5.71,
dimensions.window_height / 2 - logo:getHeight() / 5.71,
0,
0.35,
0.35
)
else
love.graphics.setColor(unpack(colors.white))
love.graphics.setCanvas(Renderable)
love.graphics.clear(unpack(colors.black))
CurrentScene:draw()
love.graphics.setCanvas()

local dx,dy = 0,0
local dx, dy = 0, 0
if ScreenShake > 0 then
dx = love.math.random() * choose{1, -1} * 2
dy = love.math.random() * choose{1, -1} * 2
dx = love.math.random() * choose {1, -1} * 2
dy = love.math.random() * choose {1, -1} * 2
end

--dx = camerapan[1]
Expand All @@ -125,11 +132,11 @@ function love.draw()

love.graphics.draw(
Renderable,
dx*love.graphics.getWidth()/GraphicsWidth,
dy*love.graphics.getHeight()/GraphicsHeight,
dx * love.graphics.getWidth() / GraphicsWidth,
dy * love.graphics.getHeight() / GraphicsHeight,
0,
love.graphics.getWidth()/GraphicsWidth,
love.graphics.getHeight()/GraphicsHeight
love.graphics.getWidth() / GraphicsWidth,
love.graphics.getHeight() / GraphicsHeight
)

for screenName, screenConfig in pairs(screens) do
Expand Down