Monday, 11 June 2012

Platformer - it's starting to look like a game

In the last two months I was busy with lots of other things, but this weekend I had time to work on my game. It was surprisingly easy to continue the development after the break, I think this signs that the code quality is not that bad. Due to the entity-component system the code-base is well separated into largely independent units (components/subsystems), so it's not hard to understand.

The new features:
  • smooth camera system, the camera can follow the movement of any entity
  • improved scripting, more and more can be done from scrips
  • graphics layers, by using perspective projection instead of orthographic
  • lots of small things under the hood which enhance the engine, but are not directly visible

I have examined the Unity and Unreal3 engines and development environments, on the first hand to see if I should use them instead of building my own engine, and on the other hand to see how real, commercial, successful engines work. I decided to continue with my own engine, and my goal is to have a single engine that can be used for different games simply by using different scripts.

The usual screenshot and video (please note that the graphics art is completely placeholder, I just drew the images in a few minutes; the game I am planning will have a completely different style):




The next step in my plan is to implement animation, then handling physical events, and meanwhile generally improve the engine. Then, when the engine is good enough, I will start building a real game with it.

BTW I have realized I love platformer games. I really enjoy jumping, shooting or solving problems in Trine 1 and 2, Limbo, Braid, American McGee's Alice and Alice: Madness Returns... I have even played Prince of Persia (the good old one, not the new version) in DOSBox. I think I will have to invest into buying Rayman: Origins too, it looks quite good. Actually I took the fancy to continue developing my game while playing Braid and Limbo... somehow I felt I shouldn't just play games, I should create them if I can.

Another thing I have realized is that how convenient it is to play games with a gamepad compared to controlling with the keyboard. It's much better leaning back in my chair or couch, resting my hands holding the controller in my laps, instead of leaning over the keyboard on my desk. So I will aim for supporting gamepads in my games.

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