Skip to content

Instantly share code, notes, and snippets.

$gtk.reset seed: Time.now.to_i
#puts "++++++++++++++++++ RESET +++++++++++++++++++++"
=begin
Creates a few different effects using particles
explode: fly apart dramatically and burn with flaming colours
melt: fall apart in a downward direction while turning toxic green
disintegrate: break apart less dramatically without burning colours
@oeloeloel
oeloeloel / main.rb
Created September 12, 2020 14:28
Bresenham's Line Algorithm in DragonRuby
# brief demonstration of Bresenham's line algorithm in DragonRuby
BRUSH_SIZE = 16
def tick(args)
args.state.last_mouse_x ||= args.inputs.mouse.x
args.state.last_mouse_y ||= args.inputs.mouse.y
# set the start of the line
x0 = args.state.last_mouse_x
@oeloeloel
oeloeloel / main.rb
Last active September 17, 2020 19:04
[DragonRuby] Recycle Symbols for Render Targets (general idea)
$gtk.reset
def tick args
args.state.rt_symbols_recycle_bin = []
args.state.rt_symbol_counter = 0
if args.state.tick_count == 0
# get a couple of fresh symbols
symbol1 = get_rt_symbol(args)
@oeloeloel
oeloeloel / main.rb
Created October 1, 2020 15:12
TeenyTiny DragonRuby MiniGameJam SimpleSample
# TeenyTiny DragonRuby MiniGameJam SimpleSample
# This is a simple sample game that takes 20 seconds to win.
SMALL_SHAPE_SIZE = 200
LARGE_SHAPE_SIZE = 300
VIEW_WIDTH = $args.grid.w
VIEW_HEIGHT = $args.grid.h
H_CENTRE = VIEW_WIDTH / 2
V_CENTRE = VIEW_HEIGHT / 2
WIN_SCORE = 10
@oeloeloel
oeloeloel / main.rb
Created October 2, 2020 18:40
Bresenham Circle in DragonRuby
# Bresenham circle for DragonRuby (basic)
RED = [255, 0, 0]
def put_pixel(args, x, y, c)
args.outputs.solids << [x, y, 1, 1, *c]
end
def drawCircle(args, xc, yc, x, y)
put_pixel(args, xc + x, yc + y, RED)
@oeloeloel
oeloeloel / main.rb
Created April 3, 2021 05:05
Breakout made quickly
$gtk.reset
def tick args
defaults args
handle_input args
calc args
render args
end
def handle_input args
@oeloeloel
oeloeloel / main.rb
Last active July 2, 2021 20:41
Remove specified background colour from sprite/spritesheet
# cromakey no chromakey
# removes a specified background colour from a spritesheet
# by making it transparent and exports it as a new file.
# change these values then run in DragonRuby
# path to spritesheet
INPUT_FILE = '/sprites/chroma-test-input.png'
# path to export file
OUTPUT_FILE = '/sprites/chroma-test-output.png'
@oeloeloel
oeloeloel / main.rb
Last active July 6, 2021 18:15
Supersampling for even rotation of odd sized sprites
# supersampling for fancy sprite rotation
# solves uneven rotation of odd-sized sprites
# using an upscaled render target
def tick(args)
args.state.size ||= 7 # width/height of sprite (odd)
args.state.upsample ||= 8 # 2 minimum, 8 is better
args.state.path ||= 'sprites/rotate5.png' # path to sprite
args.state.upsample_size ||= args.state.size * args.state.upsample
@oeloeloel
oeloeloel / main.rb
Created August 3, 2021 18:09
Modification of KFischer's Array Splat Performance Test
class AnObject
attr_reader :a, :b, :c, :d, :e, :f
def initialize
@a = 1
@b = 1
@c = 1
@d = 1
@e = 1
@f = 1
end
@oeloeloel
oeloeloel / ext.c
Last active November 26, 2021 07:11
DragonRuby Pixel Arrays with C Extensions. Quick and Dirty example.
/*
DragonRuby C Extension Pixel Array
Written by @Akzidenz-Grotesk (with help from @AlexDenisov & @Kenneth | CANICVS)
Demonstrates some quick and pretty dirty image filters
Loads image files into Pixel Array
Performs image manipulation every tick
Returns a modified 100x100 pixel image to DragonRuby
*/
#ifndef NULL