[GAME] Galactic Pirates with increasing difficulty!

Hi all,

This is my try on the laser defender game!
I named it Galactic Pirates, since you play a pirate ship and you try to gather as much loot as possible.

The game contains:

  • increasing difficulty with 3 different enemies and 3 types of formations (order of appearance is at random)
  • drops (health, shield, score and firerate boost)
  • possibility to move up and down with your ship

How much loot do you think you can salvage??

Galactic Pirates

PS: Still a unity4 build, so unity webplayer is needed in order to play

The game looks and plays amazing! Really awesome job! :smiley:

1 Like

Do You Mind Sharing The Code For Moving Up and Down

Been Trying To Implement That since Ages But It Isn’t Working.

The Movement Is Very Jittery For Me So If You don’t mind could you help me out.

Hi Kshitij,

This is all the code you need in order to get the ship also moving up and down. I do have tell you this only makes the ship move up/down OR left/right. So as an example: you can’t move to the upper rightcorner in one move, you first have to go right and then up. Under the code-block I’ll explain my code a bit more.

using UnityEngine;
using System.Collections;

public class PrintVersion : MonoBehaviour {

public float speed;
public float paddingX=0.5f;
public float paddingY=0.4f;

private float xmin;
private float xmax;
private float ymin;
private float ymax;

void Start () {
float distance = transform.position.z - Camera.main.transform.position.z;
Vector3 lowerLeft = Camera.main.ViewportToWorldPoint(new Vector3(0,0,distance));
Vector3 upperRight = Camera.main.ViewportToWorldPoint(new Vector3(1,1,distance));
xmin = lowerLeft.x+paddingX;
xmax = upperRight.x-paddingX;
ymin = lowerLeft.y+paddingY;
ymax = upperRight.y-paddingY;
void Update () {
void MoveWithKeys(){

  if (Input.GetKey(KeyCode.LeftArrow)){
  	this.transform.position += Vector3.left*speed*Time.deltaTime;
  } else if (Input.GetKey(KeyCode.RightArrow)){
  	this.transform.position += Vector3.right*speed*Time.deltaTime;
  } else if (Input.GetKey(KeyCode.UpArrow)){
  	this.transform.position += Vector3.up*speed*Time.deltaTime;
  } else if (Input.GetKey(KeyCode.DownArrow)){
  	this.transform.position += Vector3.down*speed*Time.deltaTime;
  // restrict player to gamespace
  float newX = Mathf.Clamp(transform.position.x, xmin, xmax);
  float newY = Mathf.Clamp(transform.position.y, ymin, ymax);
  transform.position = new Vector3 (newX, newY, transform.position.z);


  1. So first we look to all the variables. Since you also want to move in a second dimension (up/down) you need more variables. In this case these are paddingX, xmin and xmax.

  2. In the course we added a safeguard against the ship moving out of the playspace in the dimension left/right. Now the same has to be done for the dimension up/down. For the calibration I created the points lowerleft and upperright (instead of lowerleft and lowerright in the course). The x/y-coordinates of these two points, together with both paddings result in the values for the xmin, xmax, ymin and ymax. The following picture might illustrate this a bit better.

  1. After the calibration the MoveWithKeys method has to be changed to also have an input for the up and down arrow. Therefor we use respectively the vector3.up and vector3.down.

  2. The last thing that has to be done is to actually prevent the ship from going out of the playspace. This was already explained in the course, but now you just need to add another line where you clamp the x-coordinate to its min and max value.

I hope this explained the logic behind the code. Should you still have some questions feel free to ask!

1 Like

Great Thanks

Got It Working

Beautiful game! just… WOW!

Wow!!! Great job. Very smooth. The difficulty goes up in the right increments. Keep up the good work!

I like the fact that you implemented power ups and different enemies formation, I am trying to do this right now.

Hi EpicArcher!!

Thanks! Should you need some help with the power-ups and different formations, just ask and I’ll try to answer as quickly as possible :wink:

I just figure out how to create explosion for the player and enemies, also a have a health bar, but still a little buggy, next step will be the shield power up!

Wow, man! This almost feels like a legit, complete game. The powerups, the different enemy types with different firing methods. Visualizing the damage to enemies that take more than one hit to make you feel like you’re doing damage was a nice touch, too. I do have some minor gripes, though. I feel like the player movement is a bit slow. Also it would look nice if the enemies exploded rather than just disappear. Those are very minor, though, and doesn’t take away from what an overall achievement this is!

Some questions for you @Jonas_Boons:

  • How many layers of starfield (particles) you have?

  • How did you approached the different enemy formation ? Do you have different EnemyFormation, each on with different positon for enemies ?

  • What about the different enemies ? do you have something like a pool of enemies that you randomly get it ?


Thanks James! Yes there are still some minor changes possible and I agree with that. It’s just that I also wanted to advance with the course and not put lots of time in it. I tried some new ways of improving the game without relying on the stuff we learned in the previous game (example the exploding blocks in Block Breaker). I might even come back to this game later on in the course, who knows I might make it 3D :wink:

But I do appreciate the comments!


I used two different starfields on top of each other just like we did in the course. The following shots show the settings that I used for both.

Enemy Formations

I actually use 3 different formations (line, horn and V-formation) and each one has three difficulty levels (basic, medium and heavy), this way I’m using 9 types of formations. In the different formations I just adjusted the spots where enemies spawn. The difference for the difficulties is that the enemy spawners in the formations have different probabilities for showing a certain enemy. So my three heavy formations have more chance/probability that a more ‘difficult’ enemy will spawn.
I’ve put all nine as prefab and linked them to an object FormationSpawner with a script (with same name), which chooses one of the formations every time another wave should appear. The choice is made by using a random.range (1, 101) and compare this in if-statements with thresholds.

As an example:

You got three formations.

1. Formation 1: 40%
2. Formation 2: 40%
3. Formation 3: 20%

In the if-statement you compare the generated number with 40, if its less you get formation 1. If not you compare it with 80, if it’s less you get formation2 and if not you get formation 3.

Different Enemies

For this game I created three different enemies (but you can make as many as you like, but the time to implement does increase with every new enemy)

  1. Blue (easy): basic enemy without anything special
  2. Red (hard): More life and slow spread shot
  3. Green (hard): basic life and fast shooting machinegun-like effect

I prefab’ed them and the enemy-spawners (spots where the enemy spawns) in the formations are given probabilities to show certain enemies more or less.

Example: My medium enemy-spawner has probabilities of 40, 40 and 20. So there is 40% chance that a blue will spawn, 40% for a red one and 20% for a greeny. My heavy spawner has 0, 50 and 50. So this one will not spawn blue ones anymore and equally spawn red and green.

I hope this helps you a bit. I’ve only given hints at this time and not given my actual code because this way you learn alot more from it and it is way more fun. But if you want I can always share my code. So just ask if you want it :wink:

1 Like

Privacy & Terms