Last active
May 16, 2024 15:30
-
-
Save amirrajan/8269f53cc5cdeb4c07eba947c7873f3c to your computer and use it in GitHub Desktop.
DragonRuby Game Toolkit - Bunnymark - https://youtu.be/E_f7UkznMjY
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 Rabbit | |
def initialize x, y, w, h | |
@x = x | |
@dx = [1, -1].sample | |
@y = y | |
@dy = [1, -1].sample | |
@w = w | |
@h = h | |
@path = "sprites/wabbit_alpha.png" | |
@speed = rand * 10 | |
end | |
def move | |
@x += @speed * @dx | |
@y += @speed * @dy | |
if @x < 0 | |
@x = 0 | |
@dx = 1 | |
elsif @x > 1280 - @w | |
@x = 1280 - @w | |
@dx = -1 | |
end | |
if @y < 0 | |
@y = 0 | |
@dy = 1 | |
elsif @y > 720 - @h | |
@y = 720 - @h | |
@dy = -1 | |
end | |
end | |
def draw_override ffi_draw | |
move | |
ffi_draw.draw_sprite @x, @y, @w, @h, @path | |
end | |
end | |
def tick args | |
args.state.rabbits ||= [] | |
# every click adds 10k bunnies | |
if args.inputs.mouse.click | |
10000.times do | |
args.state.rabbits << Rabbit.new(1280 * rand, 720 * rand, 32, 32) | |
end | |
end | |
args.outputs.debug.watch GTK.current_framerate | |
args.outputs.debug.watch args.state.rabbits.length | |
args.outputs.sprites << args.state.rabbits | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment