# Pastebin U2aJZd9g use Raylib::Bindings; use NativeCall; ## Initialization constant screen-width = 1024; constant screen-height = 768; init-window(screen-width, screen-height, "Blizzard Simulator"); my int32 $null; #my $one-pointer = CArray[int32].new; #$one-pointer[0] = 1; my $one-pointer = nativecast(Pointer[int32], 1); my int32 $one = 1; my int32 $zero = 0; my int32 $size = 48; my $code-points = CArray[int32].new; my int32 $code-point-a = load-codepoints("❆", $one-pointer); $code-points[0] = $code-point-a; #my $font = load-font-ex("/Users/Longwalker/Library/Fonts/PragmataProI_0829.ttf", $size, $zero, $zero); my $snow-a = load-font-ex("/Users/Longwalker/Library/Fonts/PragmataProI_0829.ttf", $size, $code-points, $one); my $s = load-utf8($code-points, $one); dd $s; my $white = init-white; my $black = init-black; ## Implementation Classes class Snowflake { # Singleton # my @flakes = <❆>; my @flakes = <*>; my %textures; method initialize-textures { for @flakes -> $flake { # my $image = image-text($flake, 32, $white); my $image = image-text-ex($snow-a, $flake, 32e0, 0e0, $white); %textures«$flake» = load-texture-from-image($image); unload-image($image); } } method unload-textures { unload-texture($_) for %textures.values; } # Object has $.flake = @flakes.roll; has Vector2 $.pos is required is rw; has $.weight = (1,1.5,2.5).roll; method texture { %textures«$!flake» } } class SnowfallLayer { has @.snowflakes; has Num $.scale is required; has Vector2 $.wind is rw = Vector2.init(1.001e0 + (0.015e0 * $!scale), 1.008e0); has Bool $.started = False; has Supply $!update-supply = Supply.interval($!scale / 10); has Supply $!more-supply = Supply.interval($!scale * 1.5, $!scale); submethod TWEAK() { self!fill-snowflakes; $!update-supply.act: { $!started && @!snowflakes.map: { $_.pos.y = ($_.pos.y + (^10).roll * $_.weight * $!scale) * $!wind.y; $_.pos.x = $_.pos.x * $!wind.x; } }; $!more-supply.act: { $!started && self!fill-snowflakes }; } method !fill-snowflakes() { @!snowflakes = @!snowflakes.grep: *.pos.y <= screen-height; for (^screen-width).pick((1..32).roll - 8 * $!scale) -> $x { my $pos = Vector2.init($x.Num, 0e0); @!snowflakes.push: Snowflake.new: :$pos; } } method start { $!started = True } method render { for @!snowflakes -> $flake { draw-texture-ex($flake.texture, $flake.pos, 0e0, $!scale, $white); } } } class SnowfallRenderer { has @.layers; submethod TWEAK { constant scales = (0.1, 0.2, 0.2, 0.3, 0.3, 0.4)>>.Num; for scales -> $scale { @!layers.push: SnowfallLayer.new: :$scale; } } method start { @!layers.map: *.start } method render { @!layers.map: *.render } } ## Rendering Snowflake.initialize-textures; my $renderer = SnowfallRenderer.new; $renderer.start; my $flake = Snowflake.new: pos => Vector2.init((screen-width/2).Num,(screen-height/2).Num); while !window-should-close { begin-drawing; clear-background($black); $renderer.render; end-drawing; } Snowflake.unload-textures; close-window;