Shooting the Enemies

4 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.49
List Price:  €65.09
You save:  €18.60
£40.01
List Price:  £56.02
You save:  £16
CA$68.72
List Price:  CA$96.21
You save:  CA$27.49
A$76.07
List Price:  A$106.50
You save:  A$30.43
S$67.77
List Price:  S$94.88
You save:  S$27.11
HK$390.75
List Price:  HK$547.08
You save:  HK$156.33
CHF 45.42
List Price:  CHF 63.59
You save:  CHF 18.17
NOK kr546.05
List Price:  NOK kr764.52
You save:  NOK kr218.46
DKK kr346.79
List Price:  DKK kr485.54
You save:  DKK kr138.74
NZ$83.47
List Price:  NZ$116.87
You save:  NZ$33.39
د.إ183.61
List Price:  د.إ257.07
You save:  د.إ73.45
৳5,497.15
List Price:  ৳7,696.46
You save:  ৳2,199.30
₹4,174.77
List Price:  ₹5,845.02
You save:  ₹1,670.24
RM237.07
List Price:  RM331.92
You save:  RM94.85
₦70,208.45
List Price:  ₦98,297.45
You save:  ₦28,089
₨13,904.52
List Price:  ₨19,467.44
You save:  ₨5,562.92
฿1,847.12
List Price:  ฿2,586.11
You save:  ฿738.99
₺1,612.55
List Price:  ₺2,257.70
You save:  ₺645.14
B$253.69
List Price:  B$355.19
You save:  B$101.49
R928.83
List Price:  R1,300.44
You save:  R371.60
Лв91.08
List Price:  Лв127.53
You save:  Лв36.44
₩68,098.38
List Price:  ₩95,343.18
You save:  ₩27,244.80
₪185.27
List Price:  ₪259.39
You save:  ₪74.12
₱2,867.25
List Price:  ₱4,014.38
You save:  ₱1,147.12
¥7,768.14
List Price:  ¥10,876.02
You save:  ¥3,107.88
MX$845.42
List Price:  MX$1,183.66
You save:  MX$338.23
QR182.01
List Price:  QR254.83
You save:  QR72.82
P680.26
List Price:  P952.42
You save:  P272.15
KSh6,548.69
List Price:  KSh9,168.69
You save:  KSh2,620
E£2,378.08
List Price:  E£3,329.50
You save:  E£951.42
ብር2,851.79
List Price:  ብር3,992.74
You save:  ብር1,140.94
Kz41,842.62
List Price:  Kz58,583.02
You save:  Kz16,740.40
CLP$46,821.63
List Price:  CLP$65,554.03
You save:  CLP$18,732.40
CN¥361.19
List Price:  CN¥505.70
You save:  CN¥144.50
RD$2,907.93
List Price:  RD$4,071.34
You save:  RD$1,163.40
DA6,724.97
List Price:  DA9,415.49
You save:  DA2,690.52
FJ$113.71
List Price:  FJ$159.21
You save:  FJ$45.49
Q389.15
List Price:  Q544.84
You save:  Q155.69
GY$10,478.82
List Price:  GY$14,671.19
You save:  GY$4,192.36
ISK kr6,988.60
List Price:  ISK kr9,784.60
You save:  ISK kr2,796
DH502.20
List Price:  DH703.12
You save:  DH200.92
L886.35
List Price:  L1,240.96
You save:  L354.61
ден2,865.74
List Price:  ден4,012.27
You save:  ден1,146.52
MOP$403.50
List Price:  MOP$564.93
You save:  MOP$161.43
N$924.27
List Price:  N$1,294.05
You save:  N$369.78
C$1,843.71
List Price:  C$2,581.34
You save:  C$737.63
रु6,692.24
List Price:  रु9,369.68
You save:  रु2,677.43
S/186.82
List Price:  S/261.57
You save:  S/74.74
K193.90
List Price:  K271.48
You save:  K77.57
SAR187.47
List Price:  SAR262.48
You save:  SAR75
ZK1,357.40
List Price:  ZK1,900.47
You save:  ZK543.06
L231.37
List Price:  L323.94
You save:  L92.57
Kč1,164.81
List Price:  Kč1,630.83
You save:  Kč466.01
Ft18,103.62
List Price:  Ft25,346.53
You save:  Ft7,242.90
SEK kr545.15
List Price:  SEK kr763.26
You save:  SEK kr218.10
ARS$44,029.30
List Price:  ARS$61,644.55
You save:  ARS$17,615.24
Bs345.47
List Price:  Bs483.68
You save:  Bs138.21
COP$195,030.72
List Price:  COP$273,058.61
You save:  COP$78,027.89
₡25,614.18
List Price:  ₡35,861.91
You save:  ₡10,247.72
L1,237.73
List Price:  L1,732.92
You save:  L495.19
₲373,769.90
List Price:  ₲523,307.77
You save:  ₲149,537.87
$U1,917.85
List Price:  $U2,685.15
You save:  $U767.29
zł200.62
List Price:  zł280.89
You save:  zł80.26
Already have an account? Log In

