Created
July 27, 2025 03:26
-
-
Save FCO/bde2567a11fb2c6c3664c3745a0f8410 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use Raylib::Bindings; | |
| use ECS; | |
| constant $screen-width = 1024; | |
| constant $screen-height = 450; | |
| my $white = init-white; | |
| my $background = init-skyblue; | |
| init-window($screen-width, $screen-height, "Bouncing Camelias"); | |
| my $string = "./camelia.png"; | |
| my $camelia = load-image($string); | |
| my $camelia-height = $camelia.height; | |
| my $camelia-width = $camelia.width; | |
| my $texture = load-texture-from-image($camelia); | |
| unload-image($camelia); | |
| set-target-fps(60); | |
| END { | |
| unload-texture($texture); | |
| close-window; | |
| } | |
| my $world = world { | |
| component position => Vector2; | |
| component velocity => Vector2; | |
| entity "camelia"; | |
| system "move", -> :$position!, :$velocity! { | |
| from-call -> Num $delta { | |
| $position.x += $velocity.x * $delta; | |
| $position.y += $velocity.y * $delta; | |
| } | |
| } | |
| system "bounce", -> :$position! where *.y >= $screen-height - $camelia-height.Num, :$velocity! where *.y > 0 { | |
| $velocity.y *= -.8 | |
| } | |
| system "gravity", -> :$velocity! { | |
| from-call -> Num $delta { | |
| $velocity.y += 100 * $delta; | |
| } | |
| } | |
| system "draw", -> :$position! { | |
| draw-texture-v $texture, $position, $white; | |
| } | |
| system-group "physics", <move gravity bounce>; | |
| } | |
| until window-should-close { | |
| if (is-mouse-button-pressed MOUSE_BUTTON_LEFT) { | |
| $world.new-camelia: | |
| :position(Vector2.init: | |
| get-mouse-position.x - $camelia-width/2, | |
| get-mouse-position.y - $camelia-height/2, | |
| ), | |
| :velocity(Vector2.init: 0e0, 0e0), | |
| ; | |
| } | |
| $world.physics: get-frame-time; | |
| begin-drawing; | |
| clear-background $background; | |
| $world.draw; | |
| draw-fps 10, 10; | |
| end-drawing; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment