From C++ to Python


This post is more theoretic than usual and I will analyze briefly my experience on passing from C++ to Python and what I found interesting to notice when learning another programming language is needed.



After working with C++ for a while, I had to learn Python for the first time and use it with Panda3D engine. Right from the beginning I’ve found myself thinking in C++ style a lot of times while programming in Python, especially for the first couple of weeks. Finally I realized that the first programming language you master (or maybe your favorite one), can affect the way you program and think in other programming languages. Probably this thing is also true for the spoken languages.

When you learn your first programming language, you are learning also all the best practices and the techniques of the language itself. This type of notions aren’t merely syntactical and they belong to “programming theory” or “IT theory” rather than a specific language. But when you starting to master this language you create common mind paths for creating instructions and more complex modules that belong only to the specific language you’ve mastered. Obviously these are my opinions, I’m not an expert in psychology.


Programming mind path

To help passing from the C++ “mind path” to the Python ones to me has been pretty easy after all, but I recalled some struggling at the beginning. Now let’s analyze the two languages to try to facilitate the journey.

First of all, let’s talk about some actual differences from Python and C++:

  • Python is run through an interpreter and is interpreted each time it runs., whilst C++ is pre-compiled
  • In Python, there is no need to declare types explicitly
  • Python uses Garbage Collection whereas C++ does not.
  • C++ supports pointers and low-level memory management.
  • C++ is a statically typed language, while Python is a dynamically typed language.


As you can see in the previous short list Python and C++ are both object oriented languages but they are ruled by different philosophies. Beside these strict differences that are also some intrinsic principles and styles of coding that belong to the specific language and find place in the deepest part of a programmer’s mind, the mind paths. This more “abstract” side of the differences of usage is difficult to manage at the beginning and I think it takes some time to deal with it.


Things to remember

Fortunately the syntactic side of the differences is less deep-rooted and can be managed more easily: there are only some little things that can make you struggle, especially at beginning of the switch. I’ve listed a series of things I found useful to “easily” switch from C++ to Python.

  • Indentation and curly brackets: in Python there are no curly brackets to define a block of code but instead of this it use indentation
  • Loops with float: in Python you can’t easily define a loop with a float increment
  • Data structure declaration: Python has built-in lists and dictionaries and you can declare it simply with “[]” for lists and “{}” for dictionaries
  • There’s no separate char in Python
  • No switch: Python doesn’t have switch statement and you have to implement it with if, elif blocks
  • While-Else: the loops have the else statement which allows to do something when you go out of the switch
  • Use less lines: Python allows you do simple things in less lines than C++. For example: a = 5 if b == 4 else 6
  • Python allows to write if statement in a single line inside an assignment. It’s not mandatory to use this feature but since you have the chance, why shouldn’t you?
  • Function pointers: in Python there are no control on pointers in general, but since the assignment works on reference, you can do similar things. When you have to use something that works like a function pointer, all you have to do is to declare a variable and assign to a function name (without the brackets) and that’s it. Since everything is a class in Python (even functions) and everything is “callable” when you have to call the function pointer, all you have to do is to call the variable.



  • A Byte of Python – Swaroop


I define myself as a creative developer.

Steady Drop – Log #6 – 2D Art


This post on Steady Drop development is about the art process and choices I’ve made.

Minimal style

During the pre-production phase I wrote down all the possible styles I could develop for Steady Drop, and like I said in one of the first posts, I was thinking to give to my game a cartoonish-like style, similar to Cut The Rope, just to mention a famous example. I finally chose a minimal style in order to emphasize the gameplay and reduce the distractions and also because it is easy to maintain.

Since the style I wanted was really simple and minimalistic, I started to create the assets on my own. I’m not an artist, but this type of style is something I’m able to work with. I wanted the main focus to be game logic and gameplay so I eliminated the unneeded and went back to the roots: the shapes and the colors. I think that sometimes all we need to recognize an object is its shape and its color, so every element in Steady Drop has its particular (geometric) shape and its inner color. I regret a bit this choice but it makes possible to speed up the assets production and allows me to concentrate more on the development.


The need of using a vectorial format

Having a minimalistic and geometric style for all the graphic assets led me to think using a vectorial format. The pros of using a vectorial instead of a lossy format are quite important on both technical and design side:

  • Smaller file size.
  • Changing resolution without loosing details.
  • The sharpness of the shapes are always very neat.


Obviously this pros are applied for my project, you don’t always need a vectorial format. I grabbed my favourite vectorial editor and I created some ideas of objects and actors of the game. And after some concepts and a lot of inspiration sessions, I came up with the (almost) final version (posted here). The problem at this stage was: I could possibly take advantage of a vectorial format in Unity?


Using the SVG importer

