I moved to a new URL! Check it out!

posts tagged with: csharp

Dev Log: Polygon Collisions

Dev Log: Polygon Collisions
I never thought I'd be able to get polygon collisions working in Otter but this past week I managed to jam out a quick prototype of an overlapping polygon test that seems to be working.

Image


Probably not the most exciting image in the world, but it's pretty dang cool to me. I found this tutorial on the Separating Axis Theorem. This tutorial specifically has some great images, and amazing pseudocode with explanations that allowed me to finally understand what the hell to do. I still don't understand some things, like what exactly projecting a vector onto an axis means, but right now I think I have the core of it working.

I'll be working on getting the PolygonCollider integrated into Otter properly over the next few days. That means I'll have to get it working with each other Collider type which shouldn't be too crazy, but we'll see if I end up getting stumped by something!

Game Jam Procedural Generation Part IV

Game Jam Procedural Generation Part IV
The final part of this series about procedural generation for Starforger II will conclude with the last of the level generation code. In the last episode I talked about some of the details in generating rooms, tunnels, and other details in the level. In this final part I'll wrap it up by talking about how I place enemies, breakable blocks, and some final touches on the treasure room.

Image


The next thing in the generation of the level is the breakable blocks. These are blocks that the player can blow up using their bombs. I added these sort of at the last minute of the jam just to give some more interaction with the world, and it felt kinda fun to forge your own path through a big section of breakable blocks.

// put breakable blocks in random places I dunno
for (var yy = 10; yy < grid.TileRows; yy++) {
for (var xx = 0; xx < grid.TileColumns; xx++) {
if (CheckRect(xx, yy, 2, 2)) {
continue;
}
if (Rand.Chance(config.BreakableChance)) {
if (breakables < breakablesMax) {
Scene.Add(new BreakableBlock(xx * 16, yy * 16));
gridBreakable.SetRect(xx, yy, 2, 2);
breakables++;
}
if (config.Width > 1500) {
xx++;
}
if (config.Width > 1000) {
xx++;
}
}
}
}

I actually use a separate grid "gridBreakable" to keep track of where I've already placed blocks. This is less expensive in Otter. The alternative would be to do a collision check against all other breakable blocks which would take longer and longer if there are more breakable blocks being added. Whenever a block is added I add a 2 x 2 rectangle to the gridBreakable grid, and the function CheckRect() will check against the breakable grid and the ground grid, so I can't accidentally place a breakable block in the ground, or overlapping another breakable block.

Otter Updates

Otter Updates
Another quick round of updates to Otter this week. All of these changes are currently happening in the dev branch and will be moved to the default branch once I get some more documentation and testing done.

* Platforming Movement now supports jump through platforms
The PlatformingMovement component can jump through platforms now.

Image


The set up for this requires adding tags to the component that are to be used as jump through. The next step is adding a collider to the Entity that will act as the jump through platform detector. This collider should be only 1 pixel tall, and should be placed on the very bottom of the entity, and probably be the same width as the collider being used for the rest of the collisions. The component also allows for the player to push down + jump in order to drop through a platform.

* Tiny music changes
The Music class now keeps track of all of the created music objects in order to update them when the global volume is changed. Previously I was using the EventRouter but if the user ever decides to clear all of the event router subscriptions the music object would break.

* QuitKey has become QuitButton
The QuitKey has been replaced with a Button object. The default to quit is still the Escape key on the keyboard, but now it can be set to any key, mouse button, or joystick button.

* AutoTiling example
An example project has been added in the Examples folder which should show the basics on how to use the auto tiling system in Otter.

* Collider double-add bug fix
There was a bug in the Collider system that allowed a collider to be added to the internal collider list twice. If an Entity used AddCollider or SetCollider in its Added method those colliders would be added to the Scene twice. If one of those double-added colliders are then removed at some point then bad things would happen. This has been fixed by only allowing colliders to be added to the scene once.

Game Jam Procedural Generation Part III

Game Jam Procedural Generation Part III
In the last episode of Game Jam Procedural Generation I talked a lot about generating the base of the platforming level in Starforger II, and carving out rooms into the ground of the level.

Image


