pixelfaucet/examples/snow_scroll.cr

45 lines
830 B
Crystal
Raw Normal View History

2021-12-24 04:27:29 +01:00
require "../src/game"
class Snow < PF::Game
@pixels : Slice(UInt32)
@last_shift : Float64 = 0.0
def initialize(*args, **kwargs)
super
@pixels = @screen.pixels
2022-01-07 06:06:51 +01:00
clear(0, 0, 0x25)
2021-12-24 04:27:29 +01:00
end
def update(dt, event)
@last_shift += dt
end
def draw
if @last_shift >= 0.02
@last_shift = 0.0
@pixels.rotate!(-@width)
0.upto(@width - 1) do |x|
if rand(0..250) == 0
2022-01-07 06:06:51 +01:00
shade = rand(25_u8..255_u8)
@pixels[x] = PF::Pixel.new(shade, shade, shade).to_u32
2021-12-24 04:27:29 +01:00
else
2022-01-07 06:06:51 +01:00
@pixels[x] = 0x000025FF
2021-12-24 04:27:29 +01:00
end
end
end
0.upto(@height - 1) do |y|
if rand(0..2) == 0
row = Slice(UInt32).new(@pixels.to_unsafe + (y * @width), @width)
row.rotate!(rand(-1..1))
end
end
end
end
engine = Snow.new(600, 400, 2)
engine.run!