Transcript

Headier. In this lecture we'll implement shooting the enemies. The enemy object will have a variable called HP which is their health. For our enemies, the HP will be two. Each time a bullet hits an enemy, its health goes down by one. And when the health rate is zero, the enemy instance is destroyed and an explosion is created our displays, so let's get to it.

I'll start by creating a new sprite called s explosion. I click on Import. This is the explosion animation that I want to import. You can see that it's a horizontal strip image with all the frames inside it. It has six frames and I want gamemaker to split all the frames into separate sub images. So for that I've added underscore strip sets at the end of the file name.

Six is the number of frames and seeing that gamemaker will automatically split the frames into separate images. So if your strip has eight frames, you need to write eight here. If it has 12 frames you need to write well and so on So I'll import this image, it's now split into separate sub images and the animation can be played. Also make sure that you set the origin to middle center. Now we'll create an object and name it oh explosion. I'll assign the sprite.

And now allow the creative end. Here I'll add the random number action, I need to set the rotation of the subjects to a random value so that when an explosion is created, it always looks different. So I'll change decimal to integer keep the minimum at zero, set the maximum to 360. Enter the target to image underscore angle. These values are in degrees, so that's why the maximum is 360 degrees. And the target image angle is a built in variable that controls the rotation of the instance.

So the image angle will get a random value from zero to 360 degrees. Now we'll click on Add event, go to other and select animation end. Discipline drones when the sprite and Mission ends. If the explosion animation ends, we don't want to keep looping soil out or destroy astons action in this event. So the explosion animation plays once and done, it's destroyed. Now we'll open Oh enemy and go to its create event.

Here are the Assign variable action and initialize the variable hp. I'll set its value to two. Now I'll open this up and I'll search for the variable action. I'll drag it in, but make sure that the drop it here, not here so that it's outside the condition. The variable being checked will be HP, the condition will be less or equal and the value will be zero. So this condition checks whether the SP is less than or equal to zero, which means or the enemy should be destroyed.

So with that condition, I'll attach the destroy instance action. Then I'll search for the Create instance action and add it under the same condition for creating the explosion. So for the object outlet Oh explosion, the position will be the x and y of the enemy is transistor Until there will be instances. So when the enemy's HP reaches zero it will be destroyed and an explosion instance will be created at its place. Now I'll open or bullet I'll click on Add event go under collision and select Oh enemy. This event runs disadvantages when the current instance touches an instance of the other object.

Here the current instance is a bullet and the other object is oh enemy, so this event will run whenever a bullet touches an enemy. Here we need to reduce that enemy's HP so I'll add an assign variable action here. First of all, I click on this arrow. Through this menu you can select which instance the action applies to. For example, if I create a variable using this action, it will be created inside or bullet since this action is running inside the bullet object, but if I select opener here, then the variable will be created inside a player and not a bullet because that way the action will be applied to the instance soil change To order so that the action runs inside the other instance in the collision event. The other instance here is the enemy instance colliding with the bowler so this action will run in that enemy instance.

The variable being changed here is HP and the value is minus one relative. So when a bullet hits an enemy that enemy's HP will be reduced by one you can see that this action has a purple border since it is being applied to some other instance and not double it instance itself. done it should also destroy it a Buddha instance now around the game, I should the enemies and you can see that they are destroyed after being Hitwise, since the HP is true, you could change the SP one so that they are killed in one head, or you could change it to a larger value to make the game more difficult. That's it for this lecture. Now let's move on to the next one. We will implement AI 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.