Skip to content
Create a gist now

Instantly share code, notes, and snippets.

ROFLBALT World
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.