So now we have a basic level that with a bunch of empty rooms below the ground. The next step is going to be connecting those rooms together. To do this I built a quick class called a TunnelSnake (tunnel snakes rule) to dig tunnels from any point on the map to any other point. Here's the full source of that class:
class TunnelSnake {
public int X;
public int Y;
public int Width = 1;
public int Height = 2;

public int EndX;
public int EndY;

int verticalSteps;
int verticalStepMax = 4;
int forceHorizontal = 0;
int forceHDirection = 1;

public TunnelSnake(int x, int y, int endX, int endY) {
X = x;
Y = y;
EndX = endX;
EndY = endY;
}

public void Dig(GridCollider grid) {
while (X != EndX || Y != EndY) {
grid.SetRect(X, Y, Width, Height, false);

if (Rand.Chance(50) || forceHorizontal > 0) {

if (forceHorizontal > 0) {
X += forceHDirection;
Height = 2;
X = (int)Util.Clamp(X, 2, grid.TileColumns - 2);
}
else {
X += Math.Sign(EndX - X);
}

forceHorizontal--;
if (forceHorizontal == 0) {
verticalSteps = 0;
}
}
else {
verticalSteps++;

Y += Math.Sign(EndY - Y);

if (verticalSteps == verticalStepMax) {
forceHorizontal = Rand.Int(3, 15);
forceHDirection = Rand.Sign;
}
}

if (Rand.Chance(50)) {
if (Rand.Chance(50)) {
Width += Rand.Sign;
Width = (int)Util.Clamp(Width, 1, 5);
}
if (Rand.Chance(50)) {
Height += Rand.Sign;
Height = (int)Util.Clamp(Height, 2, 6);
}
}
}
}
}

Otter Updates

Otter Updates
There's been some recent happenings in the development branch of Otter. I've been busy fixing and polishing up some stuff, and also adding some of the last features I really want to get in before I can call it version 1.0. Here's some of the recent updates that can be seen in the commit log:

* Added LoadGridAutoTile() to the Tilemaps
In an effort to make game jam coding even faster I added auto tiling support to the Tilemap class. This is similar to the LoadGrid functions of Tilemap but now each tile will be placed depending on the neighboring tiles. I'll talk about this more when I merge it into the main branch, but for now it's usable and you should be able to figure out what's going on by checking out the source.

* Added SetAutoTileData() to Tilemap
If you're not using the default data set for auto tiling you can load your own data through this function. Calling this before using LoadGridAutoTile will let you use your own data. There's an example of how this data looks in the source for Tilemap.

* Added GetPowerSet() to Util
This is a handy function that can be used to get every possible combination of any amount of members of a list. Say you have a list of values {1, 2, 3}. GetPowerSet can return a list of lists that is every possible combination. So you would get {}, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}. This is useful for the auto tiling algorithm, and maybe other stuff.

* Fixed Text OutlineColor and ShadowColor
I think I fixed a bug where OutlineColor and ShadowColor were ignoring the alpha of the Text's main color which lead to some wacky stuff.

* Fixed window scaling bug
Fixed a bug where if you used SetWindowScale() or SetWindow() with only a width parameter you would get a slightly messed up window. Basically what was happening is that the height of the window was off by 1 pixel. This should now be working properly.

That's all of the major changes lately. If you're using Otter you can post questions or your projects on the forums! It's awesome to see what people are making using the engine.

Game Jam Procedural Generation Part II

Game Jam Procedural Generation Part II
In the last episode of Game Jam Procedural Generation I talked about the "outer layer" of my procedural generation code for my yet to be released game jam game. After the outer layer of stuff has been generated, that can be used to inform the "inner layer" of the procedural generation. So the outer layer in this case is the galaxy that the player can explore in their ship, and the inner layer is the actual side scrolling platformer level that they will explore.

Image


Where do we even begin? First keep in mind that I'm using Otter for all of this stuff, so if you see functions and code that looks totally unfamiliar, it's probably an Otter thing. Also keep in mind that all of this code was written during a 48 hour game jam, so it ain't pretty. I'm just going to be sharing big snippets of code and hopefully try to explain what is happening in each one.

In the last step I talked about how I create a config object to hold all of the possible fields that will be used to generate the level. Here's what that looks like:
class ScenePlatformingConfig {
public int Width;
public int Height;

public int ShipStartOffset;

public int TreasureDirection;
public int TreasureDistanceOffset;

public int GroundLevelOffset;

public bool Explored;
public bool Pillaged;

public int Jagginess;

public int Platforms;

public int DecaySpots;
public int DecayChance;

public int IslandSpots;
public int IslandSize;

public int Rooms;

public string Name;

public int BreakableChance;

public int CreatureChance;
}

Pretty straight forward. Just a simple class that will hold a bunch of values that can be then passed to the classes that generate the platforming level.