I moved to a new URL! Check it out!

posts dated from: september 2015

Otter Example: Sound and Music

Otter Example: Sound and Music
Another Otter example coming fresh off the ovens! This one marks the 14th example, and covers playing sound and music using the framework. The full example is right here, and here's a glimpse at the codes:
using Otter;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SoundStuff {
class Program {
static void Main(string[] args) {
// Create a Game.
var game = new Game("Sound and Music");
// Start the game with a new SoundScene.
game.Start(new SoundScene());
}
}

class SoundScene : Scene {
// Load the sounds into individual Sound objects.
public Sound SoundOne = new Sound("sound1.wav");
public Sound SoundTwo = new Sound("sound2.wav");
public Sound SoundThree = new Sound("sound3.wav");

// Load the music into a Music object.
public Music Music = new Music("music.ogg");

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

// Play sounds for the 1, 2, and 3 keys being pressed.
if (Input.KeyPressed(Key.Num1)) {
SoundOne.Play();
}
if (Input.KeyPressed(Key.Num2)) {
SoundTwo.Play();
}
if (Input.KeyPressed(Key.Num3)) {
SoundThree.Play();
}

// Pause or play the music on the spacebar being pressed.
if (Input.KeyPressed(Key.Space)) {
if (Music.IsPlaying) {
Music.Pause();
}
else {
Music.Play();
}
}

// Adjust the volume of the sounds with up and down keys.
if (Input.KeyDown(Key.Up)) {
Sound.GlobalVolume += 0.02f;
}
if (Input.KeyDown(Key.Down)) {
Sound.GlobalVolume -= 0.02f;
}

// Adjust the volume of the music with left and right keys.
if (Input.KeyDown(Key.Right)) {
Music.GlobalVolume += 0.02f;
}
if (Input.KeyDown(Key.Left)) {
Music.GlobalVolume -= 0.02f;
}
}
}
}
So easy!

Now there's almost nothing holding you back from making a video game using Otter if you so choose. There's still a handful of examples to go, but this one I believe marks the last in the series that is necessary to make a complete thing. Input, graphics, collision, and sound should cover a pretty large portion of making a game, right?

Otter Example: Ogmo Editor Levels

Otter Example: Ogmo Editor Levels
A new example for using my game making framework is now online! Check it out here!

Image


This Otter example goes over how to take levels made using Ogmo Editor and load them up for making games with them. The example code is actually pretty straight forward, I think!
using Otter;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OgmoEditorStuff {
class Program {
static void Main(string[] args) {

// Create a new Game.
var game = new Game("Ogmo Editor Example");
// Set the background color to see stuff a little better.
game.Color = Color.Cyan;

// Create a new Scene to use for the Ogmo data.
var scene = new Scene();

// The path to the level to be loaded.
var pathLevel = "Level.oel";
// The path to the Ogmo Project to use when loading the level.
var pathProject = "OgmoProject.oep";

// Create a new OgmoProject using the .oep file.
var OgmoProject = new OgmoProject(pathProject);

// Ensure that the grid layer named "Solids" gets the Solid collision tag when loading.
OgmoProject.RegisterTag(Tags.Solid, "Solids");

// Load the level into the Scene.
OgmoProject.LoadLevelFromFile(pathLevel, scene);

// Start the game using the Scene with the loaded Ogmo Level.
game.Start(scene);
}
}

// Collision tags to use in the game.
enum Tags {
Solid,
Player,
Coin,
Exit
}

// A Player Entity to match the Entity in the Ogmo Project.
class Player : Entity {
public Player(float x, float y) : base(x, y) {
var img = Image.CreateRectangle(32, 32, Color.Red);
AddGraphic(img);
SetHitbox(32, 32, Tags.Player);
}
}

// A Coin Entity to match the Coin in the Ogmo Project.
class Coin : Entity {
public Coin(float x, float y) : base(x, y) {
var img = Image.CreateRectangle(16, 16, Color.Yellow);
AddGraphic(img);
SetHitbox(16, 16, Tags.Coin);

// Adjust the position here because of the Origin in the Ogmo Project.
X += 8;
Y += 8;
}
}

// An Exit Entity to match the Exit in the Ogmo Project.
class Exit : Entity {
public Exit(float x, float y) : base(x, y) {
var img = Image.CreateRectangle(64, 64, Color.Magenta);
AddGraphic(img);
SetHitbox(64, 64, Tags.Exit);
}
}
}
But you should check out the full example for yourself for more details.

