Menu

BASeBlock and Polygon Blocks

June 28, 2012 - .NET, C#, Programming, Windows

That’s right. The latest version of BASeBlock now adds a working Polygon block. There was a lot of reengineering to be done, but it works realistically; which is to say, a ball will bounce at the proper angle.

Some boring technical stuff

Having Support for arbitrary polygons is something of a pipe dream I had. Every attempt failed. What made it possible was in fact me adding ellipse blocks, in which I unwittingly added support for polygon collisions, since the Ellipse Block was in fact just a polygon and used euclidean geometry to determine if and make adjustments to ball collisions. After getting that working, I realized it would make sense for EllipseBlock (and possibly other kinds of blocks) to simply derive from an Abstract PolygonBlock that did the work of dealing with the details of the polygon itself, while the derived class pretty much just handles it’s own fields and creates the Polygon to be used. The math itself actually uses some of the same code that was being used for ball collisions, which takes two polygons, a speed (for the initial polygon) and returns a result structure that determines if they currently intersect, if they will intersect, and how to adjust the latter to be no longer touch the former. I use that last item to create a collision normal, and reflect the speed vector of the ball across a vector perpendicular to it.

A lot of other code needed to be changed to streamline the support of it. iEditorBlockExtensions, a interface used for adding editor-oriented support, had to add a method to allow for the overriding of the selection “pulse” drawing, which at the time only drew the rect. A lot of other code that assumed that the BlockRectangle was the definitive source of the block’s shape had to be changed. This actually ended up in the addition of another virtual method to the base Block class, “GetPoly()” which of course in default implementations returns the polygon of the rectangle, but PolygonBlock not surprisingly overrides this and returns it’s own poly. The base implementation of EditorDraw() fills the polygon dictated by “FillPoly” so this works out just fine; The Editor now allows selection of polygon-shaped blocks by actually clicking on them (rather then in their rectangle) as well as highlighting only the poly (again, as opposed to their rectangle).

Currently it only supports convex polygons, but that is not planned to change, since a concave polygon can easily be simulated with convex polies anyway. (And I haven’t actually tested it with non-convex poly’s so I’m really just assuming for the moment it doesn’t work for them).

It will still need some touching up, and I’ve been making a few other minor cosmetic and UI changes (allowing drag-drop of files on the editor, better dirty-file prompts (for unsaved documents) and so forth). The only area that needs significant work and/or rework is probably the path editing.

In summary, the Next Version of BASeBlock is going to be a significant upgrade, with a completely new domain of blocks to use and explore. I still need to make some sort of “standard” LevelSet that isn’t the crappy LevelBuilders included with the game.

Have something to say about this post? Comment!