To solve this issue, I tried to find a way to use natively a vectorial format in Unity but unfortunately Unity (version 5.4) does not support vectorial formats, at least I haven’t found a native support. So, I started looking on the assets store and I found this (SVG Importer). Basically this tool imports a SVG file and convert it in meshes (I think one for any visible closed path), keeping the quality of the shapes at any resolution, I thinks even retina displays. The integration was very easy with no code required and the results are very good and I’m happy with it. I’ve only one little issue on replacing a svg texture at runtime but I solved it with a little workaround.


The next post will be on putting everything together and on code management. Stay tuned 🙂

I define myself as a creative developer.

Steady Drop – Log #5 – Game Input


Gyroscope handling

I want to talk a little bit about the first things I developed when I got the idea for Steady Drop. Just from the beginning I had this idea to use the gyroscope data from a mobile device and to do something with it. I started developing a first prototype which uses the gyroscope quaternion given by the “attitude” property and elaborating it to get the gravity direction using euler angles. The class doing all this stuff was (and is) called GyroTilt and for some time the name of the game/project was GyroTilt until I came up with Steady Drop. For a prototype it worked fine, and I started developing the game on top of this logic. At the time I wasn’t testing everything so often on a real device and for a reason or another I finished up screwing part of the logic and all the rotations were broken.

Recently I’ve changed the method to compute the gravity direction by simply getting the gravity directly from the the gyroscope class. This property returns a vector (with magnitude one) with the direction of the gravity in world space. I can take this vector and go on and use it with the rest of the logic which wants only the gravity direction and ignores how it is computed. Unexpectedly this gravity vector is much more stable that the attitude and I think it is not more CPU expensive that the other.

One issue I will have to resolve will probably be the device compatibility, since I’m developing this game for Android, there are hundreds of different devices with different mounted sensors. I haven’t tested my game on different devices yet, so I’m thinking to give the game build to some friends and people who can test it out, a sort of “closed alpha”.


Gravity direction, now what?

