Some refactoring

This is an intermediate step between Step 1 and Step 3, I decided to separate them to avoid Step 3 post  becoming monstrously long, and because the refactoring I made here has nothing to do with Physics simulation.

I recommend you to download the code from github before continue reading.
I’ve inserted some links across the post. Some of these links will guide you to external resources. Other links lead to my code.
I will differentiate my links with this color. 
It is important that you keep this in mind because it may be difficult to figure out what am I trying to do without reading the related code.


In this post, I’ll explain:

  1. BattlefieldStage class.

1. BattlefieldStage

1.1 General purpose

Extract the stage’s functionality from the Screen class.

1.2 Analyzing the problem

While I was adding new functionalities to the stage, I realized that GameScreen was growing very fast and dealing with lots of unconnected responsibilities, most of them lying with the Stage.

What I basically did was to take the Stage out of the Screen. As you can see here, the screen was holding the creation of the texture, position (and potentially other properties) of each Actor, and the assignment of the camera. Decoupling the Stage allows it to take full responsibility of these tasks.

1.3 Analyzing the code

This class extends Stage.

Just four little remarks:


The new attribute “word” will be the stage’s model. And before being murdered by experienced architects, let me say that I know MVC, but I won’t implement it yet because I don’t want my classes to breed like rabbits until I feel a little more comfortable with the game development. Please forgive me.

Grouping similar Actors

Then I’ve created a Kittens array to grant ease access to each group of Actors. The Stage has already an array of all its actors, but it is not efficient to use it because you may not need to evaluate each actor of the Stage to know if they are the kind of Actor that you were looking for. It’s faster to just read the Kitten array if you want to do something on Kittens.


The RayHandler is a nice new feature that will manage light projection from objects. As you drag the kittens, you will notice that they project lights that collide with opaque objects.

Growing grass

The Ground type object “battlefield”, is the tile that will be repeated in order to simulate the ground on which kittens will walk. I won’t explain it further because what I really want is that you focus on Step 3 reading, but please feel free to explore it.

That’s all for now. I’ll explain the new functionalities (like World) over Step 3.



Leave a Reply

Your email address will not be published. Required fields are marked *

Proudly powered by WordPress | Theme: Baskerville 2 by Anders Noren.

Up ↑