Created
June 13, 2020 08:38
-
-
Save amirrajan/fb2dac61ce2026bd4c617b2c5182a03e to your computer and use it in GitHub Desktop.
This file contains 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
class Star | |
attr_sprite | |
def initialize | |
@x = (1280 * rand) * -1 | |
@y = (720 * rand) * -1 | |
@s = 1 + rand * 3 | |
@w = 16 | |
@h = 16 | |
@path = "sprites/star.png" | |
end | |
def update | |
@x += @s | |
@y += @s | |
@x = 0 if @x > 1280 | |
@y = 0 if @y > 720 | |
end | |
end | |
def tick args | |
args.state.stars ||= 10000.map { Star.new } | |
args.outputs.background_color = [0, 0, 0] | |
args.outputs.solids << [0, 680, 100, 100, 255, 255, 255] | |
args.outputs.labels << [30, 710, "#{args.gtk.current_framerate}"] | |
if args.state.tick_count == 0 | |
args.outputs.static_sprites << args.state.stars | |
end | |
args.state.stars.each(&:update) | |
end | |
$gtk.reset seed: Time.now.to_i |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment