Skip to content

Instantly share code, notes, and snippets.

@amirrajan
Created June 13, 2020 08:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amirrajan/fb2dac61ce2026bd4c617b2c5182a03e to your computer and use it in GitHub Desktop.
Save amirrajan/fb2dac61ce2026bd4c617b2c5182a03e to your computer and use it in GitHub Desktop.
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