I moved to a new URL! Check it out!

posts tagged with: sfml

Dev Log: Ogmo Integration

Dev Log: Ogmo Integration
I'm starting to put together a quick example game for my C# SFML framework during the Ludum Dare weekend of jam madness, and part of this will be Ogmo Editor integration, YEAH!

Image


Loading XML seems to be pretty straight forward so far in C#, but I do miss some of the XML features of AS3. Right now in that image I'm just loading a grid collider and a tile map from the XML data in Ogmo, and the green box is a player that can run around and collide with the tiles.

For this example project I'm just going to make a quick and easy platforming and collecting game. I want to make it as complete of an example as I can, and not just a single level room. Multiple levels, menus, saving and loading, stats... I want all that kinda stuff in this example so people can see a sort of "complete" game made with my framework.

I'm hoping to have this done fairly soon, but on Wednesday I'm taking off for PAX and I don't think I'm going to be working on anything during those four days of insanity.

Dev Log: Screen Scalin'

Image


Look out, it's a 6mb animated gif! Another thing off my task list was scaling the game window to different resolutions. I wanted to keep the same stuff on the screen as I scaled the game window up and down (since I imagine people will want to play games at varying resolutions) so what I'm doing right now is just scaling a render texture to the size of the window. I guess we'll see how horrible or okay this approach is soon enough.

I've been trying to figure out the best way to start making assets in terms of their resolution. Right now my idea is to just pick a resolution that the game will natively be in, like 1920 x 1080, and just make all assets as if the game is being played at that resolution. Scaling that resolution up to 2440 x 1440, or down to something like 720 x 480, doesn't seem to be that bad. My only concern is keeping text readable at low resolutions, so I might have to do some extra work to maybe change fonts or text sizes depending on the resolution.

Image


For Snapshot, we just chose a virtual resolution of 1600 x 1200 and made all assets as if the game was being played at that resolution. This seemed to work out okay in the end, but we did spend a lot of time at the beginning of the project trying to figure out the best solution for this issue. If I were smarter I'd be doing something like having assets for different resolutions and loading the right one depending on the resolution but I have no idea how to do that for now so I'll go for the short and simple approach!

Dev Log: Collisions!

Dev Log: Collisions!
I'm back working on my C# and SFML framework after many weeks of very very slow progress. I've been tackling all the different kinds of collision detection that I want to have, and although the rectangle to rectangle collisions are easy, stuff like rectangle to grid started to get a little messy.

So then I got to the point where I wanted to add line segments and circles into the mix, and even with just these four types I found myself in a maze of code and math.

After trying to figure out some math on my own, I finally stumbled upon some line segment intersection code that helped out quite a bit. After I got that running, I was also able to find a line segment to circle collision example, and that gave me enough to fill in the rest of the blanks.

So now I have four collider types: Rectangles, Grids, Circles, and Lines, and they are all able to collide with each other. I haven't super thoroughly tested this stuff out yet though, so I'm sure some of it must be broken somewhere, but for the rest of the week I'll be testing this stuff out a little more.

Dev Log: Code Snippets

Dev Log: Code Snippets
Yesterday I posted about my amazing tile collisions, so I thought I'd post a quick code example on some of the things involved with setting it up. This isn't any of the code from the actual collision detection, but it's code that most users would see if they ever use this framework.

This is the code for the moving white box:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Otter;

namespace HelloSFML {
class BoxDude : Entity {

BasicMovement movement = new BasicMovement(500, 500, 50);
Image img;
BoxCollider hitbox;
Axis axis = new Axis();

uint size = 50;

public BoxDude() {
refreshSize();

AddComponent(movement);
AddComponent(axis);

movement.CollidesWith.Add(1);

axis.AddKeys(Key.W, Key.D, Key.S, Key.A);

movement.Axis = axis;
}

void refreshSize() {
RemoveCollider(hitbox);
RemoveGraphic(img);
img = Image.CreateRectangle(size);
hitbox = new BoxCollider(size, size, 0);
AddCollider(hitbox);
SetGraphic(img);
movement.Collider = hitbox;
}

public override void Update() {
base.Update();

img.Color = Color.White;
if (Collide(X, Y, 1) != null) {
img.Color = Color.Red;
}

if (Input.Instance.KeyPressed(Key.Period)) {
size -= 10;
refreshSize();
}
if (Input.Instance.KeyPressed(Key.Comma)) {
size += 10;
refreshSize();
}
}
}
}

Dev Log: Tile Collisions!

Image


Finally after weeks of putting off the task I got around to implementing the tile based collision system in my C# SFML framework. Right there in that animation above is a simple movement that is actively colliding with the tiles, stopping the movement. I can scale up and down the hit box and sometimes it does get caught on an overlap as a result which is why it turns red.

I used a couple of references to get this working including Flashpunk's own tile collision which can be found in the source code, and I also took a peek at C# Punk to see how it was implemented there as well. My solution is similar, and maybe worse, but for now it works and that's all that matters.

With the tile based collision in, I have all the power in the world to make a platformer if I wanted... well, as long as it didn't have any slopes.

Dev Log: Code Sample

Dev Log: Code Sample
I'm slowly getting back into the groove of programming again after a long hiatus. In case you're just tuning in, I'm working on a C# SFML framework for 2d games. Right now I'm calling the framework Otter, and eventually when I get it to a more presentable state I'll be open sourcing it on BitBucket somewhere so other people can use it, and contribute to it.

For now here's a small teaser of how some code looks when using the framework. This is for the entity that the player controls with mouse and keyboard or a PC game controller. It flies around in a top down view in the scene. It's a big chunk of code, so I'm putting it behind the "read more" link!