Ok, now that I have the gravity direction I use it for adding the increasing force (like I said in devlog #4) with its logic ruled by user inputs, and for rotating the object. To rotate the object correctly, I tried in the first place to use the RigidBody rotation caused by the force I add, which is nice but I could not find the right level of responsiveness I want. So I decided to freeze the rotation on the RigidBody component and to apply the rotation manually to the Transform. In this way the rotations are very responsive and the fact that I’m not using the rotation from the RigidBody is not a problem, since the physic system is all custom and ruled from my scripts.


Future uses

Since now the gravity direction seems stable I’m thinking to use the gravity for different purposes that can add gameplay variationsRight now the only object that react to gravity is the avatar of the player, what about some special enemy that reacts to gravity? I’m not sure to use the pendulum that I have right now, but I’m thinking a new type of walls maybe, that reacts to gravity. Maybe the gravity can affect some physics parameters of an object or an obstacle. I will decide what to do about this matter in the future, surely after the beta release.
Stay tuned for future posts 🙂

I define myself as a creative developer.

Steady Drop – Log #4 – Game Logic


Like I said in the last post, this one is about game logic.

I think games can be a pretty good simulation of the real world, and so far they do a really good job in this, even if most of the times there are only approximation of physics rules. Again, they CAN be a simulation but they do not HAVE to. So, in my case, I choose not to follow the stricts physics rules of gravity but I defined my own one.


Gravity logic

What I have at this point is only the gravity direction ruled by the device orientation. The amount of gravity force is determined by a simple algorithm: starting from a base multiplier, I add a certain value to this multiplier every N crossed unit and then I multiply the gravity vector for this multiplier.  In this way the speed increases in a sort of exponential way.

When the player stops the gravity, current force and speed are saved and they are applied once the player release the stop.


Point Logic

Let’s start with explaining the basic idea. I wanted a scoring system based on the distance that increases the points every N crossed game unit. The amount of increase depends on different factors. It depends on the gravity multiplier explained above and on a point multiplier that is progressively lerped to zero when the player stops the gravity and lerped to a maximum value when the player doesn’t stop the gravity. In this way a long stop equals to a smaller point increase, especially for high gravity multipliers. If you stop at the beginning there’s no big deal because the gravity multiplier is still low.

To do a recap:

  • Increase points every N crossed game unit .
  • The increase depends on the gravity multiplier and the elapsed time .
  • The gravity causes speed, which implies that the points are added more often.


Obviously, user-side the only things to be told are to keep falling as smoothly as possible and try to avoid to stopping too often. It seems a complex system but it’s not and it adds a certain level of unpredictability for the player.

The health is the maximum gravity stop time

The game world:

  • leaves room to the player to do basically whatever he wants
  • it’s “analogic”: the actions are not sampled or fixed


I need a system to connect all the aspects (gravity, health, score) together. I started to think about something that can affect the gravity, the points and the gameplay as well, and I think to bring in the time, too. We can stop the gravity with all the effects on point multiplier discussed earlier. But for how long we can stop it? Well…for a time related to the remaining health of the player! When stopping the gravity, a bar shows the player that the time is decreasing. When the available time is zero the time it starts to load but the player can stop the gravity again only when the time reaches the maximum value (the remaining health). I came up with this idea pretty far in the development but it is something that connects everything and I developed it.

This kind of relationship between stop time and health holds up everything giving importance to every aspects of the gameplay.

For visualization I choose two overlaid bars. When the time is increasing or decreasing the player sees the above bar that scales down or up revealing the bottom bar that represents health. In the image you can see the bar that represents health (green) and the stop time bar (lime-yellow) when the time is decreasing.

Schermata 2016-07-10 alle 14.03.30


This covers pretty much everything on game logics and since this time was a lot talking, I decided to give something visual as well. These are the current versions of the game actors. I think they will be the final ones, more or less. You can see the color palette I decided to use too.




I define myself as a creative developer.

Steady Drop – Log #3 – Level design


It’s been a while since the last devlog. I had some other projects to follow and a lot of stuff to do, but here I am. Let’s jump right into the subject: this post is about level design and my approach to level design in Steady Drop.


Level procedural creation

In this I started to think about full procedural generation where I put the rules into the algorithm and the level are generated with no manual level design at all. Sure, great approach, but I’ve found is not really suitable for what I wanted to do. Since the only level I have is potentially infinite I though more like a sequential loading.

Eventually I came out with a type of sequential loading where the level is loaded from basic parts that I call “slot”. The slots are loaded when needed progressively as long as the character falls down and are deleted/disabled when are offscreen because they are not usable anymore. The main operations of loading and deleting is shown in this code snippets below.

public void spawnNext(float fallObjYOffset){
    if (fallObjYOffset > m_CurrentYOffset - 10) //if I'm almost there
        //pick the right pool
        List<Env> currDiffEnvs = m_OrderedEnvs[m_CurrDiff.ToString()];
        //pick a random slot of the pool
        int eIndex;
            eIndex = Random.Range(0, currDiffEnvs.Count);
        } while(eIndex == m_LastIndex && currDiffEnvs.Count > 1);
        m_LastIndex = eIndex;
        //load the slot
        GameObject env = GameObject.Instantiate(currDiffEnvs[eIndex].gameObject,
                                                new Vector3(0f, -m_CurrentYOffset, -3f),
                                                Quaternion.identity) as GameObject;
        m_CurrentYOffset += envs[eIndex].offset;
    if(m_Spawns == m_DiffSpawnSlot)
        m_Spawns = 0;

Basically, the slots are divided by difficulty in different pools and since the difficulty is progressively increased as the player goes down, a random slot are picked from a pool of the current difficultyIn this way each slot has to be independent from others and still give a sense of flow and continuity when put in a slot chain, so I had to find a easy method to create a set of separate slots that convey flow.


Level design

In the last couple of months I started to read about different techniques of level design along with image composition, functional level design, “level design has to serve the gameplay” and others best practices and tips on the matter.

Finally, I found that this approach on Gamasutra could be very suitable for what I was trying to achieve, and you will find references of it in the following explanation of my level design pipeline.

Basically what I’ve done are very simple few steps.

  1. Defining the component palette: all the enemies, obstacles and even the player.
  2. Divide a blank sheet on three and drawing a curved path on each part. This is my ideal falling path, my flow.
  3. Mark the points of the path that are on the center and draw a horizontal line. In this way the horizontal line delineate a slot.
  4. Populate every slot with components of my palette in a way that makes sense along with the curved line of the flow

In the slide-show you can find an example of what I’ve done.



I chose to divide the vertical column when the flow pass through the center because in this way every slot has its flow starting and ending in the same area and they can be put in random order and still maintain a pretty consistent flowIn this way during the game, each slot can be randomly loaded as needed from a set of independent slots (like shown above).



I hope you liked this post :-). The next post I will explain the point system and the overall logic, stay tuned for more devlogs and other articles.


I define myself as a creative developer.

Blur effect shader


I’d like to share this post-process shader that I wrote to apply a simple blur effect on a video source on Panda3D engine. The related manager class (written in Python) adds more control and customizability to the shaders, but if you want, you could use just the plain GLSL shaders. Follow the link down below and happy blurring! 🙂

Source code


I define myself as a creative developer.

Texture2D Extension


Recently I had to work on Unity with Texture2D taken from a camera and for some reasons they came out flipped in strange ways. So, I had the need to rotate or flip the textures and I realized that Unity doesn’t have this function ready to use.

This is Texture2DExtensions (source code). As the name suggest is a little tool made for resizing, cropping, mirroring and flipping Unity’s Texture2D. It uses basics algorithms to iterate through the textures and set the right pixels.

