Skip to content

Instantly share code, notes, and snippets.

@awfulcooking
Created July 4, 2022 13:34
Show Gist options
  • Save awfulcooking/56d0d000391daa170f10637dd12bc1dc to your computer and use it in GitHub Desktop.
Save awfulcooking/56d0d000391daa170f10637dd12bc1dc to your computer and use it in GitHub Desktop.
Frame stepping for DragonRuby
# Frame stepping for DragonRuby - MIT License - (c) mooff
#
# 1. Copy to your_game/lib/framestep.rb (and require it)
# 2. Add "return if FrameStep.tick" to your tick method
# 3. Press Ctrl-/ in-game to activate, then / to advance
#
# Version 1.1
# - Keep GTK tick count in step when frozen
module FrameStep
SCREENSHOT_PATH = 'freeze-frame.png'
class << self
attr_accessor :step
def toggle?
$inputs.keyboard.control && $inputs.keyboard.key_down.forward_slash
end
def advance?
$inputs.keyboard.key_down.forward_slash
end
def tick
if toggle?
@step = @step ? nil : 0
@did_cap = false
$inputs.clear
puts "(FrameStep) #{@step ? 'Enter' : 'Leave'}"
end
if @step
if advance?
@step += 1
@did_cap = false
puts "(FrameStep) Advance: #{@step}"
else
Kernel.tick_count -= 1
end
if !@did_cap
@did_cap = true
$outputs.screenshots << { x: 0, y: 0, w: $grid.w, h: $grid.h, path: SCREENSHOT_PATH }
$gtk.reset_sprite SCREENSHOT_PATH
return false
end
$outputs.sprites << [0, 0, $grid.w, $grid.h, SCREENSHOT_PATH]
return true
else
return false
end
end
end
end
def tick(args)
return if FrameStep.tick
update_state
render_game
end
def tick(args)
if $gtk.development?
render_cool_debug_overlay
return if FrameStep.tick
end
update
render
end
# Custom activation
def FrameStep.toggle?
$inputs.keyboard.key_down.home
end
def FrameStep.advance?
$inputs.keyboard.key_down.end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment