Created
February 25, 2024 19:08
-
-
Save Achie72/cc93f9603bc80cfbc2161cdd007258f1 to your computer and use it in GitHub Desktop.
One Last Swing - Tutorial code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- here we modifiy the creation to accomodate | |
-- the tutorial, where we are gonna show the | |
-- player which stance beats what | |
if tutorial > 0 then | |
tutorial -= 1 | |
if tutorial > 0 then | |
-- based on which tutorial we are in, set the enemy stance so that is beatable | |
-- by the other table inside the players code when we are about to resolve the fight | |
local tutorialBeatTable = {MID_STANCE,LOW_STANCE, MID_STANCE, HIGH_STANCE} | |
enemy.stance = tutorialBeatTable[tutorial] | |
enemy.finalStance = tutorialBeatTable[tutorial] | |
end | |
end | |
-- now inside the update function | |
-- next to all the regular code we inject | |
-- we inject tutorial here, basically we wait for the player to | |
-- hold the good stance before the clash | |
local tutorialGuard = true | |
if tutorial > 1 then | |
tutorialGuard = false | |
-- grab the stance that beats the stance set in tutorial mode | |
-- in create new duel | |
local tutorialBeatStance = {nil,MID_STANCE, HIGH_STANCE, LOW_STANCE} | |
-- if the player is holding it, trigger the clash state instead of doing the | |
-- animations and such | |
if (player.stance == tutorialBeatStance[tutorial]) and (player.holding) then | |
tutorialGuard = true | |
enemy.timeLeftForAttack = enemy.finalStanceHold | |
state = "clash" | |
music(-1) | |
sfx(2) | |
end | |
end | |
-- update opponent's attack timer | |
if (tutorialGuard) then | |
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 step back time | |
-- here they already hold their final stance | |
enemy.x += 0.1 | |
enemy.stance = enemy.finalStance | |
end | |
-- since some enemies are to fast to step back a correct ammount | |
-- (more than 1 px), let the blade also flash so we can see the | |
-- attack coming | |
if enemy.timeLeftForAttack < 10 then | |
enemy.shineBlade = flr(enemy.timeLeftForAttack%2) | |
end | |
else | |
-- if timer is over, trigger the clash state | |
-- this is the samurai runing into each other | |
-- anime | |
state = "clash" | |
music(-1) | |
sfx(2) | |
end | |
end | |
-- after each tutorial stage we decrease the tutorial counter | |
-- and in the draw we print the isntruction to the player: | |
-- tutorial print based on which stage we are in the | |
-- tutorial we start at 4 | |
if (state == "game") and (tutorial > 0) then | |
local tutorialTextTable = { | |
{"wait for them","and counter"}, | |
{"on low,","swing middle"}, | |
{"if middle,","swing above"}, | |
{"if high,","swing below"} | |
} | |
local titleText ="" | |
if tutorial == 4 then titleText ="master said:" end | |
print_outline(titleText, 32-#titleText*2, 2, 7, 11) | |
print_outline(tutorialTextTable[tutorial][1],32-#tutorialTextTable[tutorial][1]*2, 10, 7, 11) | |
print_outline(tutorialTextTable[tutorial][2],32-#tutorialTextTable[tutorial][2]*2, 18, 7, 11) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment