Class: TreeGraphics
- Defined in:
- lib/entities/components/tree_graphics.rb
Constant Summary collapse
- SHAKE_TIME =
100
- SHAKE_COOLDOWN =
200
- SHAKE_DISTANCE =
[2, 1, 0, -1, -2, -1, 0, 1, 0, -1, 0]
Instance Attribute Summary
Attributes inherited from Component
Instance Method Summary collapse
- #adjust_shake(x, y, shaking_for) ⇒ Object
- #draw(viewport) ⇒ Object
- #height ⇒ Object
-
#initialize(object, seed) ⇒ TreeGraphics
constructor
A new instance of TreeGraphics.
- #shake(direction) ⇒ Object
- #width ⇒ Object
Methods inherited from Component
Constructor Details
#initialize(object, seed) ⇒ TreeGraphics
Returns a new instance of TreeGraphics.
5 6 7 8 |
# File 'lib/entities/components/tree_graphics.rb', line 5 def initialize(object, seed) super(object) load_sprite(seed) end |
Instance Method Details
#adjust_shake(x, y, shaking_for) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/entities/components/tree_graphics.rb', line 19 def adjust_shake(x, y, shaking_for) elapsed = [shaking_for, SHAKE_TIME].min / SHAKE_TIME.to_f frame = ((SHAKE_DISTANCE.length - 1) * elapsed).floor distance = SHAKE_DISTANCE[frame] Utils.point_at_distance(x, y, @shake_direction, distance) end |
#draw(viewport) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/entities/components/tree_graphics.rb', line 26 def draw() if @shaking shaking_for = Gosu.milliseconds - @shake_start shaking_x, shaking_y = adjust_shake( center_x, center_y, shaking_for) @tree.draw(shaking_x, shaking_y, 5) if shaking_for >= SHAKE_TIME @shaking = false end else @tree.draw(center_x, center_y, 5) end Utils.mark_corners(object.box) if $debug end |
#height ⇒ Object
41 42 43 |
# File 'lib/entities/components/tree_graphics.rb', line 41 def height @tree.height end |
#shake(direction) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/entities/components/tree_graphics.rb', line 10 def shake(direction) now = Gosu.milliseconds return if @shake_start && now - @shake_start < SHAKE_TIME + SHAKE_COOLDOWN @shake_start = now @shake_direction = direction @shaking = true end |
#width ⇒ Object
45 46 47 |
# File 'lib/entities/components/tree_graphics.rb', line 45 def width @tree.width end |