<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>.gitignore</filename>
    </added>
    <added>
      <filename>door.rb</filename>
    </added>
    <added>
      <filename>door_1.png</filename>
    </added>
    <added>
      <filename>door_2.png</filename>
    </added>
    <added>
      <filename>fire.wav</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -1,5 +1,6 @@
 require 'config'
 require 'sprite'
+require 'door'
 
 class Map
   Infinity = 1.0 / 0
@@ -11,6 +12,7 @@ class Map
   attr_reader   :window
   attr_reader   :textures
   attr_accessor :sprites
+  attr_accessor :doors
   attr_reader   :width
   attr_reader   :height
   
@@ -21,6 +23,20 @@ class Map
     @width  = matrix_row_column[0].size
     @height = matrix_row_column.size
     @window = window
+    @doors  = [[nil] * @width] * @height
+    
+    row = 0
+    while(row &lt; @height)
+      col = 0
+      while(col &lt; @width)
+        if @matrix[row][col] == -1
+          @doors[row][col] = Door.new
+        end
+        col += 1
+      end
+      row += 1
+    end
+    
     @textures = [nil]
     texture_files.each {|tex_file|
       pair = {}
@@ -67,11 +83,22 @@ class Map
     
     return Infinity, Infinity if(ax &lt; 0 || ax &gt; Config::WINDOW_WIDTH || ay &lt; 0 || ay &gt; Config::WINDOW_HEIGHT)
     
-    if(!hit?(ax, ay))
+    if(!hit?(ax, ay, angle, :horizontal))
       # Extend the ray
       return find_horizontal_intersection(ax, ay, angle)
     else
-      return ax, ay
+      column, row = Map.matrixify(ax, ay)
+      
+      if door?(row, column)
+        half_grid = GRID_WIDTH_HEIGHT / 2
+        door_offset = half_grid * Math::tan(angle * Math::PI / 180)
+        
+        door_offset *= -1 if angle &gt; 90 or angle &lt; 270
+        
+        return ax + door_offset, ay + half_grid
+      else
+        return ax, ay
+      end
     end
   end
   
@@ -93,11 +120,21 @@ class Map
     # If the casted ray gets out of the playfield, emit infinity.
     return Infinity, Infinity if(bx &lt; 0 || bx &gt; Config::WINDOW_WIDTH || by &lt; 0 || by &gt; Config::WINDOW_HEIGHT)
     
-    if(!hit?(bx, by))
+    if(!hit?(bx, by, angle, :vertical))
       #Extend the ray
       return find_vertical_intersection(bx, by, angle)
     else
-      return bx, by
+      column, row = Map.matrixify(bx,by)
+      
+      if door?(row, column)
+        half_grid = GRID_WIDTH_HEIGHT / 2
+        door_offset = half_grid * Math::tan(angle * Math::PI / 180) * -1
+        dx = (angle &gt; 90 &amp;&amp; angle &lt; 270) ? half_grid * -1 : half_grid
+        
+        return bx + dx, by + door_offset
+      else
+        return bx, by
+      end
     end
   end
   
@@ -105,7 +142,7 @@ class Map
     column = (x / GRID_WIDTH_HEIGHT).to_i
     row    = (y / GRID_WIDTH_HEIGHT).to_i
     
-    texture_id = @matrix[row][column]
+    texture_id = @matrix[row][column] #+ 1
     
     return @textures[texture_id][:south][x % TEX_WIDTH] if type == :horizontal and angle &lt; 180
     return @textures[texture_id][:north][(TEX_WIDTH - x) % TEX_WIDTH] if type == :horizontal and angle &gt; 180
@@ -114,13 +151,27 @@ class Map
   end
   
   def walkable?(row, column)
-    return row &gt;= 0 &amp;&amp; row &lt; @height &amp;&amp; column &gt;= 0 &amp;&amp; column &lt; @width &amp;&amp; @matrix[row][column] == 0
+    return on_map?(row, column) &amp;&amp; @matrix[row][column] == 0
   end
   
-  def hit?(x,y)
+  def hit?(x, y, angle = nil, type = nil)
     column, row = Map.matrixify(x,y)
     
-    return on_map?(row, column) &amp;&amp; !self.walkable?(row, column)
+    if(door?(row, column) &amp;&amp; (!angle.nil?) &amp;&amp; (type == :horizontal || type == :vertical))
+      offset = (type == :horizontal) ? (x % GRID_WIDTH_HEIGHT) : (y % GRID_WIDTH_HEIGHT)
+      offset_door = ( GRID_WIDTH_HEIGHT / 2 ) * Math::tan(angle * Math::PI / 180) * -1
+      
+      offset_on_door = offset + offset_door
+      
+      return @doors[row][column].pos &lt; offset_on_door if type == :horizontal
+      return @doors[row][column].pos &lt; offset_on_door if type == :vertical
+    end
+    
+    return !self.walkable?(row, column)
+  end
+  
+  def door?(row, column)
+    return on_map?(row, column) &amp;&amp; @matrix[row][column] == -1
   end
   
   def on_map?(row, column)</diff>
      <filename>map.rb</filename>
    </modified>
    <modified>
      <diff>@@ -8,6 +8,7 @@ require 'weapon'
 require 'player'
 require 'ai_player'
 require 'sprite'
+require 'door'
 
 module ZOrder
   BACKGROUND = 0
@@ -28,11 +29,12 @@ class GameWindow &lt; Gosu::Window
         [1, 0, 0, 0, 0, 0, 0, 1],
         [1, 0, 0, 0, 1, 1, 1, 1],
         [1, 0, 0, 0, 1, 0, 0, 1],
-        [1, 0, 0, 0, 0, 0, 0, 1],
+        [1, 0, 0, 0,-1, 0, 0, 1],
         [1, 0, 0, 0, 1, 0, 0, 1],
         [1, 0, 0, 0, 1, 0, 0, 1],
         [1, 1, 1, 1, 1, 1, 1, 1]],
         [
+          { :north =&gt; 'door_1.png',  :east =&gt; 'door_2.png',  :south =&gt; 'door_1.png',  :west =&gt; 'door_2.png' },
           { :north =&gt; 'blue1_1.png', :east =&gt; 'blue1_2.png', :south =&gt; 'blue1_1.png', :west =&gt; 'blue1_2.png' },
           { :north =&gt; 'grey1_1.png', :east =&gt; 'grey1_2.png', :south =&gt; 'grey1_1.png', :west =&gt; 'grey1_2.png' },
           { :north =&gt; 'wood1_1.png', :east =&gt; 'wood1_2.png', :south =&gt; 'wood1_1.png', :west =&gt; 'wood1_2.png' },</diff>
      <filename>wolf3d.rb</filename>
    </modified>
  </modified>
  <removed type="array">
    <removed>
      <filename>door_1.gif</filename>
    </removed>
    <removed>
      <filename>door_2.gif</filename>
    </removed>
  </removed>
  <parents type="array">
    <parent>
      <id>bbf45266496a1eefeaf7bc350e2e654a72a734ba</id>
    </parent>
  </parents>
  <author>
    <name>Ninh Bui (Phusion)</name>
    <email>ninh@phusion.nl</email>
  </author>
  <url>http://github.com/FooBarWidget/rubystein/commit/ebfbc31fe7b99e7f3caffb54d6804c810086f060</url>
  <id>ebfbc31fe7b99e7f3caffb54d6804c810086f060</id>
  <committed-date>2009-04-17T05:38:57-07:00</committed-date>
  <authored-date>2009-04-17T05:38:57-07:00</authored-date>
  <message>Logics for the doors have been implemented</message>
  <tree>37ed4f792367902c8353ab55d5e4085cac977f3a</tree>
  <committer>
    <name>Ninh Bui (Phusion)</name>
    <email>ninh@phusion.nl</email>
  </committer>
</commit>
