Class: World
- Inherits:
-
Object
- Object
- World
- Defined in:
- lib/rofltim.rb
Instance Attribute Summary collapse
-
#background ⇒ Object
readonly
Returns the value of attribute background.
-
#buildings ⇒ Object
readonly
Returns the value of attribute buildings.
-
#distance ⇒ Object
readonly
Returns the value of attribute distance.
-
#horizon ⇒ Object
readonly
Returns the value of attribute horizon.
-
#misc ⇒ Object
readonly
Returns the value of attribute misc.
-
#player ⇒ Object
readonly
Returns the value of attribute player.
-
#speed ⇒ Object
readonly
Returns the value of attribute speed.
-
#ticks ⇒ Object
readonly
Returns the value of attribute ticks.
Instance Method Summary collapse
- #building_under_player ⇒ Object
-
#initialize(horizon) ⇒ World
constructor
A new instance of World.
- #tick ⇒ Object
Constructor Details
#initialize(horizon) ⇒ World
Returns a new instance of World.
160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/rofltim.rb', line 160 def initialize horizon @ticks = 0 @horizon = horizon @building_generator = BuildingGenerator.new(self, WindowColor.new) @background = Background.new(self) @player = Player.new(25, @background) @buildings = [ @building_generator.build(-10, 30, 120) ] @misc = [ Scoreboard.new(self), RoflCopter.new(50, 4, @background) ] @speed = 4 @distance = 0 end |
Instance Attribute Details
#background ⇒ Object (readonly)
Returns the value of attribute background.
171 172 173 |
# File 'lib/rofltim.rb', line 171 def background @background end |
#buildings ⇒ Object (readonly)
Returns the value of attribute buildings.
171 172 173 |
# File 'lib/rofltim.rb', line 171 def buildings @buildings end |
#distance ⇒ Object (readonly)
Returns the value of attribute distance.
171 172 173 |
# File 'lib/rofltim.rb', line 171 def distance @distance end |
#horizon ⇒ Object (readonly)
Returns the value of attribute horizon.
171 172 173 |
# File 'lib/rofltim.rb', line 171 def horizon @horizon end |
#misc ⇒ Object (readonly)
Returns the value of attribute misc.
171 172 173 |
# File 'lib/rofltim.rb', line 171 def misc @misc end |
#player ⇒ Object (readonly)
Returns the value of attribute player.
171 172 173 |
# File 'lib/rofltim.rb', line 171 def player @player end |
#speed ⇒ Object (readonly)
Returns the value of attribute speed.
171 172 173 |
# File 'lib/rofltim.rb', line 171 def speed @speed end |
#ticks ⇒ Object (readonly)
Returns the value of attribute ticks.
171 172 173 |
# File 'lib/rofltim.rb', line 171 def ticks @ticks end |
Instance Method Details
#building_under_player ⇒ Object
214 215 216 217 218 |
# File 'lib/rofltim.rb', line 214 def building_under_player buildings.detect do |b| b.x <= player.x && b.right_x >= player.right_x end end |
#tick ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/rofltim.rb', line 172 def tick # TODO: this, but less often. if @ticks % 20 == 0 @building_generator.generate_if_necessary @building_generator.destroy_if_necessary end @distance += speed buildings.each do |b| b.move_left speed end if b = building_under_player if player.bottom_y > b.y b.move_left(-speed) @speed = 0 @misc << Blood.new(player.x, player.y) @misc << GameOverBanner.new player.die! end end begin if STDIN.read_nonblock(1) if player.dead? return false else player.jump end end rescue Errno::EAGAIN end player.tick if b = building_under_player player.walk_on_building b if player.bottom_y >= b.y end @ticks += 1 end |