Tutorial (Godot Engine v3 - GDScript) - Invader Graphics!

View this thread on: d.buzz | hive.blog | peakd.com | ecency.com
·@sp33dy·
0.000 HBD
Tutorial (Godot Engine v3 - GDScript) - Invader Graphics!
# ![Godot Engine Logo v3 (Competent).png](https://steemitimages.com/DQmenztXPYjpJLwd6Y1rTfWEUX9g5tsYMEhty5PzaKmaFcZ/Godot%20Engine%20Logo%20v3%20(Competent).png)   Tutorial

![](https://steemit-production-imageproxy-thumbnail.s3.amazonaws.com/DQmeRXYK5hTURHD9TqUuGi4vPsockATFzcKFZdawUYpq24B_1680x8400) ...learn how to place the Invader graphics in!

# What Will I Learn?
This tutorial builds on the last, which explained how to add [smooth movement](https://steemit.com/utopian-io/@sp33dy/tutorial-godot-engine-v3-gdscript-smooth-movement#comments) to the _Invaders_.

In this article, you will learn to place Images into the game. A very simple activity!

Once implemented, you'll find the _Invaders_ start to look real and that they are invading from space!

<center>
![twinkle twinkle.gif](https://res.cloudinary.com/hpiynhbhq/image/upload/v1519496211/dul8xmliqpkrkbutiidg.gif)
</center>
<center>Note: the recording method doesn't do justice to the smoothness of this</center>

### Assumptions
> * You have installed [Godot Engine v3.0](https://steemit.com/gamedev/@sp33dy/installing-godot-engine-v3-0-windows)
> * You've completed the previous tutorials
> * You should be familiar with [Scenes](http://docs.godotengine.org/en/3.0/getting_started/step_by_step/scene_tree.html?highlight=scene), [Nodes](http://docs.godotengine.org/en/3.0/getting_started/step_by_step/scenes_and_nodes.html?highlight=nodes), [creating instances](vhttp://docs.godotengine.org/en/3.0/getting_started/step_by_step/instancing.html?highlight=instances) and a basic grasp of [GDScript syntax and documentation](http://docs.godotengine.org/en/3.0/getting_started/scripting/gdscript/index.html?highlight=gdscript)

### You will

> * Apply a space background
> * Apply an image to the _Invader_ node
> * Apply glittering stars

# Requirements

You must have installed [Godot Engine v3.0](https://steemit.com/gamedev/@sp33dy/installing-godot-engine-v3-0-windows).

All the code from this tutorial will be provided in a [GitHub repository](https://github.com/sp33dy/Godot-v3-Tutorials-Beginner). I'll explain more about this, towards the end of the tutorial.

----

# Acquiring images; Copyright and Licenses!

For this tutorial, I need images. Preferably they'll be of a good standard and lend themselves to a 'Space Invaders' theme.

The law of copyright prohibits me taking and reusing one of the many images from the internet. I could even acquire the original Arcade images. 

> Why don't I? 

[Copyright](https://www.out-law.com/page-5633) prevents me from doing so. 

If I did, [Midway](https://www.quora.com/Intellectual-Property-Are-there-any-copyrights-on-Space-Invaders-monsters) (the copyright owners) would be entitled to issue a lawsuit against me... and I certainly don't want that!

Secondly, I want to create my own version of the game, to make it:

> * Unique
> * Modern
> * Take advantage of the graphics capabilities than were not around in the late 70's!

If I were creating a commercial game, I would try to find a Graphic Artist to collaborate with me; often either on a paid basis or on a profit-sharing basis. 

However, there is little chance that I'm going to find somebody to help me (although if you are reading this and think you can help, let me know!)

My last approach was to look amongst the MANY free game art websites that exist on the internet. 

My Personal favourites being:

> * [Open Game Art](https://opengameart.org/)
> * [Freebie section of Game Art 2D](https://www.gameart2d.com/freebies.html)
> * [The free section on itch.io](https://itch.io/game-assets/free)

There are many sites and community forums to find assets for your game. You just need to go look!

However, BE WARNED! Although many assets are free, some will have licenses attached. These can be as simple as 'do what you like with them' but others may require you to open all work as open source! This CAN be a tricky minefield to tread, but it should not put you off!

My advice is go look for assets, find what you need and then examine its license. The author will state the type of license applicable, therefore you can google its meaning; or alternatively, contact the author and check! There is nothing better than getting approval from the author and it is often nice for them that their work is appreciated and being used.

For example, for this series, I'm planning to use assets from these two brilliant artists:

> 1. [Skorpio](https://opengameart.org/users/skorpio)
> 2. [Carlos Alface](https://carlosalface.blogspot.co.uk/)

### Skorpio

I found Skorpio's [Spaceship kit](https://opengameart.org/content/space-ship-construction-kit) along with the space background assets. 

Looking at the available licenses (bottom left side):
![image.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1519492449/ytvtlnawkheku5fuhigy.png)
I selected the [Creative Commons by SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/) license. This allows:
> *  Share — copy and redistribute the material in any medium or format
> * Adapt — remix, transform, and build upon the material for any purpose, even commercially. 


It protects me because "The licensor cannot revoke these freedoms as long as you follow the license terms"; where the terms are:


> * Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
> * ShareAlike — If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original.
> * No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits.

Given the terms, I 'may' alter the star field into smaller elements, rather than one large sheet; therefore I'm allowed to do so. However, I must provide the same license to the changes. 

I had already planned to provide the tutorial code in a publicly available GitHub instance, under the [MIT license model](https://opensource.org/licenses/MIT) that Godot conforms to. Clearly, I will also include the images, but will ensure a 'readme' file exists that explains and places any derived work into the CC-SA-v3.0 license with attribution. IN this way, I make all work available under the correct license.

### Carlos Alface

I didn't stop my search for Spaceships and I soon stumbled over Carlos's material on his [blog page](https://carlosalface.blogspot.co.uk/) and in the same [Open Game Site](https://opengameart.org/content/126-2d-spaceships):
![image.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1519493211/txgzrcr3dylnxpcy6g2n.png)

As can be seen, Carlos provided his images with a CC-SA-v3.0 license too! Which makes my life much easier.

### Communication

Despite understanding the license, I contacted both to check for their permissions. They were both responded quickly to my intention of use. They were both supportive and I hope that this set of article brings them wider publicity; especially when the game is built.

ARMED with the images we need! Let's add them!

# Space is dark!

Our first step is to make sure our background in Godot Engine is pitch black. 

Open the Project Settings and select, General > Rendering > Environment and click the right hand colour in the item Default Clear Colour:

![image.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1519493505/t9yodvzptd7rnun02y34.png)

Select the bottom-left Black colour or set the values to zero.

When you close the window, you'll find the 2D background is now pitch black!

![image.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1519493562/skokbiy9ozeup6cua2rg.png)

That's a start, but let's add some stars too!

Please create a new Scene, called, _Stars_. Make sure you add a Sprite root node and name it _Stars_ . Finally, save the Scene into its own folder, called... yep you guessed it, _Stars_!

![image.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1519493693/uh1e55mmbufqx1fdxnth.png)

You will then need to obtain the [Stars-Nebulae.zip](https://opengameart.org/content/space-ship-construction-kit) from the Open Game Art site, provided kindly by Skorpio OR go to my GitHub to obtain it.

From the zip, you will need to copy the _stars.png_ to your project. I created an _images_ folder within the _Stars_ folder and placed the image here

> This is a deliberate decision because it allows me to reuse the starfield in another game, by simply copying the entire folder as a single asset! 

> The _images_ folder also allows me to place the _license.txt_ files required for the GitHub publish (see further down)

Simply attach the _stars.png_ to your Sprite's texture:

![image.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1519493946/csocon6ghwskrwzqra8y.png)

You should then save the Scene, switch back to the _Game_ Scene and then add a _Star_ Scene as an instance node:

![image.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1519494081/onyg7hdz402blcwzjur4.png)

As can be seen in the above screenshot, you will need to set the _Star_ node uncentered, otherwise it will only cover a quarter of the screen. Ignore the fact that the starfield goes across the bottom border, that's because the image does not match the screen height size!

If you now run the game, you'll have a nice Space background with stars in it, whilst the invaders fly across it!

# Change the _Invader_ images!

Let's do the same with the images of the _Invaders_. 

Please obtain the [Spaceship pack](https://opengameart.org/content/126-2d-spaceships) kindly provided by Carlos. You may select the _Invader_ of your choice; I preferred A11.png!

![image.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1519494473/jfus2wsgtf5fc5bwxe4m.png)

I created an _images_ folder in the _Invader_ folder (to ensure the image is local to it) and then assigned it in the Scene root Sprite.

Now try running it!

![image.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1519494566/ynkbmrnr3lwzfzlljgw1.png)

...oh, not what I was expecting! 

What I failed to consider was the size of the chosen image! Its dimension is 93 x 130 pixels, where as the Godot icon is only 64x64 pixels.

 Given this, I decided to change the _Invader_ Sprite scale, reducing it to half size with (0.5, 0.5):

![image.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1519495091/cniw9a0avadkcozs9dm7.png)

Our code in the previous tutorials included Scale as part of its calculation of the _Invader_ size! Therefore no matter what scale you set, the code will re-adjust proportionally.

When it is now run, the game starts to look pretty:
<center>
![pretty invaders.gif](https://res.cloudinary.com/hpiynhbhq/image/upload/v1519495646/orw5eeyemdfscsecckyh.gif)
</center>
<center>_Note: the recording reduces the quality here_</center>

# Twinkle Twinkle little star

Before I wrap this tutorial up for today, let us do one other thing! 

Let's make the stars sparkle randomly.

> In a future article, we'll introduce individual stars and make a dynamic and beautiful star field! 

The fixed field, for now, works for this tutorial but limits the capability of the engine.

Open the _Star_ scene and attach a script to the root Sprite:

    extends Sprite

    func _process(delta):
	    modulate = Color(1, 1, 1, randf() * 0.5 + 0.5)

as seen in the editor:

![image.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1519495875/ovznobo81jvfhddhiuj9.png)

Let's walk through the code:

    extends Sprite

> Extend the Sprite class

    func _process(delta):

> Implement the process function, which is called periodically by Godot Engine

	    modulate = Color(1, 1, 1, randf() * 0.5 + 0.5)

> Change the Sprite's colour! 

> The texture we assigned is primiarly transparent, with a few sprinkled stars on it (try opening in an image editor).

> The star pixels will have their alpha intensity altered between 0.5 and 1.0! In that way, they appear to sparkle and shine. 

> Unfortunately, they all will do so, like a synchronised swimming team. 

> As stated, in a future tutorial, we'll separate them, so that we can then make them shimmy independently with a broad spectrum of colours too!

Let's now run it!
<center>
![twinkle twinkle.gif](https://res.cloudinary.com/hpiynhbhq/image/upload/v1519496211/dul8xmliqpkrkbutiidg.gif)
</center>
... much better, as if the universe is alive. It's not brilliant, but it will do for now!

# Godot game workspace license file

As stated, to comply with the CC-SA-V3.0 license, I've added a _license.txt_ file into each of the _image_ folders in the _Stars_ and _Invader_ scene folders; this is why having an _images_ folder is important! You can compartmentalise images to ensure you protect the license terms and conditions:

![image.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1519496755/fe0valzanba6v2zsius9.png)

for example, the _license.txt_ reads:

    *********************************************************

    Please Note: The A11.png image was taken from the Spaceships pack found here:

    https://opengameart.org/content/126-2d-spaceships

    Using the cc-sa-v3.0 license
    https://creativecommons.org/licenses/by-sa/3.0/

    *********************************************************
    You can use any image from this pack (spaceships) in any project,
    The only condicion is that you thanks me in your project.

    If you use any of the images from this pack, please send me a email
    with a link to your project.

    Thanks

    kalface@gmail.com, 
    blog http://carlosalface.blogspot.pt/

    Carlos Alface 2017
    *********************************************************

By including these, I can be faithful to the terms I've agreed when uploading the project to GitHub. 

... but I wont stop there, I will also send a courteous email to inform them of this article!

# Finally

That concludes this issue. My next article will address  the player ship and firing a weapon! Finally, the fun will begin.

I've also created an Itch.io account for this and will make the game web playable!

Please do comment and ask questions! I'm more than happy to interact with you.

# Sample Project

I hope you've read through this Tutorial, as it will provide you with the hands-on skills that you simply can't learn from downloading the sample set of code. 

However, for those wanting the code, please download from [GitHub](https://github.com/sp33dy/Godot-v3-Tutorials-Beginner).

You should then Import the "Space Invaders (part 4)" folder into Godot Engine.

# Other Tutorials

#### Beginners

> * [Install Godot Engine 3.0](https://steemit.com/gamedev/@sp33dy/installing-godot-engine-v3-0-windows)
> * [Installing your First Demo](https://steemit.com/gamedev/@sp33dy/first-demo-godot-engine-v3-0)
> * [Your first Sprite!](https://steemit.com/utopian-io/@sp33dy/tutorial-godot-engine-v3-gdscript-your-first-moving-sprite)
> * [Move your first Sprite!](https://steemit.com/utopian-io/@sp33dy/tutorial-godot-engine-v3-gdscript-move-your-sprite)
> * [Create lots of Sprites!](https://steemit.com/utopian-io/@sp33dy/tutorial-godot-engine-v3-gdscript-create-lots-of-sprites)
> * [Sprite formations!](https://steemit.com/utopian-io/@sp33dy/tutorial-godot-engine-v3-gdscript-sprite-formations)
> * [Smooth Movement!](https://steemit.com/utopian-io/@sp33dy/tutorial-godot-engine-v3-gdscript-smooth-movement#comments)

#### Competent

> * [Custom TileMaps](https://steemit.com/utopian-io/@sp33dy/tutorial-godot-engine-v3-gdscript-custom-tilemap)
> * [Custom TileMap Scrolling](https://steemit.com/utopian-io/@sp33dy/tutorial-godot-engine-v3-gdscript-custom-tilemap-scrolling)


<br /><hr/><em>Posted on <a href="https://utopian.io/utopian-io/@sp33dy/tutorial-godot-engine-v3-gdscript-invader-graphics">Utopian.io -  Rewarding Open Source Contributors</a></em><hr/>
👍 , , , , , , , , , , ,