Skip to content

Instantly share code, notes, and snippets.

@xenobrain
Last active August 29, 2021 18:33
Show Gist options
  • Save xenobrain/1d2a736091f43634062f4434f265ee06 to your computer and use it in GitHub Desktop.
Save xenobrain/1d2a736091f43634062f4434f265ee06 to your computer and use it in GitHub Desktop.
class Renderer
attr_accessor(:background, :foreground, :overlay)
def initialize
@background = []
@foreground = []
@overlay = []
end
def draw_override(ffi_draw)
@background.shift.call(ffi_draw) until @background.empty?
@foreground.shift.call(ffi_draw) until @foreground.empty?
@overlay.shift.call(ffi_draw) until @overlay.empty?
end
def tick(args)
args.outputs.sprites << self
end
end
@renderer = Renderer.new
def draw_player
player = args.state.player
@renderer.foreground << proc |ffi|
ffi.draw_sprite(player.x, player.y, player.w, player.h, player.path)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment