Class: Actor

Inherits:
Object
  • Object
show all
Defined in:
lib/zombie-chaser/ui.rb

Direct Known Subclasses

Human

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.spritesObject



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

.windowObject



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_typeObject

Raises:

  • (NotImplementedError)


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

#drawObject



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

#imageObject



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

#windowObject



84
85
86
# File 'lib/zombie-chaser/ui.rb', line 84

def window
  self.class.window
end

#xObject



66
67
68
# File 'lib/zombie-chaser/ui.rb', line 66

def x
  calculate_x(@successful_step_count)
end

#yObject



70
71
72
# File 'lib/zombie-chaser/ui.rb', line 70

def y
  calculate_y(@successful_step_count)
end

#zObject



74
75
76
77
78
79
80
81
82
# File 'lib/zombie-chaser/ui.rb', line 74

def z
  case actor_state
  when "dead" then ZIndex.for(:dead)
  when "attacking" then ZIndex.for(:attacking)
  when "moving" then ZIndex.for(:actor)
  when "dying" then ZIndex.for(:actor)
  else raise "Unknown state"
  end
end