Hellow Guys, this week will be really simple, nothing really new, this tutorial will be 3 steps, the first one we will add a very simple background moving behind our ship, and it is really simple and without parallax (a theme that we may abort later), the second step we will add some enemies and the third step is make this enemies shoot on our ship, but this week won’t have any kind of collision (a theme for our next week) 😉 Oh, and if you want to read our last tutorial the link is HERE!

I – Adding a Simple Moving Background

The first thing, let’s add our background to our scene, drag the image bellow to your scene, in your document in Spaceship.fla: -So select it, and click in “Modify->Convert to Symbol…”.

– So click “OK” and “OK” again (if you need) Delete the Background Symbol from the scene and the BG Background will be listed in your library. Time to code: Add 3 new vars to our public class Spaceship:

And now if you test our project, the background will be moving against our ship.

II – Preparing Enemy Ship

Now the enemy ship, you will do with enemy ship bellow almost the same you did with the Background, In other words, add this to our Library with the name EnemyShip and class: EnemyShiplinked. -Import the image bellow to your flash document.

This ship also was created by me, so it is not problem to use it for this tutorial. And do the same with the new LaserShoot, convert it (bellow) to a symbol and name it: Lasershoot2 and class: Lasershoot2

Your library now, should look something like this:

So how it will work here: The enemy ship will spawn randomly coming from some possible ways crossing the screen shooting. Later for the next week: If the enemy ship hit the player he will explode and lose the game and if the player’s spaceship hit the enemy, the enemy explode and X ponts will be added to the player score. 😉 First, let’s edit our Lasershoot2 class; Right click over the Lasershoot2 on the library -Select Edit Class

We need somehow link the laser to the enemyship’s array (that we will create soon), so let’s create a get and set inside this Lasershoot2 class and the full code of this class shall looks like: Script.as

Save it with the name: Lasershoot2.as Now go to the Spaceship.fla and do the same with the EnemyShip, right-click over the “EnemyShip” in library and select Edit Class and let’s add a bunch of get and setters here. EnemyShip.as:

Explaining: This enemyShoot will create the lasershoot2 for the enemy and send it to the player direction. The “hindex” is the enemyship’s position on the array enemyList.

Now go to our function Draw(event:Event):void, first we will add the process of spawn the Enemy Spaceship:

The Spawn will works ramdomly and the movements too. However the movements are limited, if the ship spawn up to half-screen-height, the enemy ship can go straight our coming from up to down in diagonal, ekse the enemy ship can go straight our coming from down to up in diagonal: