Class: Actor
- Inherits:
-
Object
- Object
- Actor
- Defined in:
- lib/zombie-chaser/ui.rb
Direct Known Subclasses
Class Method Summary collapse
Instance Method Summary collapse
- #actor_type ⇒ Object
- #calculate_x(successful_step_count) ⇒ Object
- #calculate_y(successful_step_count) ⇒ Object
- #draw ⇒ Object
- #image ⇒ Object
- #window ⇒ Object
- #x ⇒ Object
- #y ⇒ Object
- #z ⇒ Object
Class Method Details
.sprites ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/zombie-chaser/ui.rb', line 31 def self.sprites @sprites ||= Dir[File.join(File.dirname(__FILE__),'sprites/*.png')].inject({}) do |sprites,f| sprite = File.basename(f,'.*').split('-') sprites[sprite.first] ||= {} sprites[sprite.first][sprite.last] = Gosu::Image.new(window, f, false) sprites end end |
.window ⇒ Object
29 |
# File 'lib/zombie-chaser/ui.rb', line 29 def self.window; @window end |
.window=(window) ⇒ Object
28 |
# File 'lib/zombie-chaser/ui.rb', line 28 def self.window=(window); @window = window end |
Instance Method Details
#actor_type ⇒ Object
45 46 47 |
# File 'lib/zombie-chaser/ui.rb', line 45 def actor_type raise NotImplementedError end |
#calculate_x(successful_step_count) ⇒ Object
54 55 56 57 58 |
# File 'lib/zombie-chaser/ui.rb', line 54 def calculate_x(successful_step_count) preferred_step_size = 10 max_distance = ([Window.width, Window.height].min / 2) - preferred_step_size (Window.width / 2) + Math::sin(@angle) * ((test_suite_size - successful_step_count) * preferred_step_size) * [1, max_distance * 1.0 / (test_suite_size * preferred_step_size)].min end |
#calculate_y(successful_step_count) ⇒ Object
60 61 62 63 64 |
# File 'lib/zombie-chaser/ui.rb', line 60 def calculate_y(successful_step_count) preferred_step_size = 10 max_distance = ([Window.width, Window.height].min / 2) - preferred_step_size ((Window.height / 2) + Math::cos(@angle) * ((test_suite_size - successful_step_count) * preferred_step_size) * [1, max_distance * 1.0 / (test_suite_size * preferred_step_size)].min) end |
#draw ⇒ Object
49 50 51 52 |
# File 'lib/zombie-chaser/ui.rb', line 49 def draw raise "actor is off the screen" unless (x > 0 and x < self.class.window.width and y > 0 and y < self.class.window.height) image.draw_rot(x, y, z, actor_direction) end |
#image ⇒ Object
40 41 42 43 |
# File 'lib/zombie-chaser/ui.rb', line 40 def image #self.class.sprites['robot']['idle'] #FIXME adjust this to indicate human versus zombie, and status of alive, dying or dead self.class.sprites[actor_type][actor_state] end |
#window ⇒ Object
84 85 86 |
# File 'lib/zombie-chaser/ui.rb', line 84 def window self.class.window end |
#x ⇒ Object
66 67 68 |
# File 'lib/zombie-chaser/ui.rb', line 66 def x calculate_x(@successful_step_count) end |
#y ⇒ Object
70 71 72 |
# File 'lib/zombie-chaser/ui.rb', line 70 def y calculate_y(@successful_step_count) end |