Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add density to gameobject xml

  • Loading branch information...
commit e71718fba90770c8f8c8999565f2792badddc5bc 1 parent 100f453
@reynders authored
View
2  README
@@ -16,6 +16,8 @@ for more demos see Demo.scala
Backlog
-------
* Body properties to gameobject xml
+* Force debug draw
+* log4j
* Other game objects: start point, end point
* Check performance bottlenecks
* Find out why there are pauses (-XInt helps?)
View
2  resources/gameobjects/ase_ship.xml
@@ -14,7 +14,7 @@
<sprite file="resources/gfx/ase_ship_turn_right.gif"
w="32" h="32" rows="1" columns="3" x_offset="0" y_offset="0" action="TURN_RIGHT" animation_fps="10"
rotates="true" rotation_count="36" />
- <mass_body type="polygon" center="0,0" points="-7,12 0,-13 7,12" />
+ <mass_body type="polygon" center="0,0" density="3.0" points="-7,12 0,-13 7,12" />
<force force_vector="-150,0" application_point="-2,-5" action="TURN_LEFT" />
<force force_vector="150,0" application_point="2,-5" action="TURN_RIGHT" />
<force force_vector="0,-300" application_point="0,0" action="ACCELERATE" />
View
39 src/main/scala/grambers/GameObject.scala
@@ -49,23 +49,27 @@ object GameObject {
def parseMassBodies(xml : NodeSeq) : Array[MassBody] = xml.map{massBody =>
parseMassBody(massBody)}.toArray[MassBody]
- def parseMassBody(xml : NodeSeq) : MassBody = (xml \\ "@type").text match {
- case "circle" =>
- val center = Util.strPointToPoint((xml \ "@center").text)
- val r = (xml \\ "@r").text.toDouble
- new CircleMassBody(center, r)
- case "rectangle" =>
- val center = Util.strPointToPoint((xml \ "@center").text)
- val w = (xml \\ "@w").text.toDouble
- val h = (xml \\ "@h").text.toDouble
- new RectangleMassBody(center, w, h)
- case "polygon" =>
- val center = Util.strPointToPoint((xml \ "@center").text)
- val points = Util.pointArrayStrToPointArray((xml \ "@points").text)
- new PolygonMassBody(center, points)
- case _ =>
- println("WARNING: don't know how to parse fixture type " + (xml \\ "@type").text + " xml: \n" + xml)
- new CircleMassBody(Point(0,0), 0.0)
+ def parseMassBody(xml : NodeSeq) : MassBody = {
+ val massBody = (xml \\ "@type").text match {
+ case "circle" =>
+ val center = Util.strPointToPoint((xml \ "@center").text)
+ val r = (xml \\ "@r").text.toDouble
+ new CircleMassBody(center, r)
+ case "rectangle" =>
+ val center = Util.strPointToPoint((xml \ "@center").text)
+ val w = (xml \\ "@w").text.toDouble
+ val h = (xml \\ "@h").text.toDouble
+ new RectangleMassBody(center, w, h)
+ case "polygon" =>
+ val center = Util.strPointToPoint((xml \ "@center").text)
+ val points = Util.pointArrayStrToPointArray((xml \ "@points").text)
+ new PolygonMassBody(center, points)
+ case _ =>
+ println("WARNING: don't know how to parse fixture type " + (xml \\ "@type").text + " xml: \n" + xml)
+ new CircleMassBody(Point(0,0), 0.0)
+ }
+ massBody.density = Util.parseDouble((xml \ "@density").text, 1.0)
+ massBody
}
def parseForces(xml : NodeSeq) : Array[Force] = xml.map {force => parseForce(force)}.toArray[Force]
@@ -108,7 +112,6 @@ class Sprite(val name : String, val w : Int, val h : Int,
if ((now - activeAnimationFrameShownSince) > animationDtBetweenFramesInMs) {
activeAnimationFrameIndex = (activeAnimationFrameIndex + 1) % images.size
activeAnimationFrameShownSince = now
- println("Aafi: " + activeAnimationFrameIndex)
}
} else {
isAnimating = true
View
7 src/main/scala/grambers/Util.scala
@@ -19,4 +19,11 @@ object Util {
else
str.toInt
}
+
+ def parseDouble(str : String, default: Double) : Double = {
+ if (str.equals(""))
+ default
+ else
+ str.toDouble
+ }
}
View
8 src/test/scala/grambers/UtilTest.scala
@@ -23,9 +23,15 @@ class UtilTest extends TestCase {
assertEquals(Point(-1,-1), Util.strPointToPoint("-1,-1"))
}
- def testParseInt(str : String, default : Int) {
+ def testParseInt {
assertEquals(1, Util.parseInt("1", 0))
assertEquals(-1, Util.parseInt("-1", 0))
assertEquals(42, Util.parseInt("", 42))
}
+
+ def testParseDouble {
+ assertEquals(1.0, Util.parseDouble("1.0", 0))
+ assertEquals(-1.0, Util.parseDouble("-1", 0))
+ assertEquals(42.0, Util.parseDouble("", 42))
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.