Why would you write so little code for video games?

Today I will share one of the journeys I have been on for the last month. I asked a question:

How do you make video games?

Oooh this is a tough one. In the past I shared with you how to make text video games using Twine, which was fun, but not the same level of enjoyment you get say playing Life is Strange. Driven by curiosity how to make video games, I worked with libgdx, a Java-based library to create cross-platform video games.

lifeisstrange

libgdx

libgdx uses a pretty neat idea of creating Actors and Stage to set up the scene. Each second the Actor’s act() method is called where the actor gets to do something, like walk across the stage, talk to another Actor or whack them in the head. Fun, right? I definitely had fun with the engine, but quickly realized that I won’t get very far with the games if I had to do so much object management including the score label updates and object collision.

I do not mean to claim that libgdx is bad, by no means – if I had to start learning about making video games all over again, I would start with libgdx first every time! It is very important to know how to perform collision detection calculations, aka when two objects run into each other.

collisionnocollision3

It would be a shame if I did not add some code showing how I did the collision detection in libgdx. Here is a small Java function I would call to check if a vampire was close enough to its victim to “interact” 🙂

   public static boolean closeToInteract(Actor actor1, Actor actor2){
        if (actor1 == null || actor2 == null) return false;
        float distance = ActorDistanceCalculator.getDistanceBetween(actor1, actor2);
        float actor1Width = actor1.getWidth();
        float actor2Width = actor2.getWidth();
        boolean actor1IsToTheLeft = actor1.getX() < actor2.getX();
        return actor1IsToTheLeft ? distance < actor1Width : distance < actor2Width ;
    }

This is a lot of management for a very simple game where a 2D vampire walks around a castle and sucks the blood of its victims when no one is looking. Despite all the fun I had learning about management of the game state and actor interactions in 2D world, I wanted to get back to 3D. Imagine writing a physics engine for 3D! Okay, it would be fun, involving some pretty complex and exciting geometry calculations, but this was not what my art monkey was after. (My art and math monkeys are always at odds – when one is really excited about a project, the other likes to take a nap).

in-only-lovers-left-alive-001

Unity

When I discovered Unity and over the course of two hours, from scratch created a video game where a rolling ball could collect a bunch of rotating objects, I knew I was into something awesome.

In Unity, the state, gravity and collision have all been created for you – all you need to do is add components to the objects you would like to manage. And all this with very minimum code! That means I could concentrate on creating a fun game instead of continuously struggling with physics.

Mab

Currently I am continuing my quest learning Unity, along with Blender and Source Filmmaker 3D. A CodeBrave multipotentialite, I am driven by never ending curiosity about how things work. Now go off and build a cool CodeBrave video game!

Advertisements
Why would you write so little code for video games?

No more magic self-sabotage

“I can’t do math”

“I am not artistic”

“I do not get computers”

“I cannot program”

How often do you hear different arrays of people say these things with a straight face, meaning every single word? Who taught them to say those things?

arielvoice

Continue reading “No more magic self-sabotage”

No more magic self-sabotage