Created
January 6, 2020 00:52
-
-
Save amirrajan/4b36d0f14f3a870f345d897e9217066a to your computer and use it in GitHub Desktop.
DragonRuby Mode 7
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
def defaults args | |
args.outputs.static_background_color = [0, 0, 0] | |
args.grid.origin_center! | |
args.state.texture_size = 64 | |
args.state.texture_path = 'sprites/square-orange.png' | |
return if args.state.squares | |
cols = args.grid.w.idiv(args.state.texture_size) + 2 | |
rows = args.grid.h.half.idiv(args.state.texture_size) * 2 | |
args.state.squares = cols.numbers.product(rows.numbers).map do |x, y| | |
{ | |
x: args.grid.left - args.state.texture_size + | |
x * args.state.texture_size, | |
y: args.grid.bottom - args.state.texture_size + | |
y * args.state.texture_size, | |
w: args.state.texture_size, | |
h: args.state.texture_size | |
} | |
end | |
end | |
def calc args | |
args.state.squares.each do |s| | |
s.y += 1 | |
s.y = args.grid.bottom - args.state.texture_size if s.y > 0 | |
end | |
end | |
def render args | |
args.render_target(:scene).sprites << args.state.squares.map do |s| | |
s.merge(path: args.state.texture_path) | |
end | |
slices = 720 / 4 | |
slice_height = args.grid.h / slices | |
args.outputs.sprites << slices.map_with_index do |i| | |
scale = (args.grid.bottom + i * slice_height) / args.grid.bottom | |
scale = 0 if scale < 0 | |
{ | |
x: args.grid.left * scale, | |
y: ((i * slice_height) + args.grid.bottom), | |
w: 1280 * scale, | |
h: slice_height, | |
path: :scene, | |
tile_x: 0, | |
tile_h: slice_height, | |
tile_y: args.grid.h - (i * slice_height), | |
tile_w: args.grid.w, | |
r: 255 * scale, | |
g: 255 * scale, | |
b: 255 * scale, | |
} | |
end | |
args.outputs.primitives << [args.grid.left, args.grid.bottom, 65, 30, 255, 255, 255].solid | |
args.outputs.primitives << [args.grid.left + 10, args.grid.bottom + 24, "%.2f" % args.gtk.current_framerate].label | |
end | |
def tick args | |
defaults args | |
calc args | |
render args | |
end | |
$gtk.reset |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment