Skip to content

Instantly share code, notes, and snippets.

@Achie72
Created January 23, 2024 16:53
Show Gist options
  • Save Achie72/9eb868ba5c6ca7be43dd0cfe9e60b163 to your computer and use it in GitHub Desktop.
Save Achie72/9eb868ba5c6ca7be43dd0cfe9e60b163 to your computer and use it in GitHub Desktop.
Samurai Game Jam Devlog - One Last Swing #2 - Drawing Samurai
-- draw a samurai on the screen at _x and _y positions
-- _color holds a two element array for the palette swap
-- _head holds the head sprite of the samurai
-- _flip indicates two horizontally flip the whole thing
-- for opponent drawing
function draw_samurai(_x, _y, _color, _stance, _head, _flip)
-- offset for heads, because the base sprite is not symetrical.
local headOffset = {3,1}
if _flip then headOffset = {5,1} end
-- default swap colors
local resetDark, resetLight = 5,6
-- mod the new _colors
for x=0,15,1 do
for y=0,15,1 do
-- jump to the sprite's spritesheet space. We go from 0-15 because
-- we are using 16x16 sprites, and the *8 down because sprite id 1
-- starts at x=8 position in the spritesheet.
-- Grab the color from the spritesheet and then replace them for the new ones
if sget( _stance*8 + x, y) == resetDark then
sset( _stance*8 + x, y, _color[1])
end
if sget( _stance*8 + x, y) == resetLight then
sset( _stance*8 + x, y, _color[2])
end
end
end
-- draw the clothes!
spr(_stance, _x, _y, 2, 2, _flip,false)
-- reset the colors
for x=0,15,1 do
for y=0,15,1 do
if sget( _stance*8 + x, y) == _color[1] then
sset( _stance*8 + x, y, resetDark)
end
if sget( _stance*8 + x, y) == _color[2] then
sset( _stance*8 + x, y, resetLight)
end
end
end
-- draw the head sprite from the collection, they start at 128.
spr(128+_head, _x+headOffset[1], _y+headOffset[2], 1 , 1, _flip, false)
-- draw the hand and sword.
-- we need all this so we can layer for ex: beards upon top of the clothes
-- but the swords still need to be on top of the newly drawn heads.
spr(_stance+32, _x, _y, 2, 2, _flip,false)
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