Scenario PaintHooks

PaintHooks provide a way for you to render your own custom graphics directly to the game map during play.  The PaintHooks provide you access to the .NET Graphics object that represents the visible portion of the game map.  You can use any .NET graphics calls to draw to the Graphics object.

There are two PaintHooks available, one happens after the background elements are rendered, but before the StarShip, StarSystem, and all of the other sprites in the game.  The second happens after all of the sprites have been rendered.

To hook into the rendering of the map, override one or both of these methods in your Scenario class's code:

public virtual void PaintHookBeforeSpriteRender(Graphics g, int offsetx, int offsety, int width, int height)

public virtual void PaintHookAfterSpriteRender(Graphics g, int offsetx, int offsety, int width, int height)

The Graphics "g" object provides the actual .NET Graphics object for the game map.  As such, you can use any .NET Graphics method to render to the object.

Offsetx and offsety provide the x/y offsets, or how much the map has been scrolled.  When determing the location to render information on the map, you should generally subtract these offset amounts.

Each square on the SV map is 30x30 pixels in size.  With this in mind, you can calculate the proper location within the Graphics object that corresponds to player 1's Capital like this:

StarSystem capital = Game.Players[0].Capital;
int x = capital.x * 30 - offsetx + 15;
int y = capital.y * 30 - offsety + 15;

Note that we add 15 to each value so that the result is "centered" on the StarSystem's location on the map.

The width and height parameters provide the current physical size of the visible map.  You can use this information to determine if what you want to draw is outside of the visible map area, avoiding unnecessary drawing calls.

Example

See the CollectTheScientists.cs Scenario for an example of a PaintHook.  It renders the current player's "Safe Zone", which is an area next to their Capital, as a shaded red box.  It also displays some status information in the upper left corner of the map so players can know how many of the Scientists have been collected.