Brick Destroyer (an ECS example)

Started by
-1 comments, last by Momchil 8 years, 11 months ago

Hi everyone!

For a long time I have wanted to try out the Entity Component System design pattern. There are multiple variants of ECS out there, but the one I have stuck with is where Entities hold only ID information and a set of Components; each Component is just a pure data structure, which has no methods; and Systems are the ones responsible for modifying Components and moving the world around.

That said, I've just never had the free time and the proper test project to try it out... until recently, when I decided to port a very old Java game of mine to JavaScript and it was the perfect candidate.

brick_destroyer.png

You can try the actual game here: http://momchil-atanasov.com/brick-destroyer/

You can check the source code here: https://github.com/momchil-atanasov/brick-destroyer

I've gone as far as to have all the entities and component assembly described inside the level itself. (which is a pure JSON file) This means (to the most part) that the logic and the behaviour of the game is designed and specified in the level file and not hardcoded in the game.

You can have a look at an example level file here: https://github.com/momchil-atanasov/brick-destroyer/blob/master/resources/levels/level_ecs.json

Furthermore, you can import your own external level. Here is an example (note this one is quite broken, I haven't had the time to write a better one): http://momchil-atanasov.com/brick-destroyer#https://gist.githubusercontent.com/momchil-atanasov/3096ae2781e739331f2b/raw/7ce011e800463d4ee6c7b79f6549c26b62fd7eff/gistfile1.js

(you might need to do a page refresh once or twice)

Since this was my first attempt at ECS, I cannot say it is the most polished one. In fact I opted for clean and simple to read code instead of going for performance. My main goal was to see how flexible the system can be and whether new behaviours can really be designed just by mixing components (as most articles would have you believe).

Well, it turned out that ECS can be quite good in the context of game development indeed and new game concepts can in fact emerge through the mixture of components. My main goal with this project is to increase the popularity of ECS and provide a simple example. Hope you like and approve!

Regards,

Momchil Atanasov

This topic is closed to new replies.

Advertisement