2022-05-31 01:37:31 +02:00
|
|
|
require 'app/game.rb'
|
2022-05-30 11:56:28 +02:00
|
|
|
|
|
|
|
MAX_X = 40
|
|
|
|
MAX_Y = 24
|
|
|
|
|
|
|
|
BLOCK_SIZE = (1280/MAX_X).round
|
|
|
|
|
|
|
|
INPUT = [
|
|
|
|
[9,9],
|
|
|
|
[10,10],
|
|
|
|
[9,11],
|
|
|
|
[11,11],
|
|
|
|
[9,12],
|
|
|
|
[11,12],
|
|
|
|
[13,13],
|
|
|
|
[14,13],
|
|
|
|
[15,13],
|
|
|
|
[16,13],
|
|
|
|
[16,15],
|
|
|
|
[16,16],
|
|
|
|
[17,17],
|
|
|
|
]
|
|
|
|
|
2022-05-31 01:37:31 +02:00
|
|
|
SPEED = 0.05 # every second
|
2022-05-30 11:56:28 +02:00
|
|
|
TICK_FOR_STEP = (SPEED * 60).round
|
|
|
|
|
|
|
|
|
2022-05-31 01:37:31 +02:00
|
|
|
def tick args
|
2022-05-30 11:56:28 +02:00
|
|
|
args.outputs.labels << [640, 500, 'Conways game of life', 5, 1]
|
|
|
|
# args.outputs.labels << [640, 460, 'Go to docs/docs.html and read it!', 5, 1]
|
|
|
|
# args.outputs.labels << [640, 420, 'Join the Discord! https://discord.dragonruby.org', 5, 1]
|
|
|
|
# args.outputs.sprites << [576, 280, 128, 101, 'dragonruby.png']
|
|
|
|
game = args.state.game
|
|
|
|
if game.nil?
|
2022-05-31 01:37:31 +02:00
|
|
|
game = Game.new(INPUT)
|
2022-05-30 11:56:28 +02:00
|
|
|
args.state.game = game
|
|
|
|
end
|
|
|
|
|
|
|
|
args.outputs.solids << [
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
MAX_X*BLOCK_SIZE,
|
|
|
|
MAX_Y*BLOCK_SIZE,
|
|
|
|
164,
|
|
|
|
212,
|
|
|
|
220,
|
|
|
|
128]
|
|
|
|
|
|
|
|
if args.state.tick_count % TICK_FOR_STEP == 0
|
|
|
|
game.tick
|
|
|
|
end
|
|
|
|
|
2022-05-31 01:37:31 +02:00
|
|
|
live_cells = game.live_cells
|
|
|
|
live_cells.each do |x,y|
|
|
|
|
args.outputs.solids << [
|
|
|
|
x*BLOCK_SIZE,
|
|
|
|
y*BLOCK_SIZE,
|
|
|
|
BLOCK_SIZE,
|
|
|
|
BLOCK_SIZE,
|
|
|
|
219,
|
|
|
|
163,
|
|
|
|
211,
|
|
|
|
255]
|
2022-05-30 11:56:28 +02:00
|
|
|
end
|
|
|
|
|
2022-05-31 01:37:31 +02:00
|
|
|
args.outputs.labels << [640, 600, "Round ##{game.tick_count}", 5, 1]
|
|
|
|
args.outputs.labels << [640, 700, "Tick count ##{args.state.tick_count}", 5, 1]
|
|
|
|
args.outputs.labels << [10, 710, "framerate: #{args.gtk.current_framerate.round}"]
|
2022-05-30 11:56:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
# render
|
|
|
|
# X Y WIDTH HEIGHT RED GREEN BLUE ALPHA
|
|
|
|
|
|
|
|
end
|