Skip to content

Instantly share code, notes, and snippets.

@vidarh
Created February 25, 2024 18:27
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 vidarh/1def2a38a74cf3923449612d1d1bdb80 to your computer and use it in GitHub Desktop.
Save vidarh/1def2a38a74cf3923449612d1d1bdb80 to your computer and use it in GitHub Desktop.
Stupidly basic and ugly terrain generation for DragonRuby
def tick args
args.outputs.background_color = [0,0,0]
args.outputs.labels << {x: 20, y: 700, text: "Landscape Test", r: 255, g: 255, b: 255 }
args.pixel_array(:col).width = 1
args.pixel_array(:col).height = 200
px = args.pixel_array(:col).pixels
200.times do |y|
y = y.abs.floor & 0xff
col = y << 8
if y < 100
col |= y
end
if y < 50
col |= y << 16
end
if y < 10
col = 0xffffff- (0x010101*(y)*10)
end
if y == 0
col = 0x0
end
if y > 150
col = 0xff8000
end
px[y] = 0xff000000 | col
end
$sprites = []
cw = 8
f = 0.6
col = (1400/cw).floor
$z = []
srand(-1000)
50.times do |y|
xoff = Math.sin(y)*60+rand(30)-Math.sin(y/2.5+1.5)*20
yoff = 0 #Math.sin(y*5)*10
col.times do |c|
x = c*cw*f
h = Math.sin(x/50+y/5)*50 +
Math.sin(y/40*3.14*2*x/256)*80 +
Math.sin((x*2+y*10.2)/25+y/1.5)*20 +
Math.sin((x+200)/100+ y/40)*50 +
95 + rand(10)
ty = h #(200 - h*2 + rand(5)).clamp(0,200)
$sprites << {
x: c*cw-xoff, y: 450-y*10-yoff, w: cw+4, h: h.abs.floor,
tile_x: 0, tile_y: (200-ty).clamp(2,200), tile_w: 1,
flip_vertically: false,
tile_h: ty-h/5+rand(10), #+rand(20)+Math.sin(x/100+rand(2))/10,
path: :col }
end
end
args.outputs.labels << { x: 10, y: 30, text: $gtk.args.gtk.current_framerate.to_s, r: 255, g: 128, b: 128}
args.outputs.background_color = [0,0,255]
args.outputs.sprites << $sprites
end
@vidarh
Copy link
Author

vidarh commented Feb 25, 2024

You can consider this to be public domain, or under the MIT license, whichever you prefer and/or is valid where you are.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment