pongodot day 2: i am ball

Today’s goal was to add in a ball and get it to start moving. Pretty simple, and wanted to get a basic understanding of the scripting system in Godot.

Once again, using gimp I made a ball, keeping it simple it’s just a white 64×64 pixel square. Importing that into Godot and slapping it into the tree was quick enough.

Truly the most riveting of games

But just dragging things and assembling them on a screen was yesterday’s task, so today let’s get it to move.

Godot does support C#, which is the language that I am most familiar with, having used it most in both my professional career as well as in past game projects. However, the goal of this project is to learn, so instead, let’s instead use the built-in scripting language, GDScript.

GDScript also makes sense to use since it is better integrated into Godot, designed to work natively. It’s syntax is very reminiscent of Python, which I have used in the past, and there is a lot about Python that I like, just haven’t had as much opportunity to use it in years.

Quick right click on the ball in the scene, click Add Script and we are off to the races.

The little scroll icon means I clicked the right thing.

More complex scripting will come later, but for now we are in extremely basic mode. For tonight’s brief session, the goal is to just get the ball to move diagonally on the screen. Everything else can wait for tomorrow.

See if you can spot the error.

Take one had a small issue. I made my ball out of a sprite, and it turns out this was probably not the best approach. As a sprite I don’t have access to move_and_slide, so, I need to make a few adjustments.

More nodes.

This is another area where I need to adjust my thought process. In unity all these properties would just be part of the same object, but in Godot I need to nest them in the tree structure. Again, under the hood it doesn’t work all that differently, it’s just a matter of shifting my perspective of how things are laid out.

With that I just needed to change the script I wrote so it extends KinematicBody2D instead of Sprite, and boom! I could now use move_and_slide to move the little cube across the screen.

I tried using code blocks in WordPress, but they don’t capture the highlighting the right way for GDScript.

A lot can be done to clean this up, but for now I hit play and presto! It works! Rarely do things just work smoothly on the second try, so I’m feeling pretty good about this.

woo!

Of course, it doesn’t obey the walls, but that is to be expected (as I didn’t code anything to make it obey the walls). That’s tomorrow’s problem. For now, I’m going to finish sipping on this improved whiskey cocktail and relish in another step closer.

Sipping on this while I coded was probably not helping, tbh.

-Ike

Leave a Reply

Your email address will not be published.