Doodle Post

Image

Dev Log: Pushing and Carrying

Dev Log: Pushing and Carrying
I've managed to make a little bit more progress on the platforming front yesterday for pushing and carrying things around.

Image


I had a basic way to push objects pretty similar to how I used to have it set up in Verge, but now with all the fancy features of C# I'm able to do it in a more clean way. My old GML GameMaker code definitely had some if statements that went across the whole code window and more, so hopefully this version ends up being a little bit more organized than that.

So pushing one single block around seems to be working well enough now, but when it comes to big stacks of blocks there might be some problems.

Image


My ideal scenario is that a stack of objects can be carried by another object, and I also want to make it work with pushing objects as well. Objects that can be pushed should always push each other, so a long stack of boxes should be able to be pushed by a moving object, and then after that I can take care of things of how much an object should slow down when pushing and all that good stuff.

On the real life front I am still in the middle of moving chaos, so things are a little weird for me still, but I'm somehow managing to make something work with my laptop at a coffee shop.

Doodle Post

Image

Dev Log: Platforming Frustrations!

Dev Log: Platforming Frustrations!
Game development ain't all birthday cakes and flowers as some may have you believe. As I move forward with this platformer game I'm realizing how much I actually don't know about platforming! You might think I know a lot with so many platformers under my belt, but now my ideas are way outpacing my abilities as a programmer.

Right now I'm trying to code this system and I'm making little to no progress even though a lot of code is being written. For example I'm currently working on the structure of how objects will update. The simplest way at first is to have each object go through its platforming operations one at a time in their execution order, but this leads to weird issues down the road. An object higher up in the order will have priority over other objects, and this is not something I want!

My new approach is to have each object update in parallel with one another, one pixel at a time. Each object will calculate its speeds and then buffer them into their remainder. Then a PhysicsHandler object goes through and moves all of the objects one pixel at a time each in parallel. This might not make any sense at all, but it's a set up for objects being able to push one another. For example if two moving objects collide, I want them to collide in the right spot, and I think the only way to do this is to move them one pixel at a time in parallel.

So I'm also working on the ability for objects to push one another. I have a simple box that I want to be pushable, but also solid so that objects can stand on it, and also I want it to be carried by other objects as well... but so far that is presenting a lot of challenges for how I've already coded things. For example I have no idea when I should be registering collisions on the side of a moving object now that objects can be pushed.

My assumption was that when I went to move one pixel to the side I could simply check for a pushable object and push that object to the side... however with the current way I check for surrounding collisions the results are not quite what I want. If an object can both collide with, and push the same object, the push only happens for one or two pixels and then the pushing object believes it's in front of a wall so it no longer moves.

As you can see I've already rambled for a number of paragraphs and I feel I haven't even scratched the surface of what's going on! I've been looking at my old Game Maker games platforming code to see if I can learn anything from my past self, but unfortunately the code leaves a lot to be desired. In Verge I did have boxes working that could be pushed, carried, and stood on, but I didn't cover a lot of corner cases and designed levels around not having huge bugs appear. I'm totally sick of designing levels around bugs though and I want to do this right! Unfortunately that means I'm driving myself insane as I try to handle all the possibilities I can imagine with this platforming engine.

I'm not feeling super great and I feel like everything sucks right now, but I guess I'll keep working on stuff and hope I can figure out small bits of it at a time.