Skip to content

Commit

Permalink
Added a little "depth" to the map.
Browse files Browse the repository at this point in the history
  • Loading branch information
sneakin committed Oct 16, 2011
1 parent 6b8b562 commit 588aa10
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 37 deletions.
39 changes: 2 additions & 37 deletions lib/mc/bot_gui.rb
Expand Up @@ -12,6 +12,7 @@ def initialize(bot)
@bot = bot
@packets = 0
@packet_rate = 0
@mapper = GUI::Mapper.new(bot.world)
@console = Array.new
end

Expand Down Expand Up @@ -73,20 +74,9 @@ def print_map

width = 32
height = 16
floor = Array.new(height) { Array.new(width) }

height.times do |x|
width.times do |z|
floor[x][z] = bot.world[bot.position.x.to_i - height / 2 + x - 1, bot.position.y.to_i, bot.position.z.to_i - width / 2 + z]
end
end

floor[height / 2][width / 2] = 'X'

box(65, 1) do |boxer|
floor.each do |col|
boxer.puts(col.reverse.collect { |c| if c == 'X'; c.color(:red); else; map_char(c); end }.join)
end
@mapper.print(boxer, bot.position, width, height)
end
end

Expand Down Expand Up @@ -161,31 +151,6 @@ def print_console
end
end

def map_char(block)
return '?'.color(64, 64, 64) unless block.loaded?

case block.type
when 0 then ' '
when 1 then '#'.color(:default)
when 2 then '#'.color(:green)
when 3 then '#'.color(255, 64, 0)
when 8 then '~'.color(:blue)
when 9 then '~'.color(:blue)
when 10 then '^'.color(:red)
when 11 then '^'.color(:red)
when 12 then '.'.color(:yellow)
when 17 then '@'.color(128, 64, 0)
when 18 then '#'.color(0, 128, 0)
when 50 then '`'.color(255, 255, 0)
when 64 then '|'.color(255, 255, 128)
when 71 then '|'.color(255, 255, 128)
when 53 then '>'
when 67 then '>'
when 108 then '>'
when 109 then '>'
when 114 then '>'
else '#'
end
def print_prompt
$stdout.write("> ")
end
Expand Down
1 change: 1 addition & 0 deletions lib/mc/gui.rb
@@ -1,5 +1,6 @@
module MC
module GUI
autoload :Boxer, 'mc/gui/boxer'
autoload :Mapper, 'mc/gui/mapper'
end
end
88 changes: 88 additions & 0 deletions lib/mc/gui/mapper.rb
@@ -0,0 +1,88 @@
# -*- coding: utf-8 -*-
require 'rainbow'

module MC
module GUI
class Mapper
attr_reader :world

def initialize(world)
@world = world
end

def print(io, position, width, height)
floor = Array.new(height) { Array.new(width) }

height.times do |x|
width.times do |z|
floor[x][z] = map_char(position.x.to_i - height / 2 + x - 1,
position.y.to_i,
position.z.to_i - width / 2 + z)
end
end

floor[height / 2][width / 2] = 'X'.color(:red)

floor.each do |col|
io.puts(col.reverse.join)
end
end


BlockChars = {
:rock => " _XX\"\"##",
:liquid => ' _~~""##',
:torch => ' .ii``::',
:door => '|-',
:tree => ' .oo∘∘OO',
}

def map_char(x, y, z)
legs = world[x, y, z]
return '?'.color(64, 64, 64) unless legs.loaded?

feet = world[x, y - 1, z]
head = world[x, y + 1, z]
#above = world[x, y + 2, z]

block = feet
block = legs if legs.solid?
block = head if head.solid?

solid_index = (feet.solid? ? 1 : 0) | (legs.solid? ? 1 : 0) << 1 | (head.solid? ? 1 : 0) << 2
MC.logger.debug("#{legs.inspect}\n#{feet.inspect}\n#{head.inspect}\n#{solid_index}")

case block.type
when 0 then ' '
when 1, 53, 67, 108, 109, 114 then BlockChars[:rock][solid_index].color(:default)
when 2 then BlockChars[:rock][solid_index].color(:green)
when 3 then BlockChars[:rock][solid_index].color(255, 64, 0)
when 7 then BlockChars[:rock][solid_index].color(64, 64, 64)
when 8, 9 then BlockChars[:liquid][solid_index].color(:blue)
when 10, 11 then BlockChars[:liquid][solid_index].color(:red)
when 12 then BlockChars[:rock][solid_index].color(:yellow)
when 17 then BlockChars[:tree][solid_index].color(128, 64, 0)
when 18 then BlockChars[:rock][solid_index].color(0, 128, 0)
when 50 then BlockChars[:torch][solid_index].color(:yellow)
when 64 then BlockChars[:door][0]
when 71 then BlockChars[:door][0]
else BlockChars[:rock][solid_index].color(96, 96, 96)
end
end

def block_char(block)
return '?'.color(64, 64, 64) unless block.loaded?

case block.type
when 0 then ' '
when 53 then '>'
when 67 then '>'
when 108 then '>'
when 109 then '>'
when 114 then '>'
else '#'
end
end
end
end
end
4 changes: 4 additions & 0 deletions lib/mc/world.rb
Expand Up @@ -20,6 +20,10 @@ def update(update_block)
def loaded?
@loaded
end

def solid?
type != 0
end
end

class ChunkUpdate
Expand Down

0 comments on commit 588aa10

Please sign in to comment.