Class: Dedalus::Elements::SpriteField
- Inherits:
-
Organism
- Object
- Dedalus::Element
- Organism
- Dedalus::Elements::SpriteField
- Defined in:
- lib/dedalus/elements/sprite_field.rb
Instance Attribute Summary collapse
-
#grid ⇒ Object
Returns the value of attribute grid.
-
#scale ⇒ Object
Returns the value of attribute scale.
-
#sprite_map ⇒ Object
Returns the value of attribute sprite_map.
Attributes inherited from Dedalus::Element
#background_color, #color, #height, #height_percent, #margin, #padding, #position, #width, #width_percent
Class Method Summary collapse
Instance Method Summary collapse
- #background_image ⇒ Object
- #image_grid ⇒ Object
- #layers ⇒ Object
- #show ⇒ Object
- #to_screen_coordinates(location:) ⇒ Object
Methods inherited from Dedalus::Element
#big_font, #code_font, #draw_bounding_box, #font, #huge_font, #initialize, #tiny_font, #view, #window
Constructor Details
This class inherits a constructor from Dedalus::Element
Instance Attribute Details
#grid ⇒ Object
Returns the value of attribute grid.
5 6 7 |
# File 'lib/dedalus/elements/sprite_field.rb', line 5 def grid @grid end |
#scale ⇒ Object
Returns the value of attribute scale.
5 6 7 |
# File 'lib/dedalus/elements/sprite_field.rb', line 5 def scale @scale end |
#sprite_map ⇒ Object
Returns the value of attribute sprite_map.
5 6 7 |
# File 'lib/dedalus/elements/sprite_field.rb', line 5 def sprite_map @sprite_map end |
Class Method Details
.description ⇒ Object
46 47 48 |
# File 'lib/dedalus/elements/sprite_field.rb', line 46 def self.description 'sprites overlaid on an image grid' end |
.example_data ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/dedalus/elements/sprite_field.rb', line 50 def self.example_data { grid: [[0,0,0,0,0], [0,0,0,0,0], [1,1,1,1,1], [1,1,1,1,1]], scale: 0.3, player_location: [2,2], sprite_map: { [0,0] => [ Sprite.example_data ] } } end |
Instance Method Details
#background_image ⇒ Object
42 43 44 |
# File 'lib/dedalus/elements/sprite_field.rb', line 42 def background_image Image.new(path: "media/images/cosmos.jpg", z_order: -1, scale: self.scale) end |
#image_grid ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/dedalus/elements/sprite_field.rb', line 28 def image_grid ImageGrid.new( tiles_path: 'media/images/tiles.png', grid: grid, tile_width: 64, tile_height: 64 ) end |
#layers ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/dedalus/elements/sprite_field.rb', line 11 def layers layer_stack = Dedalus::LayerStack.new layer_stack.push(Dedalus::Layer.new(background_image)) layer_stack.push(Dedalus::Layer.new(image_grid)) # TODO one sprite *layer* sprite_map.each do |location, sprite_list| sprite_list.each do |sprite_attrs| position = to_screen_coordinates(location: location) sprite = Sprite.new(sprite_attrs.merge(position: position)) layer_stack.push(Dedalus::Layer.new(sprite, freeform: true)) end end layer_stack end |
#show ⇒ Object
7 8 9 |
# File 'lib/dedalus/elements/sprite_field.rb', line 7 def show layers end |
#to_screen_coordinates(location:) ⇒ Object
37 38 39 40 |
# File 'lib/dedalus/elements/sprite_field.rb', line 37 def to_screen_coordinates(location:) x,y = *location [(x * image_grid.tile_width), (y * image_grid.tile_height)] end |