-
-
Save domgetter/fa666207c7927e6103b4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Auspice | |
class BottomFeeder | |
attr_accessor :x, :y, :z, :in, :out | |
def initialize(size,w,h) | |
@font = Gosu::Font.new(size,:name => DAT+'ttfs/ATComputer.ttf') | |
@rows = ((h / size)+size) | |
@cols = (w / @font.text_width('_',1)) | |
@size = size | |
@dtext = [''] | |
@in = '' | |
@out = '' | |
@tcolor = 0xee00ffff | |
@x = 0 | |
@y = 0 | |
@z = 0 | |
@w = w | |
@h = h | |
@pos = 0 | |
@dy = 0 | |
@dh = @h | |
end | |
def update | |
if a = @in[@pos] | |
#puts "#{a}, #{a.class}, #{a.length}" | |
@dtext[-1] << a | |
@pos += 1 | |
if @dtext[-1].size >= @cols | |
if x = @dtext[-1].rindex(' ') | |
@dtext << (@dtext[-1][(x+1)..-1]) | |
@dtext[-2] = @dtext[-2][0..x] | |
else | |
@dtext << [''] | |
end | |
@dh = @h + @size | |
@dy = -1 | |
end | |
if a == "\n" | |
@dtext << [''] | |
@dh = @h + @size | |
@dy = -1 | |
end | |
if @dh <= @h | |
@dy = 0 | |
end | |
@dh += @dy | |
end | |
end | |
def draw | |
Gosu.draw_quad(@x,@y,0x4000eeaa,@x+@w,@y,0x4000aaee,@x+@w,@y+@h,0x4000aaee,@x,@y+@h,0x40eeaaee,@z,:additive) | |
Gosu.clip_to(@x,@y,@w,@h) { | |
([@rows,@dtext.size].min-1).times {|l| | |
@font.draw(@dtext[-(l+1)], @x, @y+(@dh-(@size*(l+1))), @z, 1, 1, @tcolor, :additive) | |
} | |
} | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment