NOGDUS $1670.00 has been donated to NOGDUS!
June 23, 2017, 01:56:13 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: map-maker.rb  (Read 1718 times)
0 Members and 1 Guest are viewing this topic.
Richard Marks
Administrator
Offline Offline

Respect: 3425
« on: October 05, 2009, 08:34:09 AM »

map-maker.rb

If you were curious as to how I generated the var/set instruction pairs for the world[] array in the map.asm example, then look no further, as the full source to this useful tool is listed below.

Code:
#!/usr/bin/env ruby
# map-maker.rb
# companion ruby script for map.asm
# this will generate the var/set pairs for the specified map
# the starting address can be specified
# written by Richard Marks <ccpsceo@gmail.com>

$STARTING_ADDRESS = 1000
$MAP_ROWS = 10
$MAP_COLUMNS = 10

$MAP_DATA = [
"##########",
"#    #   #",
"# ## ### #",
"# #    # #",
"# # #### #",
"# #  #   #",
"# #    # #",
"# ########",
"#        #",
"##########"]

class MapMaker
def initialize
@world = []
self.read_map_data
#self.test_world
self.output_assembly
end
def read_map_data
$MAP_DATA.each do |row|
row.each_byte do |cell|
@world.push cell
end
end
end
def test_world
(0...$MAP_ROWS).each do |row|
(0...$MAP_COLUMNS).each do |column|
print "#{@world[column + (row * $MAP_COLUMNS)].chr}"
end
print "\n"
end
print "\n"
end
def output_assembly
counter = $STARTING_ADDRESS
@world.each do |value|
print "var #{counter}\nset #{value}\n"
counter += 1
end
end
end

if __FILE__ == $0 then
MapMaker.new
end
Logged

Tags:
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines
.: Theme by Richard Marks :.
Valid XHTML 1.0! Valid CSS!