Commits

mcc committed 54fa72f

Simple ball bounce demo. Add some utility to project_util.

Comments (0)

Files changed (4)

media/example.svg

      inkscape:pageopacity="1"
      inkscape:pageshadow="2"
      inkscape:zoom="0.7"
-     inkscape:cx="572.09422"
-     inkscape:cy="283.88112"
+     inkscape:cx="343.52279"
+     inkscape:cy="341.02398"
      inkscape:document-units="px"
      inkscape:current-layer="layer1"
      showgrid="false"
        sodipodi:rx="15.152288"
        sodipodi:cy="416.15222"
        sodipodi:cx="139.40105"
-       id="path3019"
+       id="focus"
        style="fill:#ffff00;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
        sodipodi:type="arc"
-       polycode:onCollide="print("BANG")" />
-    <rect
-       style="fill:#55ffdd;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
-       id="rect2999"
-       width="94.285713"
-       height="24.285715"
-       x="389.09467"
-       y="446.6748"
-       transform="matrix(0.92643943,0.37644386,-0.37644386,0.92643943,0,0)" />
-    <rect
+       polycode:onCollide="print(&quot;BANG&quot;)"
+       polycode:restitution="0.5"
+       polycode:density="0.5" />
+    <path
        style="color:#000000;fill:#55ffdd;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
-       id="rect3005"
-       width="114.28571"
-       height="22.857143"
-       x="-132.98544"
-       y="765.11328"
-       transform="matrix(0.78374345,-0.62108471,0.62108471,0.78374345,0,0)" />
-    <rect
+       d="M 215.71429,524.28572 301.42858,562.85715 290,584.28572 204.28572,548.57143 z"
+       id="path3044"
+       inkscape:connector-curvature="0" />
+    <path
        style="color:#000000;fill:#55ffdd;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
-       id="rect3007"
-       width="88.571426"
-       height="22.857143"
-       x="519.49548"
-       y="497.43747"
-       transform="matrix(0.87704631,0.48040584,-0.48040584,0.87704631,0,0)" />
-    <rect
+       d="m 318.57143,677.14286 88.57143,-70 L 425.71429,630 334.28571,698.57143 z"
+       id="path3046"
+       inkscape:connector-curvature="0" />
+    <path
        style="color:#000000;fill:#55ffdd;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
-       id="rect3011"
-       width="95.714287"
-       height="21.428572"
-       x="-330.38544"
-       y="1114.6279"
-       transform="matrix(0.60256751,-0.79806792,0.79806792,0.60256751,0,0)" />
-    <rect
+       d="m 220,702.85715 78.57143,44.28571 -8.57143,20 -78.57143,-42.85714 z"
+       id="path3048"
+       inkscape:connector-curvature="0" />
+    <path
        style="color:#000000;fill:#55ffdd;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
-       id="rect3013"
-       width="97.14286"
-       height="18.571428"
-       x="947.05621"
-       y="515.8844"
-       transform="matrix(0.85405852,0.52017694,-0.52017694,0.85405852,0,0)" />
-    <rect
+       d="m 322.85714,348.57143 285.71429,45.71428 -10,28.57143 -280,-42.85714 z"
+       id="path3050"
+       inkscape:connector-curvature="0"
+       transform="translate(-5.7142857,448.57143)" />
+    <path
        style="color:#000000;fill:#55ffdd;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
-       id="rect3015"
-       width="287.14285"
-       height="28.571428"
-       x="429.71344"
-       y="748.46313"
-       transform="matrix(0.98964347,0.1435472,-0.1435472,0.98964347,0,0)" />
+       d="M 697.14286,481.42857 754.28571,410 l 21.42858,20 -61.42858,75.71429 z"
+       id="path3052"
+       inkscape:connector-curvature="0"
+       transform="translate(-5.7142857,448.57143)" />
+    <path
+       style="color:#000000;fill:#55ffdd;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
+       d="m 547.14286,485.71429 84.28571,51.42857 -12.85714,17.14285 -81.42857,-55.71428 z"
+       id="path3054"
+       inkscape:connector-curvature="0"
+       transform="translate(-5.7142857,448.57143)" />
+    <path
+       style="color:#000000;fill:#55ffdd;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
+       d="m 732.85714,24.285714 30,-2.857143 L 770,324.28571 l -31.42857,0 z"
+       id="path3056"
+       inkscape:connector-curvature="0"
+       transform="translate(-5.7142857,448.57143)" />
   </g>
 </svg>

media/overlay/game/onLoad.lua

 -- On Load
-memory_setup()
+memory_setup()
+
+ball = id("focus")
+ballstart = r(vDup(ball:getPosition()))

media/overlay/game/onUpdate.lua

 -- On Update
+
+local p = ball:getPosition()
+if p.y > surface_height + 100 then
+	setPosition(ball, ballstart.x, ballstart.y)
+end
+
 memory_drain()

source/project_util.lua

 		elseif tbl.__info and tbl.__info.__isclass then
 			return string.format("<class %s>", tbl.__info.__name)
 		elseif tbl.__info and tbl.__info.__class then
-			return string.format("<object %s>", tbl.__info.__class.__info.__name)
+			local name = tbl.__info.__class.__info.__name
+			if name == "Vector3" then
+				return string.format("<vector %s, %s, %s>", tbl.x, tbl.y, tbl.z)
+			else
+				return string.format("<object %s>", tbl.__info.__class.__info.__name)
+			end
 		else 
 			local sb = {}
 			local first = true
 end
 
 function setPosition(entity, x, y)
-	screen():setTransform(entity, Vector3(x,y,0), 0)
-	screen():wakeUp(entity) -- So gravity works
+	local physics = PhysicsScreen(screen())
+	physics:setTransform(entity, Vector3(x,y,0), 0)
+	physics:wakeUp(entity) -- So gravity works
 end
 
 function help(path)