You can use it right away into your projects to manipulate any Texture2D you want 🙂 Keep in mind though that It’s a little heavy computationally speaking so, don’t use it to manipulate in the update cycle.

Source code


I define myself as a creative developer.

Steady Drop – Log #2 – Graphics Style


In the last post (here) I forgot to mention that the inputs of the game are both the gyroscope and the touch screen: by holding the finger on the screen you can stop the gravity force.
I have to make a short document with a more detailed description of the game. I will post it soon.

In the last few weeks I converted all the logic of the game to be strictly 2D. Before I had some legacy of a 3D prototype that I made for the initial tests. I had to convert Rigidbodies, Colliders and stuff to the 2D version of the components. No big deal.

Beside that, I created a state machine that goes through the game states (like pause, loose, play, etc…) with a menu system that can load a menu based on the state of the game. I have to refine the transitions a bit and it’s perfect 🙂

Component pallette

I’m also working on creating my pallette of components that will compose the levels on two different layers: design aspects on one hand and graphics style on the other.

Desing & technical
Currently I have:

  • the player: the object that is falling down (triangle).
  • a wall: an obstacle that cause immediate death to the player if the player touch it (square).
  • a gravity magnet: it can pull towards or push away the character while is falling (circle).

Every object can move around or not, for example we can have movable walls. I’m planning to have a discontinuous laser and a pendulum object.

Graphics style
Here some examples of the concepts so far

steady drop actors

Once I have a concept and behaviour that I like for every component I will start to create some levels for testing the overall result. [SPOILER] The next post will be on level design 😛

I define myself as a creative developer.

Custom Event System for Unity

The Unity built-in event system is good for simple stuff and basic message sending. But when it comes to sending complex data or deactivate listeners it doesn’t fit well for that.

If you want a more customizable system you could use my event system:


I developed it (in C#) starting from the following class, than I extended it to satisfy my needs:


This event system allows you to define a specific event class (with all the benefits of encapsulated data), to add and remove listeners from a specific event and to define a callback for that event.

It’s safer than the Unity standard system, since it uses a delegate (like a function pointer) to specify callbacks, instead of strings (typo unsafe). It also uses the class name to differentiate events, and a listener has to use the type of the event to which it wants to react.

Use it freely on your projects. Happy coding!

Source code

I define myself as a creative developer.

Steady Drop – Log #1 – Starting off

This is the first post of Steady Drop dev log. I’m going to start this dev log maybe a little too late (my bad), but I’m going to do a recap. First of all, what is Steady Drop? Steady Drop is a 2D game about controlling the gravity by tilting your mobile device while, your character is falling down.

Starting development

The development started in summer 2015 when I had the idea that the input on a mobile phone can be given in several different ways other than the classic input methods (swipe and tap). At the time I choose the gyroscope to be the main input that served the gameplay and I imagined  a game that could satisfy this paradigm. So I grabbed my sketchbook and after some sketching session and I came up with a falling game. (Only recently I realize that Ridicolous Fishing has similar inputs, but the gameplay is pretty different). Then I passed into Unity 5 and started the development.I had the vision of the game pretty fixed in my head, so the first couple of weeks I worked on to get the input controls right. The gyroscope attribute is very easily achievable in Unity without requiring any native plugin for the devices, so I used that to create a first prototype and I was pretty happy about it.Then I thought about structure of the game, level organization, menus and so on. I came up with something similar to Cut the rope 2 or Two Dots in term of level selection but with down scrolling (since is a falling game). I started to develop the architecture for the game actors and all the managers and the level handling. At the time I was thinking of a playful graphic style and some themes for level groups (like space, sky with clouds, ground and underground. I was planning to release the themes on regular time spans. I also studied  the character design and a little bit of the game plot placed in a believable world and environment.

Change of direction

To make it short, I was planning to add a lot of things (maybe more) and after a period of time where the things was stalling, I decided to cut the fat of the project and resize it a bit. Instead of having multiple levels I choose  one infinite level. Also because a continuous fall divided into levels maybe was not a great design idea. I also redesigned the graphic style choosing a more minimalistic style with flat 2D shapes and no themes at all. So I had to go through some refactoring sessions to change direction and to get to the point where I am now. I regret a little bit this change of direction but without it the project would fail.

Current state

I’m currently working on the visual style and on the tools to make the things looking good on different screen resolution. I’m thinking of using svg format for images and I found this plugin on the assets store, I will try it out soon. I’m also planning to integrate an analytics framework and a life system based on how many add you watch (like Threes game), we’ll see. Since is a side project, I’m working on it in the spare time, so be gentle with me if it’s taking me a lot of time to finish. I will post other previous and present development stuff in future posts. Stay tuned!

I define myself as a creative developer.