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

Bump LÖVE to 11.5 #21

Open
wants to merge 2 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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ This 2D game was made by [Rasmus Nordling](https://github.com/happystinson) and
## Dependencies

- Lua 5.1
- [LÖVE](https://www.love2d.org/) 11.1
- [LÖVE](https://www.love2d.org/) 11.4

## Downloads

Check the [releases](https://github.com/HappyStinson/downhill-willy/releases) tab for this repo or view the game at [itch.io](https://rasmusnordling.itch.io/downhill-willy).
Check the [releases](https://github.com/HappyStinson/downhill-willy/releases) tab for this repo or view the game at [itch.io](https://rasmusnordling.itch.io/downhill-willy).
2 changes: 1 addition & 1 deletion conf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
function love.conf(t)
t.title = "Downhill Willy - BOSS Jam 2014"
t.window.icon = "assets/logo.png"
t.version = "11.1"
t.version = "11.4"
t.window.width = 1280
t.window.height = 720
end
Expand Down
19 changes: 6 additions & 13 deletions main.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
-- just a comment

-- This game requires level.lua
require('level')
require('constants')
require 'src.constants'
require 'src.level'
Input = require 'src.input'

function love.load()
love.mouse.setVisible(false)
gameCanvas = love.graphics.newCanvas(GAME_WIDTH, GAME_HEIGHT)
level.load()

Input:initJoystick()

-- Start the game in fullscreen
love.window.setFullscreen(true, "desktop")
end
Expand Down Expand Up @@ -40,12 +41,4 @@ end

function getMarginX(scale)
return (love.graphics.getWidth() - GAME_WIDTH * scale) / 2
end

function love.keypressed(key)
if key == controls.quit then
love.event.quit()
end

level.keypressed(key, controls)
end
File renamed without changes.
File renamed without changes.
File renamed without changes.
80 changes: 80 additions & 0 deletions src/input.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
-- Simple LÖVE Joystick and Keyboard input
local Input = {}

require 'src.level'
require 'src.whale'

local inputState = {
keyPressed = {
up = false,
down = false,
},
gamepadButtonPressed = {
dpadUp = false,
dpadDown = false,
}
}

function Input:initJoystick()
local joysticks = love.joystick.getJoysticks()
joystick = joysticks[1]
end

local function startGame()
level.startGame()
end

function Input:keyPressed(key)
if key == "up" or key == "w" then
inputState.keyPressed.up = true
elseif key == "down" or key == "s" then
inputState.keyPressed.down = true

elseif key == controls.toggle_fullscreen then
level.toggleFullscreen()
level.toggleMouseVisibility()
elseif key == controls.start then
startGame()
end
end

function Input:gamepadButtonPressed(button)
if button == "dpup" then
inputState.gamepadButtonPressed.dpadUp = true
elseif button == "dpdown" then
inputState.gamepadButtonPressed.dpadDown = true
elseif button == "start" then
startGame()
end
end

function Input:processCharacterMovementInput()
local upReleased = inputState.keyPressed.up or inputState.gamepadButtonPressed.dpadUp
local downReleased = inputState.keyPressed.down or inputState.gamepadButtonPressed.dpadDown

if upReleased then
whale.moveUp()
inputState.keyPressed.up = false
inputState.gamepadButtonPressed.dpadUp = false
end

if downReleased then
whale.moveDown()
inputState.keyPressed.down = false
inputState.gamepadButtonPressed.dpadDown = false
end
end

function love.keypressed(key)
if key == controls.quit then
love.event.quit()
end

Input:keyPressed(key)
end

function love.gamepadpressed(joystick, button)
Input:gamepadButtonPressed(button)
end

return Input
94 changes: 47 additions & 47 deletions level.lua → src/level.lua
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
-- This file describes our level

level = {}
require 'whale'
require 'constants'
local audio = require 'audio'
local colors = require 'colors'

local function loadImages()
img_fn = {"bg_forest", "bg_mnt1", "bg_mnt2", "fg_snow", "ui_hiscore", "lanes", "logo", "obj_log", "obj_snowman", "obj_stone", "obj_tree", "player_idle", "player_run1", "player_run2", "ui_score", "sky", "vall"}
images = {}
for _, v in ipairs(img_fn) do
images[v] = love.graphics.newImage("assets/"..v..".png")
end
require 'src.whale'
require 'src.constants'
local audio = require 'src.audio'
local colors = require 'src.colors'

-- LOAD
local function createBackgroundQuad()
-- Create a quad for the background
mapWidth = images.bg_mnt1:getWidth() * 2
mountainQuad = love.graphics.newQuad(0, 0, mapWidth, 704, 1547, 704)
Expand All @@ -22,6 +18,16 @@ local function loadImages()
images.bg_forest:setWrap("repeat")
end

local function loadImages()
img_fn = {"bg_forest", "bg_mnt1", "bg_mnt2", "fg_snow", "ui_hiscore", "lanes", "logo", "obj_log", "obj_snowman", "obj_stone", "obj_tree", "player_idle", "player_run1", "player_run2", "ui_score", "sky", "vall"}
images = {}
for _, v in ipairs(img_fn) do
images[v] = love.graphics.newImage("assets/"..v..".png")
end

createBackgroundQuad()
end

local function initFont()
fonts = {
score = love.graphics.newFont("assets/font_score.otf", 22),
Expand All @@ -39,10 +45,28 @@ local function initLanes()
}
end

local function initAudio()
audioSources = {
idle = audio.streamLooped("yodel_idle"),
yodel_intro = audio.stream("yodel_intro"),
yodel_loop = audio.streamLooped("yodel_loop")
}
audioSources.idle:play()

soundEffects = {
fanfare = audio.soundEffect("fanfare"),
obj_log = audio.soundEffect("crash-log"),
obj_snowman = audio.soundEffect("crash-snowman"),
obj_stone = audio.soundEffect("crash-stone"),
obj_tree = audio.soundEffect("crash-tree")
}
end

function level.load()
loadImages()
initFont()
initLanes()
initAudio()
level.objects = {}

isRunning = false
Expand All @@ -65,22 +89,6 @@ function level.load()

laneYPos = {330, 250, 175}

-- Initialize audio
audioSources = {
idle = audio.streamLooped("yodel_idle"),
yodel_intro = audio.stream("yodel_intro"),
yodel_loop = audio.streamLooped("yodel_loop")
}
audioSources.idle:play()

soundEffects = {
fanfare = audio.soundEffect("fanfare"),
obj_log = audio.soundEffect("crash-log"),
obj_snowman = audio.soundEffect("crash-snowman"),
obj_stone = audio.soundEffect("crash-stone"),
obj_tree = audio.soundEffect("crash-tree")
}

-- Keep track of current and best score
score = 0
hiscore = 0
Expand All @@ -89,6 +97,7 @@ function level.load()
whale.load()
end

-- UPDATE
local function updateBackground(dt)
bgOffsets.mnt1 = bgOffsets.mnt1 + dt * 5 * speed
bgOffsets.mnt2 = bgOffsets.mnt2 + dt * 10 * speed
Expand Down Expand Up @@ -213,6 +222,7 @@ function level.update(dt)
end

-- Update whale position
Input:processCharacterMovementInput()
whale.update(dt)

if time > 2 then
Expand All @@ -227,6 +237,7 @@ function level.update(dt)
end
end

-- DRAW
local function drawBackground()
-- Draw the beautiful sky
love.graphics.draw(images.sky, 0, 0)
Expand Down Expand Up @@ -360,35 +371,24 @@ function level.draw(controls)
drawGUI(controls)
end

local function toggleFullscreen()
function level.toggleFullscreen()
local isFullscreen = not love.window.getFullscreen()
love.window.setFullscreen(isFullscreen, "desktop")
end

local function toggleMouseVisibility()
function level.toggleMouseVisibility()
local state = not love.mouse.isVisible()
love.mouse.setVisible(state)
end

local function startGame()
isRunning = true
playerGotNewHighScore = false
audioSources.idle:stop()
if not audioSources.yodel_loop:isPlaying() then
audioSources.yodel_intro:play()
end
end

function level.keypressed(key, controls)
function level.startGame()
if not isRunning then
if key == controls.toggle_fullscreen then
toggleFullscreen()
toggleMouseVisibility()
end
if key == controls.start then
startGame()
isRunning = true
playerGotNewHighScore = false
audioSources.idle:stop()

if not audioSources.yodel_loop:isPlaying() then
audioSources.yodel_intro:play()
end
else
whale.keypressed(key)
end
end
10 changes: 7 additions & 3 deletions whale.lua → src/whale.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ function whale.update(dt)
whale.y = getY(whale.lane, whale.x)
end

function whale.keypressed(key)
if key == "up" and whale.lane < 3 then
function whale.moveUp()
if whale.lane < 3 then
whale.lane = whale.lane + 1
elseif key == "down" and whale.lane > 1 then
end
end

function whale.moveDown()
if whale.lane > 1 then
whale.lane = whale.lane - 1
end
end
Expand Down