Class: UI::VoltorbFlip::Cursor

Inherits:
Sprite show all
Defined in:
scripts/01450 Systems/09000 Games/00002 VoltorbFlip/02200 VoltorbFlipSprites.rb

Overview

Cursor shown in VoltorbFlip scene

Instance Attribute Summary collapse

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 Sprite

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

Methods inherited from LiteRGSS::Sprite

new, #set_origin, #set_position

Methods inherited from LiteRGSS::Disposable

#dispose, #disposed?

Constructor Details

#initialize(viewport) ⇒ Cursor

Create a new cursor

Parameters:



71
72
73
74
75
76
77
78
79
# File 'scripts/01450 Systems/09000 Games/00002 VoltorbFlip/02200 VoltorbFlipSprites.rb', line 71

def initialize(viewport)
  super(viewport)
  set_bitmap('voltorbflip/markers', :interface)
  self.mode = :normal
  @move_count = false
  @board_x = 0
  @board_y = 0
  set_position(*get_board_position(@board_x, @board_y))
end

Instance Attribute Details

#board_xInteger (readonly)

The X coords on the board of the cursor

Returns:



61
62
63
# File 'scripts/01450 Systems/09000 Games/00002 VoltorbFlip/02200 VoltorbFlipSprites.rb', line 61

def board_x
  @board_x
end

#board_yInteger (readonly)

The Y coords on the board of the cursor

Returns:



64
65
66
# File 'scripts/01450 Systems/09000 Games/00002 VoltorbFlip/02200 VoltorbFlipSprites.rb', line 64

def board_y
  @board_y
end

#modeSymbol

The cursor mode :normal, :memo

Returns:

  • (Symbol)


67
68
69
# File 'scripts/01450 Systems/09000 Games/00002 VoltorbFlip/02200 VoltorbFlipSprites.rb', line 67

def mode
  @mode
end

Instance Method Details

#get_board_position(x, y) ⇒ Array(Integer, Integer)

Convert board coord in pixel coords

Parameters:

  • x (Integer)

    X position on the board

  • y (Integer)

    Y position on the board

Returns:



96
97
98
99
100
101
102
103
104
105
106
107
# File 'scripts/01450 Systems/09000 Games/00002 VoltorbFlip/02200 VoltorbFlipSprites.rb', line 96

def get_board_position(x, y)
  if y > 4 # Quit button
    return GamePlay::Casino::VoltorbFlip::QuitDispX,
           GamePlay::Casino::VoltorbFlip::QuitDispY
  elsif x > 4 # Memo
    return GamePlay::Casino::VoltorbFlip::MemoDispX,
           GamePlay::Casino::VoltorbFlip::MemoDispY + y * ::GamePlay::Casino::VoltorbFlip::MemoTileSize
  else # Board
    return GamePlay::Casino::VoltorbFlip::BoardDispX + x * ::GamePlay::Casino::VoltorbFlip::TileOffset,
           GamePlay::Casino::VoltorbFlip::BoardDispY + y * ::GamePlay::Casino::VoltorbFlip::TileOffset
  end
end

#move_on_board(dx, dy)

Start the cursor mouvement

Parameters:

  • dx (Integer)

    the number of case to move in x

  • dy (Integer)

    the number of case to move in y



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'scripts/01450 Systems/09000 Games/00002 VoltorbFlip/02200 VoltorbFlipSprites.rb', line 112

def move_on_board(dx, dy)
  # Update board coords
  if @board_y == 5 && dx != 0
    @board_x = (dx < 0 ? 4 : 5)
    @board_y = 4
  else
    @board_x += dx
    @board_y += dy
  end
  # Correct boundaries
  @board_x = 0 if @board_x < 0
  @board_y = 0 if @board_y < 0
  @board_x = 5 if @board_x > 5
  @board_y = 5 if @board_y > 5
  # Init mouvement
  @move_count = 0
  @move_data = [x, y, *get_board_position(@board_x, @board_y)]
end

#moveto(board_x, board_y)

Move the cursor to a dedicated board coordinate

Parameters:



134
135
136
# File 'scripts/01450 Systems/09000 Games/00002 VoltorbFlip/02200 VoltorbFlipSprites.rb', line 134

def moveto(board_x, board_y)
  set_position(*get_board_position(@board_x = board_x, @board_y = board_y))
end

#update_moveBoolean

Update the cursor mouvement, return true if the mouvement has been updated

Returns:

  • (Boolean)


83
84
85
86
87
88
89
90
# File 'scripts/01450 Systems/09000 Games/00002 VoltorbFlip/02200 VoltorbFlipSprites.rb', line 83

def update_move
  return false unless @move_count
  cursor_duration = GamePlay::Casino::VoltorbFlip::CursorMoveDuration
  self.x = @move_data[0] + (@move_data[2] - @move_data[0]) * @move_count / cursor_duration
  self.y = @move_data[1] + (@move_data[3] - @move_data[1]) * @move_count / cursor_duration
  @move_count = false if (@move_count += 1) > cursor_duration
  return true
end