Skip to content

Instantly share code, notes, and snippets.

@Achie72
Last active August 10, 2022 10:18
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/d672da5ecd047c81883ef07d7c3b77c6 to your computer and use it in GitHub Desktop.
Save Achie72/d672da5ecd047c81883ef07d7c3b77c6 to your computer and use it in GitHub Desktop.
Attack Mission declaration for enemies
-- Created for my Ko-fi article about my game
-- dev journey with my witch smup game
-- https://ko-fi.com/post/ENGHUN-Unnamed-Project--Making-Abilites-Look-B-X8X2DH3X2
-- Code is In progress, heavily not optimized
-- and geared towards readability until PICO_8
-- token counts come into play
elseif enemy.mission == "attack" then
if enemy.tpe == 1 then
--bats go only forward with up and down
-- flying movement as they flap their wings
enemy.sx = -1.7
enemy.sy = sin(t/20)
-- with sin() function we a negative trend in values
-- leading to our enemies leaving the play area so we
-- slightly guide them to the center
-- trend toward center from top
if enemy.y < 40 then
enemy.sy += 1
end
-- trend toward center from bot
if enemy.y > 88 then
enemy.sy -= 1
end
elseif enemy.tpe == 2 then
--crows will fly at you
enemy.sx = -2.6
if (not enemy.changed) then
-- their normal movement
enemy.sy = sin(t/10)
if enemy.y < 20 then
enemy.sy += 0.5
end
end
-- and if they are close enough they will turn sharply
-- by applying values to sy based on their y (height) coordinate
-- after that we set the guard so they don't change again
if ((enemy.x < player.x + 20) and (not enemy.changed)) then
if enemy.y < 64 then
enemy.sy = 2.7
else
enemy.sy = -2.7
end
enemy.changed = true
end
elseif enemy.tpe == 3 then
--ghosts are slowly moving tanky enemies
enemy.sx = -0.4
enemy.sy = sin(t/30)
-- trend toward center from top
if enemy.y < 32 then
enemy.sy += 1 -(enemy.y/32)
end
-- trend toward center from bot
if enemy.y > 88 then
enemy.sy -= (enemy.y - 88)/32
end
elseif enemy.tpe == 4 then
enemy.sx = -2
enemy.sy = sin(rnd(30))+0.5
-- trend toward center from top
if enemy.y < 40 then
enemy.sy += 1 - (enemy.y/40)
end
-- trend toward center from bot
if enemy.y > 88 then
enemy.sy -= (enemy.y-88)/32
end
elseif enemy.tpe == 5 then
-- The Eyes are stationary enemies which will shoot at you
-- with their weird pattern
-- attack patterns explained in the article
if (time()%1 == 0) then
attack_with_patern(enemy, "double", 0.5)
sfx(4)
enemy.shoot = 5
end
if (time()%2 == 0) then
attack_with_patern(enemy, "single")
sfx(4)
enemy.shoot = 5
end
end
move(enemy)
elseif enemy.mission == "up-down-attack" then
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment