Dev Log Entry 3: Learn by doing and a primordial “Newtius”

This about both learning GameMaker Studio 2 and some basic of game making.

As I mentioned in dev log entry 2, I decided I learn a lot better by doing then I do by hypotheticals from reading things or transcribing someone else’s code.

So I decided at some point to just start making a new game using what I’ve learned from the four tutorials I’ve completed thus far. As a GML project.

Not sure the title is interesting enough to explain (feel free to skip).
I was going to make my version of Gradius for the NES. An alternative title (or sequel, whatever) to Gradius is called Salamander. And a sub-species of the Salamander is the Newt. So I thought I would combine "Newt" with "Gradius" to make Newtius. It's a working title.

If this sounds familiar it’s because it was my original idea in my introductory post of the “find a game making solution” series of posts.


I started out in the most obvious places for space shooter: create a ship sprite and a ship object then assign the sprite to the object.

With that heavy lifting out of the way, I drag-and-dropped the object into the default game room in GMS2 so it would actually be visible. I then compiled my “game” to stare at a static image of the ship I had made in the pixel editor.

The first build of Newtius (try not to hyperventilate from the excitement).

Actually I spent quite a long time on that ship sprite. Feel free to feel impressed on the level of detail.

The next most obvious step was to work on allowing the sprite to move in at least four different directions. And setting the window size to 640×480. But after that, definitely the four directions.

I actually ended up with a few different options for this from the different samples. The Udemy course I completed actually had the most straight forward method – assigning the test for different keys to an array – but I decided to use something else that would be easier to read and understand if I were to come back later. By which I mean created events labeled “KeyPressed: Up” for instance.

First I went into my ship object and added a Create event. In here I set a variable called spd to 7: spd = 7. I won’t bother putting that in a code formatted paragraph as it seems rather on the nose. The reason for this variable will become apparent in a moment.

Arrow keys?

For the left/right/up/down I decided to use the four arrow keys.

This is the code that worked for moving the left. The lines that start with // are a comment, which the code compiler ignores.

// move ship left
if ( x < room_width - sprite_xoffset - spd) {
	x -= spd; // move to right is just x += spd;
}

As it turns out, for moving the ship to the right I only have to change the one line to read x+=spd. That’s it.

Similarly, for the vertical movement:

// move ship upwards
if ( y < room_height - sprite_yoffset - spd) {
	y -= spd; // to move downwards: y += spd;
}

The room_height and sprite_yoffset and x/y actually are simply variables provided by GMS2 by default. I don’t need to retrieve that information or anything, it’s simply there.

And I say variables on purpose as these values can be changed in code (as opposed to constants that cannot be changed).

All this code really does is check the information of the object the code is associated with then allow a check against it or for you to change it. For instance is the ship at a position less than the top of the room (room height), taking into account the size of the sprite itself (sprite offset).

Upon testing this code for the four directions I found it worked as expected. Except the ship kept getting stuck on at least one edge. If you I move all the way to the bottom I can’t move it up again but I can move it left/right. Unless I touch the lower right corner at which point I can’t move it any direction. Upon further testing I’ve noticed touching the right edge makes it stuck to that location but I can move it up/down. All the way up or all the way left allows the ship to go off the screen without consequence and doesn’t stick. So really the issue is the right edge and bottom edge of the window.

But other than that the game is working great. I know I have examples of properly handling the window edges and I’m sure I can figure it out. I should mention a obj_game object I created and imported a bunch of code from other projects. Logically I should delete all the code in that object to see if that fixes this bug. I don’t think it will since I didn’t put it in the game room. But it might. Or I could just comment all the code out. That also could work.

Projectiles are exciting

Before I had noticed the edge sticking bug I had already gone on to making the ship fire a projectile.

Similar to the ship sprite and object, I created a bullet sprite (2×2 pixel white box) and a matching bullet object, then associated the object with the sprite.

Then in the Ship object I create a KeyPress Space event and put in some code almost entirely unmodified from the space rocks YouTube tutorial:

// space ship object's "key press space" event
// create new instance of bullet object on the "Instances" layer at 
// coordinate 0,0 which is the x and y cords of the 
// ship object at that particular moment...

var newBullet = instance_create_layer(x + 0, y + 0, "Instances", obj_bullet);

// direction is included in the GML language. 
newBullet.direction = image_angle;

From here we jump over to the bullet object.

In the Create event of bullet object, I set the values of these two included variables, in the GML language. GMS2 just knows what speed is. Same with direction. No need to explain.

direction = 0;
speed = 6;

Then there’s a also an Outside Room event which consists of one line:

instance_destroy();

Can probably guess this removes the bullet in question from memory/the game since it’s not in the room any more and not visible.

So, with all this code I have a sprite of a ship that can move in four directions and fire a bullet left to right with the starting point of said ship sprite.

Bugs give it character

I might be taking the term “dev log” a little too literally. But it’s definitely a log of development, isn’t it?

For the record I don’t have a build on my GitHub repo right now, but so far as I know if you download the project (clone the repo) it can be opened and run with the free edition of GMS2. I also don’t have any idea how to embed the HTML 5 version of a build into a regular web page.


The latest version/progress of Newtius can always be found at my GitHub repo:
https://github.com/tildesarecool/newtius

One thought on “Dev Log Entry 3: Learn by doing and a primordial “Newtius”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s