Saturday, 7 April 2012

A basic platformer

I have started to work on the 2d platformer game I mentioned in the previous article. As the first step I am developing the engine. It is in C++, using Box2D for physics, SFML for window handling, input and audio, OpenGL for rendering (currently just old style OpenGL, later I plan to use shaders), and Lua for scripting. Box2D, OpenGL and the C++ glue code will do the heavy lifting, while the game logic and events will be scripted in Lua.

I use my own entity-component framework which is based on this article to organize the 'things' in the game. This is my first experiment with an EC system, so far it seems to work really well. It is quite different from object oriented design, it modified the way I think about structuring the code.

Building a basic platformer with Box2D is not really hard. I chose boxes as the physical representation of entities. It might not be too accurate, but I think it will be sufficient for the game I plan. But later I can extend it anyway. Platforms that do not move have a static Box2D body, other things that should be able to move and react to forces have a dynamic body.

As a platformer game, jumping has an important role in gameplay. The player should be able to jump, also enemies, but only when there is something they can jump from, that is, they are standing on something. My first approach to detect if an entity can jump was to check the forces effecting the body, and if the y component is greater than zero, then there is surely something pushing the body upwards and jumping should be allowed. I implemented this method, at first seemed to work, but then I noticed that when the player was standing on another dynamic body then sometimes it could not jump. After some examination it turned out that when two dynamic bodies are resting on each other then the value of y component varies inconsistently (at least as far as I can tell...), so this is not a good method.

My next idea was to attach sensors to the lower parts of the bodies, and use them to detect if there is something under the body. Sensors are like ghost bodies, they go through other bodies (they do not generate collisions), but they detect if they are touching something. I implemented this method too, and it works like a charm. So from now on every living thing in the game will have a thin 'foot sensor' to decide whether it can jump.

The 'living things' (the player, enemies...) have 0.0 friction to move easily, and fixed rotation because that's how they should behave in a platformer :) To move a body I just set it's velocity (e.g. v.y=30 to jump, v.x=20 to move right), and Box2D will take care of everything. Here is an image showing the simple sandbox environment I used for testing. It has 2 static platforms, 3 dynamic boxes and the player.


A picture is worth a thousand words, but since this is a game a video might be worth a thousand pictures, so here is a short one:


There is much work to do... implementing animation, particle systems, sound effects, camera... lot's of tangential stuff like menu system, starting a game, loading, saving... then programming the gameplay, creating content. So I will not be bored :)

Saturday, 3 March 2012

My experiments with 2d animation

Recently I was playing with the thought to start developing a new game, now that the previous one is finished. One of my ideas is a 2d sidescroller platformer game, similar to the 2d mode of Alice: Madness Returns, with some inspirations from Trine. After considering different options I decided that I would develop my own game engine (I like programming, so that would be the funniest part anyway:), that would use Box2D for physics, Lua for scripting and OpenGL with shaders for rendering.

While planning the game I was thinking much about animation. For The Silliness of the Lambs I have done some basic animations, but they are quite ugly, and creating them was a bit tedious. I realized that drawing animations frame by frame is not my slice of bread, so I was looking for other ways to do it. I wanted something like drawing parts of a character (like body, head, arms, legs), and then putting them together in different poses to form an animation.

Since skeletal animation is the most used method for 3d animations, as a first attempt I designed a 2d skeletal animation system. In this system every character would have:
  • a skeleton: a hierarchical set of bones, defining the main structure of the character
  • a 'skin': a set of images; each bone would have an image
  • poses: a pose would define the position of each bone related to their parents
  • animations: a sequence of poses and the interpolation times between them would form an animation
The advantages of this system would be naturally looking animations, and that the skeleton could be used for ragdoll effects. Existing tools could also be used for this, the animations could be created in a 3d editor, and an engine like Ogre could play them. But I don't have much experience with 3d editors, and I thought that Ogre would be overkill for a simple 2d game, so on paper I designed an animation program that I could use to edit skeletons, skins, poses and animations. After that I realized that I did not really want to implement a such complex program just to create animations, and that this whole system was too complicated.

So I started to think about a simpler method, and I realized that a skeleton is not really needed for an animation, so I designed a new system without a skeleton. In this system the basic structure is the 'animation'; different animations for a character are not related. An animation consists of a set of parts (images), several frames, and the interpolation times between the frames. A frame defines a transformation (translation, rotation and scale) for each image, and these transformations are interpolated between frames (by the way I have learned that interpolating angles is not just that simple...).

This new system does not have the advantages of the previous one, but it was much more appealing for me, so I implemented a simple editor for it. I used Java , because that's what I like to use to create programs with GUIs.

Adding the first part

The left area is for handling the parts. Parts can be added, deleted, named and put in order (the order is important when drawing the animation, it defines the drawing order). The upper panel is the palette. Parts can be selected from the list on the left, and the desired operation on them can be performed with the mouse.

Some more parts, named, ordered, moved and rotated

The area below the drawing canvas is for handling frames (adding, removing them, and setting the duration between them). The transformation operations on the parts always modify the current frame.

Adding and editing frames

The most exciting part of the GUI is the Play button, if it is clicked, a new window is opened which plays the animation. I have recorded a short video of the animation of the wizard that you can see in the pictures:


Yeah, it's quite simple, not really naturally looking, but much easier to create than drawing each frame manually, and easier to use than the skeletal version.

Hopefully one day you will see a game featuring animation created with this program :)

Sunday, 8 January 2012

The Silliness of the Lambs released!

I have finished The Silliness of the Lambs and released it for completely free. It is available for download from the Android Market:


It features 20 levels, sound effects, and all good things that accumulated during the 4-5 months of development. Do not hesitate to try it :) All feedback is welcome.

