pixelfaucet/examples/animated_sprite.cr

30 lines
713 B
Crystal
Raw Normal View History

2022-01-25 04:05:04 +01:00
require "../src/game"
require "../src/sprite"
2022-01-26 05:32:48 +01:00
require "../src/animation"
2022-01-25 04:05:04 +01:00
module PF
class SpriteExample < Game
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-02-04 06:09:09 +01:00
draw_string("Frame: #{@person.frame}", 5, 5)
2022-01-26 05:32:48 +01:00
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!