Class: RoadToRubykaigi::Sprite::Deadline

Inherits:
Sprite
  • Object
show all
Defined in:
lib/road_to_rubykaigi/sprite/deadline.rb

Constant Summary collapse

DEADLINE_SPEED =
0.3
DEADLINE_START_X =
{ 2025 => 18, 2026 => 48 }

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Sprite

#characters

Instance Attribute Details

#heightObject (readonly)

Returns the value of attribute height.



7
8
9
# File 'lib/road_to_rubykaigi/sprite/deadline.rb', line 7

def height
  @height
end

#widthObject (readonly)

Returns the value of attribute width.



7
8
9
# File 'lib/road_to_rubykaigi/sprite/deadline.rb', line 7

def width
  @width
end

#xObject (readonly)

Returns the value of attribute x.



7
8
9
# File 'lib/road_to_rubykaigi/sprite/deadline.rb', line 7

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y.



7
8
9
# File 'lib/road_to_rubykaigi/sprite/deadline.rb', line 7

def y
  @y
end

Instance Method Details

#activate(player_x:) ⇒ Object



37
38
39
# File 'lib/road_to_rubykaigi/sprite/deadline.rb', line 37

def activate(player_x:)
  @waiting = false if player_x > DEADLINE_START_X[RoadToRubykaigi.version]
end

#bounding_boxObject



33
34
35
# File 'lib/road_to_rubykaigi/sprite/deadline.rb', line 33

def bounding_box
  { x: @x, y: @y, width: @width, height: @height }
end

#build_buffer(offset_x:) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/road_to_rubykaigi/sprite/deadline.rb', line 22

def build_buffer(offset_x:)
  buffer = Array.new(Map::VIEWPORT_HEIGHT) { Array.new(Map::VIEWPORT_WIDTH) { "" } }
  relative_x = @x - offset_x - 1
  relative_y = @y - 1
  @height.times do |i|
    next if relative_x < 1
    buffer[relative_y+i][relative_x] = ANSI::RED + "#" + ANSI::DEFAULT_TEXT_COLOR
  end
  buffer
end

#find {|self || nil| ... } ⇒ Object

Yields:

  • (self || nil)


9
10
11
# File 'lib/road_to_rubykaigi/sprite/deadline.rb', line 9

def find
  yield self || nil
end

#simulate_physicsObject



13
14
15
16
17
18
19
20
# File 'lib/road_to_rubykaigi/sprite/deadline.rb', line 13

def simulate_physics
  return unless active?
  now = Time.now
  if (now - @last_update) > DEADLINE_SPEED
    @x += 1
    @last_update = now
  end
end