Skip to content

Instantly share code, notes, and snippets.

@Achie72
Created January 23, 2024 17:18
Show Gist options
  • Save Achie72/7dc35e3dbe5d589140319e8706419550 to your computer and use it in GitHub Desktop.
Save Achie72/7dc35e3dbe5d589140319e8706419550 to your computer and use it in GitHub Desktop.
Samurai Game Jam Devlog - One Last Swing #2 - Clue System - PICO-8
-- red starts from high stance
-- for ex, let's say the start at a high stance
enemy.finalStance = HIGH_STANCE
local modifierCollection = {}
-- let's roll a few modifires, which are
-- showcased by the clue system for you
-- to figure out
for i=1,3 do
-- roll a chance for it to even happen
if rnd() > 0.5 then
-- let's roll ups or downs
if rnd() > 0.5 then
-- moving stance upwards
add(modifierCollection, 1)
else
-- moving stance downward
add(modifierCollection, -1)
end
end
end
-- apply modifiers to stance
for mod in all(modifierCollection) do
enemy.finalStance += mod
-- wrap it around if needed in both directions
if enemy.finalStance > HIGH_STANCE then enemy.finalStance = LOW_STANCE end
if enemy.finalStance < LOW_STANCE then enemy.finalStance = HIGH_STANCE end
-- spawn the clue based on value
local randomClueType = rnd()
-- birds < 33
-- clouds < 66
-- deer > 66
local modifierType = mod < 0
if randomClueType <= 0.33 then
-- negative modifier means bird on left -> sword moving down
add_bird_or_cloud(modifierType, true)
elseif (0.33 < randomClueType) and (randomClueType <= 0.66) then
-- negative modifier means cloud on left -> sword moving down
add_bird_or_cloud(modifierType, false)
else
-- negative modifier means male deer -> male deer -> sword moving down
add_deer(modifierType)
end
end
-- adders:
function add_bird_or_cloud(_leftOrRight,_bird_or_cloud)
local object = {
x = 0,
y = rnd({0,1,2,3}),
leftOrRight = _leftOrRight
}
-- if itis a bird
if _bird_or_cloud then
add(birdCollection, object)
else
object.sprite = rnd({119,120,121,122})
add(cloudCollection, object)
end
end
-- check the words for the deer genders (buck, doe)
function add_deer(_maleOrFemale)
local deer = {
x = rnd(30)+15,
y = rnd(20)+15,
maleOrFemale = _maleOrFemale
}
add(deerCollection, deer)
end
-- drawing the clues
function draw_clues()
-- draw the birds
local birdsOnLeft, birdsOnRight, cloudsOnLeft, cloudsOnRight = 0, 0, 0, 0
for bird in all(birdCollection) do
-- calc if we need offsets so birds on same side don't overlap
local xPos = 0
-- bird on right side is false with leftOrRight
if bird.leftOrRight then
xPos += birdsOnLeft * 6
birdsOnLeft += 1
else
xPos = 32 + birdsOnRight * 6
birdsOnRight += 1
end
-- draw the bird
-- offset so the seem to be flapping wings
local offset = time() % 2
spr(126+offset, xPos, bird.y)
end
for cloud in all(cloudCollection) do
-- calc if we need offsets so clouds on same side don't overlap
local xPos = 0
cloud.x += 0.1
-- cloud on right side is false with leftOrRight
if cloud.leftOrRight then
xPos += cloudsOnLeft * 6
cloudsOnLeft += 1
else
xPos = 32 + cloudsOnRight * 6
cloudsOnRight += 1
end
-- draw the cloud
spr(cloud.sprite, xPos + cloud.x, cloud.y)
end
for deer in all(deerCollection) do
local sprite = 79
if deer.maleOrFemale then sprite = 78 end
spr(sprite, deer.x, deer.y)
end
end
@Achie72
Copy link
Author

Achie72 commented Jan 23, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment