Class: UI::VoltorbFlip::BoardTile

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

Overview

Board tile in VoltorbFlip game

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, #size, #stop_animation, #translate_mouse_coords, #update, #update_position, #visible, #visible=, #with_cache, #with_font, #with_surface, #z, #z=

Constructor Details

#initialize(viewport) ⇒ BoardTile

Create a new BoardTile

Parameters:



186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'scripts/01450 Systems/09000 Games/00002 VoltorbFlip/02200 VoltorbFlipSprites.rb', line 186

def initialize(viewport)
  super(viewport, default_cache: :interface)
  @tile_back = push(14, 14, 'voltorbflip/tiles')
  @tile_back.ox = 14
  @tile_back.oy = 14
  @tile_back.set_rect_div(0, 0, 5, 1)

  @tile_front = push(14, 14, 'voltorbflip/tiles')
  @tile_front.ox = 14
  @tile_front.oy = 14
  @tile_front.set_rect_div(0, 0, 5, 1)
  @tile_front.visible = false

  @markers = Array.new(4) do |i|
    s = push(-3, -3, 'voltorbflip/markers')
    s.set_rect_div(2 + i, 0, 6, 1)
    s.visible = false
    next(s)
  end
end

Instance Attribute Details

#contentInteger, :voltorb

Returns Content of the tile.

Returns:

  • (Integer, :voltorb)

    Content of the tile



182
183
184
# File 'scripts/01450 Systems/09000 Games/00002 VoltorbFlip/02200 VoltorbFlipSprites.rb', line 182

def content
  @content
end

Instance Method Details

#hide

Hide the tile



245
246
247
248
249
250
251
252
# File 'scripts/01450 Systems/09000 Games/00002 VoltorbFlip/02200 VoltorbFlipSprites.rb', line 245

def hide
  return unless @tile_front.visible
  @animation = :hide
  @animation_counter = 0
  @tile_back.visible = false
  @tile_front.visible = true
  @markers.each { |m| m.visible = false }
end

#hiden?Boolean

Tell if the tile is hidden

Returns:

  • (Boolean)


255
256
257
# File 'scripts/01450 Systems/09000 Games/00002 VoltorbFlip/02200 VoltorbFlipSprites.rb', line 255

def hiden?
  return @tile_back.visible
end

#reveal

Reveal the tile



229
230
231
232
233
234
235
236
# File 'scripts/01450 Systems/09000 Games/00002 VoltorbFlip/02200 VoltorbFlipSprites.rb', line 229

def reveal
  return unless @tile_back.visible
  @animation = :reveal
  @animation_counter = 0
  @tile_back.visible = true
  @tile_front.visible = false
  @markers.each { |m| m.visible = false }
end

#revealed?Boolean

Tell if the tile was revealed

Returns:

  • (Boolean)


240
241
242
# File 'scripts/01450 Systems/09000 Games/00002 VoltorbFlip/02200 VoltorbFlipSprites.rb', line 240

def revealed?
  return @tile_front.visible
end

#simple_mouse_in?(mx, my) ⇒ Boolean

Detect if the mouse is in the tile

Parameters:

  • mx (Integer)

    X coordinate of the mouse

  • my (Integer)

    Y coordinate of the mouse

Returns:

  • (Boolean)


211
212
213
# File 'scripts/01450 Systems/09000 Games/00002 VoltorbFlip/02200 VoltorbFlipSprites.rb', line 211

def simple_mouse_in?(mx, my)
  return @tile_back.simple_mouse_in?(mx + @tile_back.ox, my + @tile_back.oy)
end

#toggle_memo(index)

Toggle a memo marker

Parameters:

  • index (Integer)

    index of the memo in the marker array



224
225
226
# File 'scripts/01450 Systems/09000 Games/00002 VoltorbFlip/02200 VoltorbFlipSprites.rb', line 224

def toggle_memo(index)
  @markers[index].visible = !@markers[index].visible
end

#update_animationBoolean

Update the animation of the tile

Returns:

  • (Boolean)

    if the animation will still run



261
262
263
264
265
266
267
268
269
# File 'scripts/01450 Systems/09000 Games/00002 VoltorbFlip/02200 VoltorbFlipSprites.rb', line 261

def update_animation
  case @animation
  when :reveal
    return update_reveal_animation
  when :hide
    return update_hide_animation
  end
  return false
end

#update_hide_animationBoolean

Update the hide animation

Returns:

  • (Boolean)

    if the animation will still run



296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
# File 'scripts/01450 Systems/09000 Games/00002 VoltorbFlip/02200 VoltorbFlipSprites.rb', line 296

def update_hide_animation
  case @animation_counter
  when 0, 1, 2, 3, 4, 5, 6, 7
    @tile_front.zoom_x -= 1 / 8.0 # 0.25
  when 8
    @tile_front.visible = false
    @tile_front.zoom_x = 1
    @tile_back.visible = true
    @tile_back.zoom_x = 0
  when 9, 10, 11, 12, 13, 14, 15
    @tile_back.zoom_x += 1 / 8.0
  when 16
    @tile_back.zoom_x = 1
    @animation_counter = 0
    @animation = nil
    return self
  end
  @animation_counter += 1
  return !@animation.nil?
end

#update_reveal_animationBoolean

Update the reveal animation

Returns:

  • (Boolean)

    if the animation will still run



273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
# File 'scripts/01450 Systems/09000 Games/00002 VoltorbFlip/02200 VoltorbFlipSprites.rb', line 273

def update_reveal_animation
  case @animation_counter
  when 0, 1, 2, 3, 4, 5, 6, 7
    @tile_back.zoom_x -= 1 / 8.0 # 0.25
  when 8
    @tile_back.visible = false
    @tile_back.zoom_x = 1
    @tile_front.visible = true
    @tile_front.zoom_x = 0
  when 9, 10, 11, 12, 13, 14, 15
    @tile_front.zoom_x += 1 / 8.0
  when 16
    @tile_front.zoom_x = 1
    @animation_counter = 0
    @animation = nil
    return self
  end
  @animation_counter += 1
  return !@animation.nil?
end