Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 35 additions & 7 deletions wolfentext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -415,14 +415,45 @@ def clear_buffer
#
def clear_screen( full = false )
puts "\e[2J" if full
puts "\e[0;0H"
move_to 0, 0
end

# Draws the current buffer to the screen.
#
def draw_buffer
puts @buffer.map { |b| b.join }.join( "\r\n" )
end

def move_to x, y
puts "\e[#{y};#{x}f"
end

def render( full = false )
clear_screen full

if @previous_render
burst_start = nil
chars = []
render_burst = -> {
next unless burst_start
move_to *burst_start
print chars
burst_start = nil
chars = []
}
@buffer.each_with_index do |line, y|
line.each_with_index do |char, x|
next render_burst if char == @previous_render[y][x]
burst_start ||= [x, y]
chars << char
end
render_burst
end
else
draw_buffer
end
@previous_render = @buffer.map(&:dup)
end

# Draws extra information onto HUD.
#
Expand All @@ -445,8 +476,7 @@ def draw_screen_wipe( type )
end
end

clear_screen true
draw_buffer
render true
sleep 0.25
end

Expand All @@ -455,8 +485,7 @@ def draw_screen_wipe( type )
@buffer[ i / @screen_width ][ i % @screen_width ] = Color.colorize( " ", Color::WHITE, @color_mode )

if j % ( 4 ** @color_mode ) == 0
clear_screen
draw_buffer
render
end
end

Expand All @@ -473,8 +502,7 @@ def draw_screen_wipe( type )
@buffer[ i / @screen_width ][ i % @screen_width ] = @backup_buffer[ i / @screen_width ][ i % @screen_width ]

if j % ( 4 ** @color_mode ) == 0
clear_screen
draw_buffer
render
end
end
end
Expand Down