Skip to content

Instantly share code, notes, and snippets.

@st235
Last active January 26, 2025 11:39
Show Gist options
  • Save st235/e064ac5b297ef2ee69fbcbd84bca2cbc to your computer and use it in GitHub Desktop.
Save st235/e064ac5b297ef2ee69fbcbd84bca2cbc to your computer and use it in GitHub Desktop.
Animated Crow?!
WINDOW_WIDTH = 512
WINDOW_HEIGHT = 916
CROW_WIDTH = 48
CROW_HEIGHT = 48
CROW_ANIMATION_CHANGE = 0.25
function engine.start()
engine.window.setTitle("Animated Crow?!")
engine.window.setWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT)
-- See /gameplay/resources
font = engine.graphics.newFont("PixeloidSans.ttf", 72)
greeting_text = engine.graphics.newText(font, "Crow(bar)", { 14, 17, 17 })
crow_atlas = engine.graphics.loadTexture("Crow.png")
crow_animation_frames = {
engine.graphics.newQuad(0, 0, CROW_WIDTH, CROW_HEIGHT),
engine.graphics.newQuad(48, 0, CROW_WIDTH, CROW_HEIGHT),
engine.graphics.newQuad(96, 0, CROW_WIDTH, CROW_HEIGHT),
engine.graphics.newQuad(144, 0, CROW_WIDTH, CROW_HEIGHT),
engine.graphics.newQuad(0, 48, CROW_WIDTH, CROW_HEIGHT),
engine.graphics.newQuad(48, 48, CROW_WIDTH, CROW_HEIGHT),
engine.graphics.newQuad(96, 48, CROW_WIDTH, CROW_HEIGHT),
engine.graphics.newQuad(144, 48, CROW_WIDTH, CROW_HEIGHT),
engine.graphics.newQuad(0, 96, CROW_WIDTH, CROW_HEIGHT),
engine.graphics.newQuad(48, 96, CROW_WIDTH, CROW_HEIGHT),
engine.graphics.newQuad(96, 96, CROW_WIDTH, CROW_HEIGHT),
engine.graphics.newQuad(144, 96, CROW_WIDTH, CROW_HEIGHT),
engine.graphics.newQuad(0, 144, CROW_WIDTH, CROW_HEIGHT),
engine.graphics.newQuad(48, 144, CROW_WIDTH, CROW_HEIGHT),
engine.graphics.newQuad(96, 144, CROW_WIDTH, CROW_HEIGHT),
engine.graphics.newQuad(144, 144, CROW_WIDTH, CROW_HEIGHT),
}
crow_animation_timer = 0
crow_animation_frame = 0
end
function engine.update(dt)
crow_animation_timer = crow_animation_timer + dt
if (crow_animation_timer > CROW_ANIMATION_CHANGE) then
crow_animation_frame = (crow_animation_frame + 1) % #crow_animation_frames
crow_animation_timer = 0
end
end
function engine.draw()
engine.graphics.clear(210, 210, 207)
engine.graphics.draw(greeting_text,
(WINDOW_WIDTH - greeting_text:width()) // 2,
(WINDOW_HEIGHT - greeting_text:height()) // 2 + 164,
15)
engine.graphics.draw(crow_atlas,
crow_animation_frames[crow_animation_frame + 1],
(WINDOW_WIDTH - CROW_WIDTH) // 2,
(WINDOW_HEIGHT - CROW_HEIGHT) // 2)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment