Skip to content

Instantly share code, notes, and snippets.

@Achie72
Created January 23, 2024 17:05
Show Gist options
  • Save Achie72/fc07b272f2ce5a6b0bb2af33456176a0 to your computer and use it in GitHub Desktop.
Save Achie72/fc07b272f2ce5a6b0bb2af33456176a0 to your computer and use it in GitHub Desktop.
Samurai Game Jam Devlog - One Last Swing #2 - Rock-Paper-Scissor Combat - PICO-8
-- inside update:
-- update opponent's attack timer
if enemy.timeLeftForAttack > 0 then
-- decrease the time till the opponent attacks
enemy.timeLeftForAttack -= 1
-- let them switch around randomly to juke
if (enemy.timeLeftForAttack > enemy.finalStanceHold) then
if rnd() > 0.9 then
enemy.stance = rnd({1,2,3})
end
else
enemy.x += 0.1
enemy.stance = enemy.finalStance
end
else
state = "clash"
sfx(2)
--resolve_duel()
end
-- clash is a placeholder state that handles
-- the lerping between the two warriors. Code courtesy of
-- fletchmakes! https://www.twitch.tv/fletchmakes
function update_clash()
-- see if we have a fighter to move into middle
local playerInPos,enemyInPos = false,false
if player.x < 24 then
player.x = lerp(player.x, 24, 0.4)
else
playerInPos = true
end
if enemy.x > 32 then
enemy.x = lerp(enemy.x, 32, 0.6)
else
enemyInPos = true
end
-- if not, they are in the middle, so resolve the
-- combat
if playerInPos and enemyInPos then
resolve_duel()
end
end
-- resolving is a simple check on stance values
function resolve_duel()
-- define which stance beats which
-- high -> mid
-- mid -> low
-- low -> high
-- stance 1 -> low
-- stance 2 -> mid
-- stance 3 -> high
-- if sword is not out, lose
-- high beats mid, mid beats low, or low beats high
if ((player.stance == 3) and (enemy.finalStance == 2))
or ((player.stance == 2) and (enemy.finalStance == 1))
or (((player.stance == 1) and (enemy.finalStance == 3))) then
state = "won"
score += 1
elseif not (player.stance == enemy.finalStance) then
state = "dead"
end
if (state == "dead") then
score = 0
end
if not ((state == "won") or (state == "dead")) then
state = "game"
reset_duel()
end
if not (player.holding) then state = "dead" 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