[gosuhunt] self-made interger scaling
This commit is contained in:
parent
af513c4d9a
commit
a1f0d62984
1 changed files with 18 additions and 18 deletions
|
@ -7,30 +7,32 @@ require 'minehunt'
|
||||||
|
|
||||||
class GosuHunt < Gosu::Window
|
class GosuHunt < Gosu::Window
|
||||||
def initialize( number_of_mines = 20 )
|
def initialize( number_of_mines = 20 )
|
||||||
@scale = 4
|
@scale = 3
|
||||||
@sprite_size = 6
|
@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
|
@number_of_mines = number_of_mines
|
||||||
@field = MineHunt::Board.new( @number_of_mines )
|
@field = MineHunt::Board.new( @number_of_mines )
|
||||||
@finished = false
|
@finished = false
|
||||||
@state = { dead: false, victory: false }
|
@state = { dead: false, victory: false }
|
||||||
|
|
||||||
@font = Gosu::Font.new( 20 )
|
@font = Gosu::Font.new( 20 )
|
||||||
@images = { explorer: Gosu::Image.from_blob( @sprite_size, @sprite_size, bits_to_rgbas( '000000001100011110011110001100000000' ) ),
|
@images = { explorer: Gosu::Image.from_blob( @sprite_size * @scale, @sprite_size * @scale, bits_to_rgbas( '000000001100011110011110001100000000' ) ),
|
||||||
dead_explorer: Gosu::Image.from_blob( @sprite_size, @sprite_size, bits_to_rgbas( '100001010010001100001100010010100001' ) ),
|
dead_explorer: Gosu::Image.from_blob( @sprite_size * @scale, @sprite_size * @scale, bits_to_rgbas( '100001010010001100001100010010100001' ) ),
|
||||||
door: Gosu::Image.from_blob( @sprite_size, @sprite_size, bits_to_rgbas( '010101101010' ) * ( @sprite_size / 2 ) ),
|
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, @sprite_size, bits_to_rgbas( '111111110011100001100001110011111111' ) ),
|
mine: Gosu::Image.from_blob( @sprite_size * @scale, @sprite_size * @scale, bits_to_rgbas( '111111110011100001100001110011111111' ) ),
|
||||||
cell: Gosu::Image.from_blob( @sprite_size, @sprite_size, bits_to_rgbas( '1' ) * @sprite_size * @sprite_size ),
|
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, @sprite_size, bits_to_rgbas( '0' ) * @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
|
end
|
||||||
|
|
||||||
def bits_to_rgbas( bits )
|
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
|
end
|
||||||
|
|
||||||
def new_level
|
def new_level
|
||||||
|
@ -104,11 +106,9 @@ class GosuHunt < Gosu::Window
|
||||||
@images[:mine]
|
@images[:mine]
|
||||||
else
|
else
|
||||||
@images[:cell]
|
@images[:cell]
|
||||||
end ).draw ( @scale * ( x * @sprite_size ) ) + x + @scale,
|
end ).draw ( ( @sprite_size + 1 ) * x * @scale ) + @scale,
|
||||||
( @scale * ( y * @sprite_size ) ) + 20 + y + @scale,
|
( ( @sprite_size + 1 ) * y * @scale ) + @scale + 20,
|
||||||
0,
|
0
|
||||||
@scale,
|
|
||||||
@scale
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue