This weeks update is not overly action packed or feature filled, I’m afraid. With some sickness in the house (human as well as canine) free time was at a real premium. As such, feature wise and blog wise, this is going to be a very short one.
As mentioned in the last blog post, I finished fleshing out my collision API, although I did not follow through with my tentative plans for determining collisions between lines and rectangles/circles; instead I just finalized how I wanted everything to look and feel API wise and then proceeded to port the code back to the engine’s dev branch.
This turned out to be a fair bit of time, and in the end I just went ahead and did it adding new commits instead of doing a regular merge. I didn’t really want to include the history of all of the little missteps and experiments that I engaged in before I finalized the design that I wanted. I looked into squashing the commits together before merging or cherry picking just the commits I cared about, but in WebStorm I didn’t much care for the workflow; I wanted the ability to perform the merge but not do an immediate commit.
Undoubtedly there is a way to accomplish that using the tools at hand, but that sort of action is pretty foreign to how I generally need to interact with source control so I was a little out of my element and not interested in pursuing it much more at the time, since the time to actually work on anything was at a premium to begin with this week.
With the code merged over I followed through on making the new Collider class the superclass of Actor (and thus also an ancestor of Entity) with the minor code changes needed in those classes to support this.
One thing that was missing in the code at this point was the ability to change the collider type of an Actor/Entity instance; The Collider class itself wants to be told the initial type of collision volume it uses, which means that the call to super() in the Actor class needs to either choose one or include parameters that allow the specification of one.
That seemed way more cumbersome than it was worth since most things probably want to use rectangular collision anyway. As such, the Actor class creates a RECTANGLE collider type by default; jiving nicely with how the Actor class already takes a width and height as parameters. A couple of new methods are added to the Actor class to allow for switching.
The first, makeCircle(), converts the collision type of the object into a circle by changing around the underlying members as appropriate, while the second, makeRectangle() does the reverse. Both methods take an optional boolean that indicates if the origin should be modified; for example, when turning the collision bounds into a circle, you probably want the origin to be the center of the circle.
With that done I got as far as updating the ts-tennis code to use the new version of the engine and verify that everything still works.
What remains to do (which I may do tonight; these blog posts are prepared the night before I post them) is use the new engine features in the existing ts-tennis code base. This would alter how the collision between the paddles and the ball is handled, cleaning up the code significantly, but would also allow for the use of sprite sheets for things like the multiple states of the ball.