Class: UI::Bag::BagSprite

Inherits:
SpriteSheet show all
Defined in:
scripts/01450 Systems/00103 Bag/00002 UI/00040 BagSprite.rb

Overview

Class that show the bag sprite in the Bag UI

Constant Summary collapse

POCKET_TRANSLATION =

Array translating real pocket id to sprite piece

[0, 0, 1, 3, 5, 4, 2, 6, 7]
COORDINATES =

Coordinates of the bag

[71, 103]

Instance Attribute Summary collapse

Attributes inherited from SpriteSheet

#nb_x, #nb_y, #sx, #sy

Attributes inherited from LiteRGSS::ShaderedSprite

#blendmode, #shader

Attributes inherited from LiteRGSS::Sprite

#__index__, #angle, #bitmap, #height, #mirror, #opacity, #ox, #oy, #src_rect, #viewport, #visible, #width, #x, #y, #z, #zoom, #zoom_x, #zoom_y

Instance Method Summary collapse

Methods inherited from SpriteSheet

#bitmap=, #select

Methods inherited from Sprite

#load, #mouse_in?, #set_origin_div, #set_rect, #set_rect_div, #set_z, #simple_mouse_in?, #translate_mouse_coords

Methods inherited from LiteRGSS::Sprite

new, #set_origin, #set_position

Methods inherited from LiteRGSS::Disposable

#dispose, #disposed?

Constructor Details

#initialize(viewport, pocket_indexes) ⇒ BagSprite

Create a new Bah Sprite

Parameters:

  • viewport (Viewport)
  • pocket_indexes (Array<Integer>)

    each shown pocket by the UI



14
15
16
17
18
19
# File 'scripts/01450 Systems/00103 Bag/00002 UI/00040 BagSprite.rb', line 14

def initialize(viewport, pocket_indexes)
  super(viewport, 1, 8)
  @index = 0
  @pocket_indexes = pocket_indexes
  init_sprite
end

Instance Attribute Details

#indexInteger

Returns the current socket index.

Returns:

  • (Integer)

    the current socket index



6
7
8
# File 'scripts/01450 Systems/00103 Bag/00002 UI/00040 BagSprite.rb', line 6

def index
  @index
end

Instance Method Details

#animate(target_index)

Start the animation between socket



28
29
30
31
# File 'scripts/01450 Systems/00103 Bag/00002 UI/00040 BagSprite.rb', line 28

def animate(target_index)
  @target_index = target_index.clamp(0, 7)
  @counter = 0
end

#done?Boolean

Test if the animation is done

Returns:

  • (Boolean)


52
53
54
# File 'scripts/01450 Systems/00103 Bag/00002 UI/00040 BagSprite.rb', line 52

def done?
  @counter >= 8
end

#mid?Boolean

Test if the animation is at the middle of its progression

Returns:

  • (Boolean)


58
59
60
# File 'scripts/01450 Systems/00103 Bag/00002 UI/00040 BagSprite.rb', line 58

def mid?
  @counter == 4
end

#update

Update the animation



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'scripts/01450 Systems/00103 Bag/00002 UI/00040 BagSprite.rb', line 34

def update
  return if done?
  if @counter < 2
    self.x = COORDINATES.first - @counter
  elsif @counter < 4
    self.x = COORDINATES.first - 4 + @counter
  elsif @counter == 4
    self.index = @target_index
  elsif @counter < 6
    self.x = COORDINATES.first + @counter - 4
  else
    self.x = COORDINATES.first + 8 - @counter
  end
  @counter += 1
end