Class: Window
- Inherits:
-
Gosu::Window
- Object
- Gosu::Window
- Window
- Defined in:
- lib/zombie-chaser/ui.rb
Instance Attribute Summary collapse
-
#grid ⇒ Object
Returns the value of attribute grid.
-
#human ⇒ Object
writeonly
Sets the attribute human.
-
#zombie_list ⇒ Object
writeonly
Sets the attribute zombie_list.
Class Method Summary collapse
Instance Method Summary collapse
- #button_down(id) ⇒ Object
- #draw ⇒ Object
- #draw_human ⇒ Object
- #draw_scenery ⇒ Object
- #draw_zombies ⇒ Object
-
#initialize ⇒ Window
constructor
A new instance of Window.
- #map ⇒ Object
-
#no_living_zombies_apart_from_me?(desired_step_count, actor) ⇒ Boolean
No longer a major issue now zombies approach from all directions in GUI mode.
-
#tile_positions ⇒ Object
private.
Constructor Details
#initialize ⇒ Window
Returns a new instance of Window.
102 103 104 105 106 107 108 109 110 |
# File 'lib/zombie-chaser/ui.rb', line 102 def initialize super(self.class.width, self.class.height, false) self. = 'Zombie-chaser' self.grid = 1 @grass = Gosu::Image.new(self, File.join(File.dirname(__FILE__),'tiles/grass.png'), true) @shrubbery = Gosu::Image.new(self, File.join(File.dirname(__FILE__),'tiles/shrubbery.png'), true) end |
Instance Attribute Details
#grid ⇒ Object
Returns the value of attribute grid.
99 100 101 |
# File 'lib/zombie-chaser/ui.rb', line 99 def grid @grid end |
#human=(value) ⇒ Object (writeonly)
Sets the attribute human
100 101 102 |
# File 'lib/zombie-chaser/ui.rb', line 100 def human=(value) @human = value end |
#zombie_list=(value) ⇒ Object (writeonly)
Sets the attribute zombie_list
100 101 102 |
# File 'lib/zombie-chaser/ui.rb', line 100 def zombie_list=(value) @zombie_list = value end |
Class Method Details
.height ⇒ Object
97 |
# File 'lib/zombie-chaser/ui.rb', line 97 def self.height; @height end |
.height=(height) ⇒ Object
96 |
# File 'lib/zombie-chaser/ui.rb', line 96 def self.height=(height); @height = height end |
.width ⇒ Object
94 |
# File 'lib/zombie-chaser/ui.rb', line 94 def self.width; @width end |
.width=(width) ⇒ Object
93 |
# File 'lib/zombie-chaser/ui.rb', line 93 def self.width=(width); @width = width end |
Instance Method Details
#button_down(id) ⇒ Object
118 119 120 |
# File 'lib/zombie-chaser/ui.rb', line 118 def (id) close if id == Gosu::Button::KbEscape end |
#draw ⇒ Object
112 113 114 115 116 |
# File 'lib/zombie-chaser/ui.rb', line 112 def draw draw_scenery draw_human draw_zombies end |
#draw_human ⇒ Object
152 153 154 |
# File 'lib/zombie-chaser/ui.rb', line 152 def draw_human @human.draw if defined?(@human) end |
#draw_scenery ⇒ Object
144 145 146 147 148 149 150 |
# File 'lib/zombie-chaser/ui.rb', line 144 def draw_scenery map.each do |row| row.each do |col| col[:tile].draw(col[:x], col[:y], ZIndex.for(:world)) end end end |
#draw_zombies ⇒ Object
156 157 158 |
# File 'lib/zombie-chaser/ui.rb', line 156 def draw_zombies @zombie_list.draw_zombies if defined?(@zombie_list) end |
#map ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/zombie-chaser/ui.rb', line 132 def map @map ||= tile_positions[:y].map do |y| tile_positions[:x].map do |x| { :x => x, :y => y, :tile => (rand(32) % 32 == 0) ? @shrubbery : @grass } end end end |
#no_living_zombies_apart_from_me?(desired_step_count, actor) ⇒ Boolean
No longer a major issue now zombies approach from all directions in GUI mode
161 162 163 |
# File 'lib/zombie-chaser/ui.rb', line 161 def no_living_zombies_apart_from_me?(desired_step_count, actor) true end |
#tile_positions ⇒ Object
private
124 125 126 127 128 129 130 |
# File 'lib/zombie-chaser/ui.rb', line 124 def tile_positions w, h = @grass.width, @grass.height @tile_positions ||= { :x => (0...width).to_a.inject([]) {|a,x| a << x if x % w == 0; a}, :y => (0...height).to_a.inject([]) {|a,y| a << y if y % h == 0; a} } end |