diff --git a/ruby/bin/gosuhunt b/ruby/bin/gosuhunt index 303e323..70e8bec 100755 --- a/ruby/bin/gosuhunt +++ b/ruby/bin/gosuhunt @@ -7,30 +7,32 @@ require 'minehunt' class GosuHunt < Gosu::Window def initialize( number_of_mines = 20 ) - @scale = 4 + @scale = 3 @sprite_size = 6 - super ( @scale * ( @sprite_size * 16 ) ) + 16 + @scale, - ( @scale * ( @sprite_size * 8 ) ) + 20 + 8 + @scale - - self.caption = 'Gosu Hunt' - @number_of_mines = number_of_mines @field = MineHunt::Board.new( @number_of_mines ) @finished = false @state = { dead: false, victory: false } @font = Gosu::Font.new( 20 ) - @images = { explorer: Gosu::Image.from_blob( @sprite_size, @sprite_size, bits_to_rgbas( '000000001100011110011110001100000000' ) ), - dead_explorer: Gosu::Image.from_blob( @sprite_size, @sprite_size, bits_to_rgbas( '100001010010001100001100010010100001' ) ), - door: Gosu::Image.from_blob( @sprite_size, @sprite_size, bits_to_rgbas( '010101101010' ) * ( @sprite_size / 2 ) ), - mine: Gosu::Image.from_blob( @sprite_size, @sprite_size, bits_to_rgbas( '111111110011100001100001110011111111' ) ), - cell: Gosu::Image.from_blob( @sprite_size, @sprite_size, bits_to_rgbas( '1' ) * @sprite_size * @sprite_size ), - visited_cell: Gosu::Image.from_blob( @sprite_size, @sprite_size, bits_to_rgbas( '0' ) * @sprite_size * @sprite_size ) } + @images = { explorer: Gosu::Image.from_blob( @sprite_size * @scale, @sprite_size * @scale, bits_to_rgbas( '000000001100011110011110001100000000' ) ), + dead_explorer: Gosu::Image.from_blob( @sprite_size * @scale, @sprite_size * @scale, bits_to_rgbas( '100001010010001100001100010010100001' ) ), + door: Gosu::Image.from_blob( @sprite_size * @scale, @sprite_size * @scale, bits_to_rgbas( '010101101010' * ( @sprite_size / 2 ) ) ), + mine: Gosu::Image.from_blob( @sprite_size * @scale, @sprite_size * @scale, bits_to_rgbas( '111111110011100001100001110011111111' ) ), + cell: Gosu::Image.from_blob( @sprite_size * @scale, @sprite_size * @scale, bits_to_rgbas( '1' * @sprite_size * @sprite_size ) ), + visited_cell: Gosu::Image.from_blob( @sprite_size * @scale, @sprite_size * @scale, bits_to_rgbas( '0' * @sprite_size * @sprite_size ) ) } + + super ( ( @sprite_size + 1 ) * @field.width * @scale ) + @scale, + ( ( @sprite_size + 1 ) * @field.height * @scale ) + @scale + 20 + + self.caption = 'Gosu Hunt' end def bits_to_rgbas( bits ) - bits.gsub( '0', "\0\0\0\0" ).gsub( '1', "\255\255\255\255" ) + bits.scan(/.{#{@sprite_size}}/).map do |line| + line.gsub( '0', "\0\0\0\0" * @scale ).gsub( '1', "\255\255\255\255" * @scale ) * @scale + end.join end def new_level @@ -104,11 +106,9 @@ class GosuHunt < Gosu::Window @images[:mine] else @images[:cell] - end ).draw ( @scale * ( x * @sprite_size ) ) + x + @scale, - ( @scale * ( y * @sprite_size ) ) + 20 + y + @scale, - 0, - @scale, - @scale + end ).draw ( ( @sprite_size + 1 ) * x * @scale ) + @scale, + ( ( @sprite_size + 1 ) * y * @scale ) + @scale + 20, + 0 end end end