Something went wrong. Try again.
A Love2D remaster of my bug-catching-cult-classic Bait and Switch
Something went wrong. Try again.
3.7 kB · 144 lines
Lua
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144local tutorial = {}
local assets = require("src.assets")local player = require("src.player")local enemy = require("src.enemy")local gameState = require("src.gameState")local config = require("src.config")local input = require("src.input")local utils = require("src.utils")
tutorial.config = { walkIconOffset = -32, clickIconOffset = 12, clickIconYAlign = 0.5, fadeSpeed = 5, bugYOffset = -64}
function tutorial.load() tutorial.active = true local bugX = player.x local bugY = player.y + tutorial.config.bugYOffset tutorial.elements = { walk = { active = true, alpha = 1, icon = assets.ui.tutorial.walk, x = player.x - assets.ui.tutorial.walk:getWidth() / 2, y = player.y + tutorial.config.walkIconOffset, fadingOut = false }, click = { active = true, alpha = 1, icon = assets.ui.tutorial.click, x = bugX + tutorial.config.clickIconOffset, y = bugY - assets.ui.tutorial.click:getHeight() * tutorial.config.clickIconYAlign, fadingOut = false } } tutorial.createTutorialBug(bugX, bugY) gameState.tutorialMode = true tutorial.shadowOffset = config.visual.shadowOffset tutorial.shadowColor = config.visual.shadowColorend
function tutorial.createTutorialBug(x, y) tutorial.tutorialBug = { x = x, y = y, angle = 0, caught = false, isTutorialBug = true, dead = false } table.insert(enemy.active, tutorial.tutorialBug)end
function tutorial.checkMovement() return input.isMovementDown("up") or input.isMovementDown("down") or input.isMovementDown("left") or input.isMovementDown("right")end
function tutorial.updateElement(element, dt, condition) if not element.active then return end if condition and not element.fadingOut then element.fadingOut = true end if element.fadingOut then element.alpha = element.alpha - dt * tutorial.config.fadeSpeed if element.alpha <= 0 then element.active = false element.alpha = 0 end endend
function tutorial.drawElement(element) if not element.active or element.alpha <= 0 then return end local originalColor = {love.graphics.getColor()} love.graphics.setColor(1, 1, 1, element.alpha) utils.drawWithShadow( element.icon, math.floor(element.x), math.floor(element.y), 0, 1, 1, 0, 0, tutorial.shadowOffset, {tutorial.shadowColor[1], tutorial.shadowColor[2], tutorial.shadowColor[3], element.alpha} ) love.graphics.setColor(originalColor)end
function tutorial.update(dt) if not tutorial.active then return end if tutorial.tutorialBug and not tutorial.tutorialBug.caught then tutorial.tutorialBug.angle = tutorial.tutorialBug.angle + enemy.config.spinSpeed * dt end tutorial.updateElement(tutorial.elements.walk, dt, tutorial.checkMovement()) tutorial.updateElement(tutorial.elements.click, dt, input.isActionDown("net")) if tutorial.tutorialBug and tutorial.tutorialBug.caught then tutorial.active = false gameState.tutorialMode = false endend
function tutorial.draw() if not tutorial.active then return end tutorial.drawElement(tutorial.elements.walk) tutorial.drawElement(tutorial.elements.click) love.graphics.setColor(1, 1, 1, 1)end
return tutorial