sábado, 18 de mayo de 2013

Particles and item drops.... Ooh also Scripting!

This week on the Wildlands' Sidescroller subproject, i implemented the features on the title of this post.

Particles

Although Libgdx includes a particle editor and a particle engine, there's a major bugging problem with their particle system: No 3rd axis.
That means that my particles won't have parallax scrolling and that the code won't be capable of being ported to my main project.
So i went and coded my own particle system. The system had some requirements, namely:
  • Possibility to change the generator shape.
  • Possibility to change the particle shape.
  • Simple file format, capable of being edited with a notepad.
  • Fast and memory efficient.
So basically what i implemented was a 4 class system, that loaded the information from a JSON file the classes are responsible of each requirement:
  • Factory: Responsible of loading the particle system file, and generating the aforementioned systems.
  • Generator: Abstract class responsible of generating the particles, must accomodate to different needs when a different shape is required.
  • Particle: Responsible of maintaining the information of shape and properties of a generic particle, which don't change over time.
  • System: Responsible of maintaining a memory pool of the particles and handling them. Also, this class handles the rendering of the particle system.
As you can see, i mixed the rendering of the particle system with the logic handling it, that's an intentional mix up because i'm letting each class handle the responsability of not only storing their data, but also of representing it. This could be enhanced by adding representation classes for each class, but i'm not coding that way because this project is meant to test a lot of productivity and fun ideas.


Item drops

No good Action-RPG works without item drops and mine is no exception. The item drops must be simple enough for the level designer and flexible enough to the programmer to adjust to the player level. This lead me to asign the drop probability to a simple float value between 0 and 1. Also, it is planned to add more than 1 item drop from each container, but that's a to-do. In the game side, the drop is handled as almost any other dynamic object, having a mesh rendered with an attached physics body. Simple stuff.
BUT... the item pick up must be handled correctly, that's where Box2D enters in action, they have this nice class named ContactListener which lets you know when a body touches another, basically you must check that your contacts are valid and take action accordingly.



But the drops must be handled somehow, with some flexibility to add different item drops in the future, that's where comes the...

Scripting

For the scripting part i was entertaining the idea of using Javascript with the Rhino engine, but that would bloat my game. I also tried to use Lua, but almost everything i found needed native libraries (a no-no, i'm trying to maximize portability). So i went with a nice little scripting engine i found some time ago called FScript (from Fast Script).

The pros and cons of using FScript are:

Pros

  • Fast.
  • Small.
  • Efficient.
  • Simple.
  • Easy to embed.
  • Easy to create an API for.
  • LGPL License.

Cons

  • Almost non-existant support library
  • Everything must be made from scratch
  • No code editor with syntax highlighting.
  • Extremely strongly typed. (Not necessarily a con).
  • No debugging.
  • Project seems dead.
  • LGPL License. :-)
So, using it has some very serious problems and risks but, as you can guess, i used it anyways, because it is small and portable. However, i'm going to change it because of the license (i want to be able to embed everything in my code to minimize downloads and be able to use GWT with Libgdx as backend).

I'm probably embedding another language in the coming week. What engine do you think would meet my requirements?

No hay comentarios:

Publicar un comentario en la entrada