class TreeGraphics
Constants
- SHAKE_COOLDOWN
- SHAKE_DISTANCE
- SHAKE_TIME
Public Class Methods
new(object, seed)
click to toggle source
Calls superclass method
Component::new
# File lib/entities/components/tree_graphics.rb, line 5 def initialize(object, seed) super(object) load_sprite(seed) end
Public Instance Methods
adjust_shake(x, y, shaking_for)
click to toggle source
# 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)
click to toggle source
# File lib/entities/components/tree_graphics.rb, line 26 def draw(viewport) 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()
click to toggle source
# File lib/entities/components/tree_graphics.rb, line 41 def height @tree.height end
shake(direction)
click to toggle source
# 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()
click to toggle source
# File lib/entities/components/tree_graphics.rb, line 45 def width @tree.width end
Private Instance Methods
center_x()
click to toggle source
# File lib/entities/components/tree_graphics.rb, line 57 def center_x @center_x ||= x - @tree.width / 2 end
center_y()
click to toggle source
# File lib/entities/components/tree_graphics.rb, line 61 def center_y @center_y ||= y - @tree.height / 2 end
load_sprite(seed)
click to toggle source
# File lib/entities/components/tree_graphics.rb, line 51 def load_sprite(seed) frame_list = trees.frame_list frame = frame_list[(frame_list.size * seed).round] @tree = trees.frame(frame) end
trees()
click to toggle source
# File lib/entities/components/tree_graphics.rb, line 65 def trees @@trees ||= Gosu::TexturePacker.load_json($window, Utils.media_path('trees_packed.json')) end