Enemy Ships

5 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$49.99
List Price:  $69.99
You save:  $20
€46.58
List Price:  €65.22
You save:  €18.63
£40.03
List Price:  £56.04
You save:  £16.01
CA$68.63
List Price:  CA$96.09
You save:  CA$27.45
A$76.02
List Price:  A$106.44
You save:  A$30.41
S$67.81
List Price:  S$94.93
You save:  S$27.12
HK$390.69
List Price:  HK$547
You save:  HK$156.30
CHF 45.46
List Price:  CHF 63.65
You save:  CHF 18.19
NOK kr546.43
List Price:  NOK kr765.05
You save:  NOK kr218.61
DKK kr347.46
List Price:  DKK kr486.48
You save:  DKK kr139.01
NZ$83.33
List Price:  NZ$116.68
You save:  NZ$33.34
د.إ183.60
List Price:  د.إ257.06
You save:  د.إ73.45
৳5,489.47
List Price:  ৳7,685.71
You save:  ৳2,196.23
₹4,174.55
List Price:  ₹5,844.71
You save:  ₹1,670.15
RM236.99
List Price:  RM331.80
You save:  RM94.81
₦70,298.43
List Price:  ₦98,423.43
You save:  ₦28,125
₨13,909.88
List Price:  ₨19,474.95
You save:  ₨5,565.06
฿1,846.13
List Price:  ฿2,584.73
You save:  ฿738.60
₺1,610.66
List Price:  ₺2,255.06
You save:  ₺644.39
B$254.49
List Price:  B$356.31
You save:  B$101.82
R927.79
List Price:  R1,298.99
You save:  R371.19
Лв91.12
List Price:  Лв127.57
You save:  Лв36.45
₩68,531.94
List Price:  ₩95,950.21
You save:  ₩27,418.26
₪186.70
List Price:  ₪261.40
You save:  ₪74.69
₱2,868.05
List Price:  ₱4,015.50
You save:  ₱1,147.44
¥7,794.14
List Price:  ¥10,912.42
You save:  ¥3,118.28
MX$847.82
List Price:  MX$1,187.01
You save:  MX$339.19
QR181.98
List Price:  QR254.79
You save:  QR72.81
P683.14
List Price:  P956.45
You save:  P273.31
KSh6,548.69
List Price:  KSh9,168.69
You save:  KSh2,620
E£2,366.87
List Price:  E£3,313.80
You save:  E£946.93
ብር2,871.93
List Price:  ብር4,020.93
You save:  ብር1,149
Kz41,809.30
List Price:  Kz58,536.36
You save:  Kz16,727.06
CLP$46,797.13
List Price:  CLP$65,519.73
You save:  CLP$18,722.60
CN¥361.26
List Price:  CN¥505.79
You save:  CN¥144.53
RD$2,902.73
List Price:  RD$4,064.05
You save:  RD$1,161.32
DA6,738.30
List Price:  DA9,434.16
You save:  DA2,695.86
FJ$113.87
List Price:  FJ$159.43
You save:  FJ$45.56
Q388.63
List Price:  Q544.12
You save:  Q155.48
GY$10,470.35
List Price:  GY$14,659.33
You save:  GY$4,188.98
ISK kr7,002.59
List Price:  ISK kr9,804.19
You save:  ISK kr2,801.60
DH501.40
List Price:  DH702
You save:  DH200.60
L883.29
List Price:  L1,236.68
You save:  L353.38
ден2,870.60
List Price:  ден4,019.08
You save:  ден1,148.47
MOP$402.76
List Price:  MOP$563.89
You save:  MOP$161.13
N$930.61
List Price:  N$1,302.92
You save:  N$372.31
C$1,841.31
List Price:  C$2,577.98
You save:  C$736.67
रु6,683.63
List Price:  रु9,357.62
You save:  रु2,673.98
S/186.29
List Price:  S/260.83
You save:  S/74.53
K193.80
List Price:  K271.34
You save:  K77.53
SAR187.48
List Price:  SAR262.49
You save:  SAR75
ZK1,366.70
List Price:  ZK1,913.50
You save:  ZK546.79
L231.77
List Price:  L324.50
You save:  L92.73
Kč1,164.46
List Price:  Kč1,630.34
You save:  Kč465.87
Ft18,093.17
List Price:  Ft25,331.89
You save:  Ft7,238.71
SEK kr546.34
List Price:  SEK kr764.93
You save:  SEK kr218.58
ARS$44,079.30
List Price:  ARS$61,714.55
You save:  ARS$17,635.24
Bs345.59
List Price:  Bs483.86
You save:  Bs138.26
COP$194,670.18
List Price:  COP$272,553.83
You save:  COP$77,883.65
₡25,602.51
List Price:  ₡35,845.57
You save:  ₡10,243.05
L1,236.05
List Price:  L1,730.57
You save:  L494.52
₲373,702.36
List Price:  ₲523,213.21
You save:  ₲149,510.84
$U1,931.55
List Price:  $U2,704.33
You save:  $U772.77
zł200.15
List Price:  zł280.23
You save:  zł80.07
Already have an account? Log In

