public
Created

ROFLBALT World

  • Download Gist
world.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
class World
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
attr_reader :buildings, :player, :horizon, :speed, :misc, :ticks, :distance, :background
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
def building_under_player
buildings.detect do |b|
b.x <= player.x && b.right_x >= player.right_x
end
end
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.