pixelfaucet/examples/animated_sprite.cr

33 lines
812 B
Crystal
Raw Normal View History

2022-01-25 04:05:04 +01:00
require "../src/game"
require "../src/sprite"
require "../src/pixel_text"
2022-01-26 05:32:48 +01:00
require "../src/animation"
2022-01-25 04:05:04 +01:00
module PF
class SpriteExample < Game
@text : PixelText = PixelText.new("assets/pf-font.png")
def initialize(*args, **kwargs)
super
2022-01-26 05:32:48 +01:00
@person = Animation.new("assets/walking.png", 32, 64, 10)
@cat = Animation.new("assets/black-cat.png", 18, 14, 15)
2022-01-25 04:05:04 +01:00
end
def update(dt, event)
2022-01-26 05:32:48 +01:00
@person.update(dt)
@cat.update(dt)
2022-01-25 04:05:04 +01:00
end
def draw
clear(60, 120, 200)
2022-01-26 05:32:48 +01:00
@text.draw_to(screen, "Frame: #{@person.frame}", 5, 5)
fill_rect(0, 65, width - 1, height - 1, Pixel.new(100, 100, 100))
@person.draw_to(screen, (viewport // 2) - @person.size // 2)
@cat.draw_to(screen, 30, 56)
2022-01-25 04:05:04 +01:00
end
end
end
game = PF::SpriteExample.new(120, 80, 5)
game.run!