Class: UI::MiningGame::Tiles_Stack

Inherits:
SpriteStack show all
Defined in:
scripts/01450 Systems/00020 Mining_Game/00030 UI_Mining_Game/00007 Tiles_Stack.rb

Overview

Class that describes the Tiles_Stack object

Constant Summary

Constants inherited from SpriteStack

SpriteStack::NO_INITIAL_IMAGE

Instance Attribute Summary collapse

Attributes inherited from SpriteStack

#animated, #data, #moving, #stack, #viewport, #x, #y

Instance Method Summary collapse

Methods inherited from SpriteStack

#[], #add_background, #add_line, #add_text, #anime, #anime_delta_set, #dispose, #each, #execute_anime, #move, #move_to, #opacity, #opacity=, #push, #push_sprite, #set_origin, #set_position, #simple_mouse_in?, #size, #stop_animation, #translate_mouse_coords, #update, #update_animation, #update_position, #visible, #visible=, #with_cache, #with_font, #with_surface, #z, #z=

Constructor Details

#initialize(viewport, arr) ⇒ Tiles_Stack

Create the Tiles_Stack

Parameters:

  • viewport (Viewport)

    the viewport of the scene

  • arr (Array<Array<Integer>>)

    the array containing the arrays containing the tiles (columns<lines<tiles state>>)



10
11
12
13
14
15
16
17
18
19
# File 'scripts/01450 Systems/00020 Mining_Game/00030 UI_Mining_Game/00007 Tiles_Stack.rb', line 10

def initialize(viewport, arr)
  super(viewport, initial_x, initial_y)
  @tile_array = Array.new(arr.size) { [] }
  arr.each_with_index do |line, y_index|
    line.each_with_index do |state, x_index|
      push(texture_length * x_index, texture_width * y_index, bitmap_filename, state, type: Tiles)
    end
  end
  stack.each_with_index { |tile, index| @tile_array[index / 16] << tile }
end

Instance Attribute Details

#tile_arrayArray<UI::MiningGame::Tiles] the array containing all the Tiles sprite

Returns Array<UI::MiningGame::Tiles] the array containing all the Tiles sprite.

Returns:

  • (Array<UI::MiningGame::Tiles] the array containing all the Tiles sprite)

    Array<UI::MiningGame::Tiles] the array containing all the Tiles sprite



6
7
8
# File 'scripts/01450 Systems/00020 Mining_Game/00030 UI_Mining_Game/00007 Tiles_Stack.rb', line 6

def tile_array
  @tile_array
end

Instance Method Details

#get_adjacent_of(x, y) ⇒ Array<UI::MiningGame::Tiles>

Get the Tiles sprite adjacent to the one at given coordinates

Parameters:

Returns:



33
34
35
36
37
38
39
40
# File 'scripts/01450 Systems/00020 Mining_Game/00030 UI_Mining_Game/00007 Tiles_Stack.rb', line 33

def get_adjacent_of(x, y)
  arr = []
  arr << get_tile(x - 1, y) unless x == 0
  arr << get_tile(x + 1, y) unless x == @tile_array[0].size - 1
  arr << get_tile(x, y - 1) unless y == 0
  arr << get_tile(x, y + 1) unless y == @tile_array.size - 1
  return arr
end

#get_tile(x, y) ⇒ UI::MiningGame::Tiles

Get the Tiles sprite at given coordinates

Parameters:

Returns:



25
26
27
# File 'scripts/01450 Systems/00020 Mining_Game/00030 UI_Mining_Game/00007 Tiles_Stack.rb', line 25

def get_tile(x, y)
  return @tile_array[y][x]
end