Transcript

Here in this lecture, we'll add enemy shapes to our game. Here I've imported a sprite for the enemy, make sure its origin is set to middle center. Now we'll create a new object and name it oh enemy, so this will be the enemy shape. I'll assign the sprite. Now I'll add a create event. In this event, I'll add the set speed action.

I'll change direction to vertical and set the speed to two. So the enemy ships will move downwards at a speed of two. Now I'll add the step event. Now we need to make it so that the enemy instance is destroyed when it goes out of the room. So as you know, we can use the outside room event for that. But we want to create our enemies above the room so that they come down from there, but that's outside the room as well.

So the instances will just get deleted. So we want to make sure that the enemies are only destroyed when they are below the rule. So for that, we'll use a country We'll check the stances y value and make sure that it's greater than the room height, then we'll destroy the instance. So in the step event, I'll add the variable action, the variable will be y, I'll set the condition to greater and the value to room height. So as you can see in the overview here, it's x if the y is greater than the room height, now allowed to destroy and stuff action and attach it to this condition. So the instance will be destroyed when the y is greater than the room height.

Now we need to implement enemy spawning. So I'll open a manager and open the Create event. I click on the plus sign here to add another alarm countdown. Alarm zero is used for the islands. So for the enemies, I'll use alarm one, and the count on value will be 60. And now I'll add the alarm one event.

In this event alert the get random number action We'll use this action to get a random exposition for the enemy ship just like we did for the islands. So we'll change decimal to integer, I'll leave the minimum at zero and set the maximum to 1024, which is my room word. And for the variable, I'll type ship x, I'll make it temporary. Now I'll add the Create instance action for the object or slash or enemy, the exposition will be shaped x, which is a random value returned from the previous action, the y position will be minus 64. So it will be created above the room and the layer will be instances which is a default layer. Now we need to set the alarm on countdown again, so that alarm keeps looping.

But instead of setting the alarm to a specific value, I'm gonna use a random action so that there's some variation in the enemy spawns. So I'll add another get random number action here. I'll change decimal to integer because land values are generally integers. Now we'll set the minimum to 60, which is one second and the maximum to 240, which is four seconds. The variable name will be alarm time anecca temporary. Now I'll add the alarm countdown action.

The event will be alarm one, and the countdown will be alarmed time. So the alarm countdown will be based on a random number from this action. Now we'll run the game and you can see the enemy stances spawning from the top. But there is one issue when the enemy ships reach the bottom you can see them being destroyed. So let's see why that happens. I'll go to all enemies type event.

As you can see, we destroy that instance if the y is greater than the room wide, the y of the stars is at the center because the origin of the sprite is set to middle center. So when that center point, which is the why becomes greater than the room hide the instance is destroyed. So half of the shape is still visible inside the room when it is destroyed. So to fix this, we can increase the value in the condition. So instead of room height, we can check at room height plus 64. So that will be 64 pixels below the room boundary.

That point is outside the room. So when the instance is destroyed there, it won't be visible in the room, soldier on the game. Escape a bit ahead, and you can see that there are no destroyed when they're still in the room. And now we need to add another feature. As you know, the range for the exposition of an enemy is from zero to the room where it so the enemies can spawn anywhere from the left border to the very tight border. So we need to add margins on both sides so that enemies don't spawn in those areas.

This will also make the game easier for the players since enemies will be spawning in a smaller area. So I'll open or managers alarm one event, we need to set a margin value, so I'll go with 120 pixels as the margin. So I'll set the minimum to 120. And we'll subtract 120 from the maximum value. So now the modules are implemented. Now the enemies will not spawn in the margin area.

So that's it for the lecture. Let me know if you have any questions. And now let's move on to the next lecture we will implement enemy shooting

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.