I'm trying to figure out the best way of getting Box2D to play well with Ashley. Fortunately there are existing examples, such as those found in Overlap2D, so I don't have to do too much thinking – just as well as I'm shattered! My daughter wanted to see in the New Year, not realizing just how exhausted my wife and I are having had to cater to her relatives.
Much of today - at least once I got up - was taken up with spending time with my wife and daughter, playing Yoshi's Woolly World on the Wii-U, and Avian Attorney and Shovel Knight on the PC. For what it's worth, Shovel Knight is my favourite as it has very precise controls and a great retro feel. I think I may be putting in more than a few hours.
Eventually, when everyone else had gone to bed and the house was quiet, I managed to squeeze in a couple of hours programming. I'm impressed with Kotlin's when expression and smart casts. By the way, createFixture() is a nested function. Nice.
when (shapedComponent.shape) {
is CircleShaped -> {
val circle = CircleShape().apply { radius = shapedComponent.shape.radius } createFixture(circle) circle.dispose() }
is BoxShaped -> { val polygon = PolygonShape().apply {
setAsBox(shapedComponent.shape.halfWidth, shapedComponent.shape.halfHeight)
}
createFixture(polygon)
polygon.dispose();
}
}
Today's progress:
- Added Box2D physics and implemented a PhysicsSystem. It still needs some work, but the rudiments are there.
- Created a BodyComponent to represent Box2D bodies in Ashley.
- Created a ShapedComponent, which can currently be either circle shaped or box shaped.
- Learned about Kotlin's smart casts and when expression.