Skip to content

Instantly share code, notes, and snippets.

@Achie72
Created November 5, 2023 10:37
Show Gist options
  • Save Achie72/f4562eb573fa0f91c40a376cbe11f573 to your computer and use it in GitHub Desktop.
Save Achie72/f4562eb573fa0f91c40a376cbe11f573 to your computer and use it in GitHub Desktop.
Lina: Suika Hunt - Combo System for PICO-8
-- function to build directional combo
-- with lenght of the parameter
-- 11 fruit types
function create_combo(_length)
-- combo options
local comboTable = {"⬅️","⬇️","⬆️","➡️"}
-- combo string in build
local combo=""
-- create string equal to combo lenght
for i=1,_length do
combo=combo..rnd(comboTable)
end
-- return string
return combo
end
-- spawn fruits into the game
function add_fruit(_x, _type)
-- combo length based on ID
-- 1,2 - 1
-- 3,4 - 2
-- 5,6 - 3
-- 7,8 - 4
-- 9-10- 5
-- 11 - 6
-- 12 - 6
local comboLengthTable = {1,1,2,2,3,3,4,4,5,5,6}
-- ceil(n/2)
local comboLenght = ceil(_type/2)
local fruit = {
x = _x,
y = 100, -- arbitary number, where they should spawn horizontally
ax = rnd({1,-1}), -- acceleration in X direction
ay = -rnd(1), -- acceleration in Y direction
type = _type, -- type indicating which fruit this one is
comboString = create_combo(comboLenght) --rnd goes from 0 to number-1 at base
}
add(fruitCollection, fruit)
end
-- during gameplay we want to press directions
-- those direction should go into a comboString
-- on button press we "shoot" a fruit down
-- by checking if our comboString equals to one of the fruit's combo
-- string. If yes, delete that fruit.
if btnp(0) then
playerComboString = playerComboString.."⬅️"
elseif btnp(1) then
playerComboString = playerComboString.."➡️"
elseif btnp(2) then
playerComboString = playerComboString.."⬆️"
elseif btnp(3) then
playerComboString = playerComboString.."⬇️"
end
-- now if we press X check for combo
if btnp(5) then
-- check each fruit to see if we have a combo matching on of
-- their combo string
for fruit in all(fruitCollection) do
-- check for combo
if fruit.comboString == playerComboString then
-- we add the score of the fruit to the points
-- which is the same as the type
score+=ceil(fruit.type)
-- the fruits that have the same get deleted from
-- the collection
del(fruitCollection, fruit)
-- we immediatly add a new fruit to the scene
add_fruit( rnd(128), flr(rnd(8))+1)
end
end
-- empty the combo string so nothing remains in it
-- basically to start from empty after shooting
playerComboString = ""
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment