Skip to content

Instantly share code, notes, and snippets.

@Achie72
Last active April 10, 2023 09:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Achie72/f533863e09019ab854cbe9dcd9703002 to your computer and use it in GitHub Desktop.
Save Achie72/f533863e09019ab854cbe9dcd9703002 to your computer and use it in GitHub Desktop.
Upgrade System
-- made for Rogala, my Devtober 2022 entry
-- you can read the corresponding devlog on:
-- https://ko-fi.com/Post/Eng-Devtober2022-3--MORE-UPGRADES-R6R3FL67S
-- https://itch.io/jam/devtober-2022/topic/2406837/achies-devlog-shmup-game
-- globals we need
levelUp = false
lvl = 1
upgrades = {5,0,0,0,0,3}
levelUpgrades = {}
upgradeIndicator = 0
playerXP = 0
-- in update upon player level up
if (playerXP >= lvl*2) and (not levelUp) then
-- generate the random pickups and put them in the collection
for i=0,3 do
table.insert(levelUpgrades,math.random(0,5))
end
-- set variable to true, so we change controls from game mode
-- to upgrade selection mode
levelUp = true
-- 0 our XP and increase the level
playerXP = 0
lvl = lvl+1
end
-- now we check if we use the level up dialog controls or regular
-- gameplay ones
if levelUp then
if btn(4) then
-- upon button press, we resume to the game
levelUp = false
-- save the currently indicated upgrade
local choosenUpgrade = levelUpgrades[upgradeIndicator]
-- and increase the player upgrades slot corresponding to the upgrade, hence saving
-- the increased number of the selected upgrade
upgrades[choosenUpgrade+1] = upgrades[choosenUpgrade+1]+1
levelUpgrades = {}
end
-- this code just handles the hand cycling correctly between the shown upgrades
if btnp(0) then
upgradeIndicator = upgradeIndicator-1
end
if btnp(1) then
upgradeIndicator = upgradeIndicator+1
end
if upgradeIndicator < 1 then
upgradeIndicator = 4
end
if upgradeIndicator > 4 then
upgradeIndicator = 1
end
else
-- player controls
end
end
-- in draw call
-- level up dialog
if (levelUp==true) then
-- create the local collection for names
local names = {"rocket","afterburner","Chain reloader","ion shield","repair bot","mini turrets"}
-- draw a background so stage elements don't obscure anything
rect(20,20,160,90,0)
-- flash the level up text and the hand that indicates the choosen upgrade
if t%20 > 10 then
print("--- level up ---",60,20,5)
spr(12,18,20+upgradeIndicator*20,0)
print(levelUpgrades[upgradeIndicator],8,20+upgradeIndicator*20,3)
end
-- draw the randomly generated upgrades with offsets
for _,up in ipairs(levelUpgrades) do
rectb(26,18+_*20,14,14,5)
spr(16+up, 30, 20+_*20, 0)
print(names[up+1],50 ,20+_*20,5)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment