Commits

Anonymous committed 6e21e90

fixing

  • Participants
  • Parent commits 3afba9f

Comments (0)

Files changed (6)

classes/board.lua

   self.border=50
   self.body_left=love.physics.newBody(pWorld, self.x-(self.border)/2, self.y+self.h/2, 0, 0)
   self.shape_left=love.physics.newRectangleShape( self.body_left, 0, 0,self.border,self.h,0)
+  self.shape_left:setData( {tipo="board_left"} )
   self.body_right=love.physics.newBody(pWorld, self.x+self.w+self.border/2, self.y+self.h/2, 0, 0)
   self.shape_right=love.physics.newRectangleShape( self.body_right, 0, 0 , self.border,self.h , 0)
-  self.body_bot=love.physics.newBody(pWorld, self.x+self.w/2, self.y+self.h+self.border/2, 0, 0)
-  self.shape_bot=love.physics.newRectangleShape( self.body_bot, 0, 0,self.w+self.border*2,self.border,0)
+  self.shape_right:setData( {tipo="board_right"} )
+  self.body_bottom=love.physics.newBody(pWorld, self.x+self.w/2, self.y+self.h+self.border/2, 0, 0)
+  self.shape_bottom=love.physics.newRectangleShape( self.body_bottom, 0, 0,self.w+self.border*2,self.border,0)
+  self.shape_bottom:setData( {tipo="board_bottom"} )
 end
 
 function board:update(dt)

classes/object.lua

   end
   self.body=love.physics.newBody(pWorld, self.x, self.y, _mass, _mass)
   self.shape=love.physics.newPolygonShape( self.body, unpack(self.vertices))
+  if pInteractive then
+    self.shape:setData( {tipo="object",value=self} )
+  elseif pNext then
+  	self.shape:setData( {tipo="object_next",value=self} )
+  else
+  	self.shape:setData( {tipo="objects",value=self} )
+  end
 end
 
 function object:update(dt)
   love.graphics.polygon('line', self.shape:getPoints())
 end
 
+function object:stopInteractive()
+	self.interactive=false
+	self.shape:setData( {tipo="objects",value=self} )
+end

classes/sensor.lua

   self.x=px
   self.y=py
   self.activate=0
+  --self.shape:setData( {tipo="sensor",value=self} )
 end
 
 function sensor:update(dt)

doc/files/utils.html

 	<td class="summary">copy tables copy input table in new table </td>
 	</tr>
 
+	<tr>
+	<td class="name" nowrap><a href="#to_string">to_string</a>&nbsp;(data, indent)</td>
+	<td class="summary">Converts an arbitrary data type into a string.</td>
+	</tr>
+
 </table>
 
 
 </dd>
 
 
+
+
+<dt><a name="to_string"></a><strong>to_string</strong>&nbsp;(data, indent)</dt>
+<dd>
+Converts an arbitrary data type into a string. Will recursively convert tables. 
+
+
+<h3>Parameters:</h3>
+<ul>
+	
+	<li>
+	  <code><em>data</em></code>: The data to convert.
+	</li>
+	
+	<li>
+	  <code><em>indent</em></code>: (optional) The number of times to indent the line. Default is 0.
+	</li>
+	
+</ul>
+
+
+
+
+
+
+<h3>Return value:</h3>
+<ul>A string representation of a data, will be one or more full lines.</ul>
+
+
+
+</dd>
+
+
 </dl>
 
 
     end
   end
 
-
   -- gui
   --
   --
 function state:mousereleased(x, y, button)
 end
 
+function addCollision(a, b, coll)
+	--print("add:a")
+	--print(to_string(a))
+  --print("add:b")
+  --print(to_string(b))
+  if a.tipo=="object" or b.tipo=="object" then
+  	print("add2")
+ 		local _obj=b
+ 		local _oth=a
+  	if b.tipo=="object" then
+  		_obj=b
+  		_oth=a
+  	else
+  		_obj=a
+  		_oth=b
+    end
+    print("add3")
+    if _oth.tipo=="objects" or _oth.tipo=="board_bottom" then
+    	print("add4")
+    	_obj.value:stopInteractive()
+    	table.insert(state.objects,_obj.value)
+		  state.object=_G.object:new(pLevel,state.board,state.world,true,true,false)
+		  state.next=_G.object:new(pLevel,state.board,state.world,false,false,true)
+    end
+  end
+  print("add-fine")
+end
+
+function persistCollision(a, b, coll)
+	--print("persist:a")
+	--print(to_string(a))
+  --print("persist:b")
+  --print(to_string(b))
+end
+
+function remCollision(a, b, coll)
+	--print("rem:a")
+	--print(to_string(a))
+  --print("rem:b")
+  --print(to_string(b))
+end
+
+function resultCollision(a, b, coll)
+	--print("result:a")
+	--print(to_string(a))
+  --print("result:b")
+  --print(to_string(b))
+end
+
 function state:newLevel(pLevel)
   -- physics
   state.world = love.physics.newWorld(0,0,love.graphics.getWidth( ),love.graphics.getHeight(),0, pLevel*100+200,true)
   state.world:setMeter(30)
+  state.world:setCallbacks(addCollision, persistCollision, remCollision, resultCollision)
   -- classes
   state.objects={}
   state.board=_G.board:new(pLevel,state.world)
   state.object=_G.object:new(pLevel,state.board,state.world,true,true,false)
   state.next=_G.object:new(pLevel,state.board,state.world,false,false,true)
   state.speed = pLevel
-end
+end
   for k, v in pairs(t) do u[k] = v end
   return setmetatable(u, getmetatable(t))
 end
+
+
+-- 
+---Converts an arbitrary data type into a string. Will recursively convert 
+-- tables. 
+-- 
+--@param data   The data to convert. 
+--@param indent (optional) The number of times to indent the line. Default 
+--              is 0. 
+--@return A string representation of a data, will be one or more full lines. 
+function to_string(data, indent) 
+    local str = "" 
+
+    if(indent == nil) then 
+        indent = 0 
+    end 
+
+    -- Check the type 
+    if(type(data) == "string") then 
+        str = str .. (" "):rep(indent) .. data .. "\n" 
+    elseif(type(data) == "number") then 
+        str = str .. (" "):rep(indent) .. data .. "\n" 
+    elseif(type(data) == "boolean") then 
+        if(data == true) then 
+            str = str .. "true" 
+        else 
+            str = str .. "false" 
+        end 
+    elseif(type(data) == "table") then 
+        local i, v 
+        for i, v in pairs(data) do 
+            -- Check for a table in a table 
+            if(type(v) == "table") then 
+                str = str .. (" "):rep(indent) .. i .. ":\n" 
+                str = str .. to_string(v, indent + 2) 
+            else 
+                str = str .. (" "):rep(indent) .. i .. ": " .. 
+to_string(v, 0) 
+            end 
+        end 
+    else 
+        print( "Error: unknown data type: ".. type(data)) 
+    end 
+
+    return str 
+end