I used the following software to develop this game:
  • Eclipse IDE + Android SDK for coding
  • Inkscape, Gimp and IrfanView for graphics
  • Git for version control
  • SheepEditor (my own custom editor) for creating levels

Now I can finally start working on new projects :)

Friday, 2 December 2011

The Silliness of the Lambs - DEMO 2

I have added the missing features to The Silliness of the Lambs and I have improved some aspects of the game based on the feedback I received from different sources, so I am releasing a second (and hopefully last) demo. Thanks again for everyone who tried the previous demo and provided feedback :) I have digested the suggestions and chose the most important ones to be included in the game.

Download.

New features:
  • Sound effects
  • Improved UI graphics (might need seed some more improvement...)
  • Gameplay improvements (e.g. the sheep don't get stuck in the corners)
  • Some minor bugixes
Since the graphics hasn't changed much no screenshots this time.

Sunday, 20 November 2011

The Silliness of the Lambs - DEMO

I have finished the demo for the Android version of The Silliness of the Lambs. You are free to download it, all feedback is welcomed. It contains six levels, and it is fully (or hopefully) playable.

To install the APK file you have to copy it to your device (or download it right there, it's only half MB) and after enabling Unknown Sources it is ready for installation.

Download.

It features updated graphics and new levels. I have implemented a level selecting screen, font rendering, and lots of small things to make it a complete game.

After finishing it (making a pile of levels, fixing possible bugs, implementing sound playback and adding sounds and music) I plan to release it on the Android market. Hopefully I can do it soon :)

Title Screen

Sample level

It's cold in here

Another level

Thursday, 3 November 2011

The Silliness of the Lambs - Level Editor

In the web based version of the game the levels were tile-maps and some additional objects (dog, sheep, bush...). Every level's data was inlined in the Processing source, the tile-maps were stored as arrays and the objects were added to the level instances. I designed the levels on paper, then based on the drawings I created the maps in a text editor and calculated the positions for every object - it was quite tedious.

In the Android version I use an image for the background, and objects for everything else. I did not want to create the levels manually, so I quickly put together a simple level editor. I have finished it in one day and I think this time will come back soon when I'll start producing the levels for the game. Since I develop the game in Java I chose it as the language for implementing the editor. I recalled my memories of creating GUIs in Swing, designed it on paper and then manually coded it (I prefer creating simple user interfaces manually rather than using an editor). When most of the widgets were in place I implemented the event handlers and listeners, the editor was functioning. Creating new levels is now a piece of cake :)

Using it is quite simple. After clicking the "New" button you can choose the background image from a file open dialog, and it is displayed in the editor. The logical dimensions of the level can be set in the text-boxes on the left. The dog, sheep and bushes can be added to the level by selecting them from the "palette" and clicking on the image. Walls (and generally every blocking areas) can be added by selecting the "Wall" tool and drawing a rectangle. Setting the fold is similar. This follows the logic of the game, since objects that could move have a circle shape, and blocking objects are represented by axis aligned boxes. The level can be saved as an XML file by clicking the "Save" button (surprisingly).

Screenshots (as you can see it's not a WYSIWYG editor):

Initial window

After loading the background picture

Adding the dog (black circle)

Adding a few sheep (grey circles)

Some bushes... (green circles)

Setting the fold walls (red rectangles)


Setting the fold area (blue rectangle) 

In-game screenshot of the level

Thursday, 27 October 2011

Do Androids Dream of Electric Sheep?

Soon they will. I am porting (or rather rewriting) The Silliness of the Lambs to Android. The game doesn't need much processing power, the gameplay is quite casual, and it's control mechanics is ideal for touchscreen devices, so the idea to make a smartphone version came quite naturally. It is possible to play the original on a phone in the browser, but it's too slow, and I wanted to get into Android programming anyway.

So I went to http://developer.android.com, learned the basics of Android development, installed JDK + Eclipse + Android SDK, and started to discover the platform and tried to build up the basics for the game. I was surprised to find that developing for Android is as easy as stomping on kittens. My pessimist self expected that I would have to build the Java project, then manually convert it to an Android package, then somehow transfer it to my phone where I can finally run it. Instead of this I just have to click on the Run button, lean back in my chair, and all of the tasks is done automagically. If my phone is connected to the dev computer through USB then the program is run on it, otherwise the emulator is started and my program is run inside it. On a second thought this is what I really expect of a development environment.

After discovering the possibilities I decided to use OpenGL ES for rendering. I have made a simple program which created an OpenGL display and drew a flat shaded triangle, and then extended it step-by-step, added handling of touch events, controlling fps, implemented texture loading and drawing of textured rectangles. At this point I had a basic engine with the functions I needed, so I could start porting the game source. Since Processing is quite similar to Java it did not seem to be too hard, though it wasn't easy. Java needs lots of "decoration" (public final static abstract...), classes go to separate files, the libraries have different functions, etc.

During the porting/rewriting I could restructure the code, so it is organized better now. I have redesigned some aspects of the implementation of the game, e.g.  instead of a tiled background (which determined both the graphical appearance of the level and the physical representation) I use one big background image (graphical appearance) and the physical objects (e.g. walls) are now stored independently. This modification speeded up both rendering and collision detection. The levels are not inlined in the code anymore but loaded at runtime from xml resources.

So now I have a (gameplay-wise) mostly functional version for Android. This means that I am ready with the 90% of the project, now I just have to finish the remaining 90%. I have to implement font rendering, create a menu or level selecting screen, create levels and other contents, and I also plan to add sound effects and maybe music. After it's finished I would like to release it on Android market. I intend to release a demo soon so that you can try it if you are interested.

Some images as usual (please note that some parts of the graphics are just placeholders :)

In the emulator:


On my phone:





P.S. I have watched Blade Runner to have some right to use this title :) I will also read the book.