Create A Space Shooter Game | Egretia Engine Tutorial For Beginners Part 2

This is the second part of Egretia Engine tutorial, showing how to build a space shooter game!

Part 1 https://bit.ly/32xy7r3

Demonstration

Programming

>Bullet

Image for post

Speed principle:

Image for post

Error

Image for post

Wrong code

Image for post

Correction:

1this.bg = new BG(this);

2this.player = new Player(this);

3// x,y, speed,angle

4this.zd = new ZD(this.player.x,this.player.y, 20 ,30,this);

5

6this.addChild(this.bg);

7this.addChild(this.zd);

8this.addChild(this.player);

9

>Factory Pattern

Core: objects creation

In Factory pattern, we create object which will be stored in the factory’s storage system.

New object creation will be allocated and returned in the storage system, but the objects will be removed when certain conditions are met.

If you use the factory pattern to manage object, the object must have a property:

The visible (vis) property: The boolean type represents whether it can still be stored in the factory.

vis== false. This object will be removed in order to ensure that storage system is not full

vis == true means that it can be stored.

Bullet update:

Image for post

>ZDManager

1public create(x:number,y:number,v:number,n:number,game:MainGame){

2 //create bullet

3 let one = new ZD(x,y,v,n,game);

4 //add

5 this.addChild(one);

6 // to the end of array

7 this.zm.push(one);

8 //

9 }

Update principles

1public update(){

2 // the total length

3 for(let i = 0 ; i < this.zm.length ; i++){

4 // find each bullet

5 let one = this.zm[i];

6 one.update();

7 // remove the extra bullets

8 // if bullet is off the screen ,vis == false, remove

9 if(one.vis == false){

10 //remove it from the scene

11 this.removeChild(one);

12 //remove it from the storage system

13 this.zm.splice(i ,1);

14 //remove one item, the length -1

15 i — ;

16 }

17 }

18}

Maingame update principles

1 public update()

2 {

3 this.bg.update();

4 this.player.update();

5 this.zm.update();

6 //time interval

7 this.t++;

8 if(this.t >= 4){

9 //after the creation is called, the bullet will occur

10 //add two more ballistic paths, there are five paths in total

11 this.zm.create(this.player.x,this.player.y,20,0, this );

12 this.zm.create(this.player.x,this.player.y,20,-15, this );

13 this.zm.create(this.player.x,this.player.y,20,-30, this );

14 this.zm.create(this.player.x ,this.player.y,20,15, this );

15 this.zm.create(this.player.x,this.player.y,20,30, this );

16 this.t = 0;

17 }

18 }

What are the coolest projects you saw from people using Egretia engine?

Stay tuned for updates from the Egretia official channels below so that you can be involved in all the exciting things to come!

Egretia Telegram: https://t.me/Egretia

Egretia Twitter: https://twitter.com/Egretia_io

Egretia Website: https://egretia.io/