# How To Make A Game - Adding Interesting Enemies [6]

https://www.youtube.com/watch?v=UWIrB98Qnxg

[00:00] this is the final video in a tutorial series where we'll be making a wave defense game.
[00:07] in the last video people were asked to vote on what we would do in this video and they picked enemy AI.
[00:16] so we'll be giving all of the enemies a unique movement pattern or ability and then we'll finish the project with a couple of touches including mobile controls because people have been asking for it so let's jump in now.
[00:30] the quickest way to give your enemies some movement is to use the Boyd's extension which I kind of overuse but it's really good for giving basic enemies some more interesting movement.
[00:42] so we'll just give that behavior to the ghost enemy.
[00:47] there we go.
[00:50] and now go to enemies and instead of telling it to move I'm going to tell it to go towards the center using the Boyd's extension.
[00:58] I'm gonna tell it to go towards an
[01:00] object
[01:01] and the object is the center
[01:04] decision wait we'll just start with 10
[01:07] and see how that works
[01:08] and now we'll preview the game
[01:11] foreign
[01:14] okay that's way too fast and they were rotating
[01:18] so let's turn off rotation
[01:20] and turn down the max speed a lot
[01:26] and let's see how that works out
[01:31] there it comes
[01:33] still too fast
[01:37] and it's kind of beelining for the center
[01:41] so we need to change that as well
[01:44] let's change the decision weight down to two
[01:46] and see what that does
[01:51] [Music]
[01:54] change it to 0.5
[01:56] see if that helps
[02:01] oh there we go
[02:04] now we're getting that
[02:07] kind of I'll be there eventually
[02:08] Behavior
[02:10] that's what I want
[02:12] I'm going to tweak the values a little
[02:14] bit and then come back
[02:18] [Music]
[02:25] thank you
[02:26] [Music]
[02:58] okay there we go so I have tweaked the
[03:01] speeds a little bit and I've changed it.
[03:03] so that now the ghost tries to avoid the player.
[03:06] so when you're playing the game you can try to chase them off away from the center.
[03:10] which makes them a much more interesting and kind of dynamic enemy.
[03:12] but also makes them a little random so if you get your hands on this game you might want to tweak the values on these things.
[03:22] alright now I'm going to do the same thing to the Imp but I'm going to make it different on how they approach the center.
[03:27] I'll give them the same behavior uh leave all that alone.
[03:35] I want them to be even slower than the ghost.
[03:40] not rotate.
[03:42] [Music]
[03:47] I don't want them to be afraid of the player.
[03:53] okay and now I'm also going to give them the fire bullet extension as well.
[03:55] so they can fire at the center.
[04:04] there we go.
[04:06] let's make their firing cool down every four seconds.
[04:13] put one into the scene.
[04:17] going to create a new object Sprite.
[04:36] okay so we'll go here make a new group.
[04:43] imp.
[04:47] and we'll make it so that when the Imp is foreign.
[04:57] we changed the fire rate in the extension itself or the behavior itself to four seconds so we need to make it.
[05:03] shoot or fire bullet towards a position from the Imp.
[05:14] oh no wait.
[05:15] fire the bullet nope here.
[05:20] fire the bullet from the Imp and we'll go from the Imp Center.
[05:34] X and Y to the center objects.
[05:41] Center.
[05:43] X and Y and make it go at 50 I guess.
[05:51] okay and we'll see if that works.
[05:55] it should fire up there it is yep okay.
[05:58] great.
[06:00] uh the well it's a little bit out of alignment.
[06:04] because I haven't changed the points.
[06:06] changes origin to its Center.
[06:11] now see how it looks.
[06:18] there we go great.
[06:21] and now we'll change this down to 40.
[06:26] and we'll change the imps movement speed.
[06:27] down slower.
[06:29] go 10 and 10.
[06:34] all right now I want to make this so.
[06:36] that you can block these bullets with.
[06:38] your own body.
[06:39] because why not I can do what I want to.
[06:43] and you can change this if you uh open.
[06:46] the example later and want a different.
[06:48] thing.
[06:49] [Music]
[06:51] so let's create a new event here.
[06:54] if the enemy bullet is in collision with.
[06:57] the player.
[07:01] delete.
[07:03] enemy bullet.
[07:05] so that way you have a way to combat these bullets when they fly in.
[07:11] so when they shoot the bullet.
[07:14] yeah I can run into it and stop it.
[07:17] all right.
[07:19] I will want to change the player's collision mask I think a little bit.
[07:25] yep.
[07:27] let's bring this down.
[07:31] okay.
[07:33] all right and that is the Imp done.
[07:37] and now for the spider I'm not going to use boys movement for the spider because that gives like a floating effect.
[07:42] instead I'm going to use points and spawn the spider and use the movement paper that we've already got set up.
[07:48] so I'm going to duplicate this and call this the spider spawn.
[07:56] and put a couple points in here and here and here and here maybe a couple more.
[08:07] there we go okay and I'm going to add another object in.
[08:13] call this shadow.
[08:15] if you've ever seen those hand enemies.
[08:17] the evil hand enemies from Zelda back in the day this is what I'm doing.
[08:24] adding a new Sprite object call this drop.
[08:31] great change the center point to the center.
[08:37] oh wait no no no it needs to be the same as the spider.
[08:41] so spider's points.
[08:44] its origin is 12 22.
[08:48] cancel.
[08:50] Shadow points 12 22.
[08:56] and the drop object 12 22.
[09:03] and this is only going to work because the shadow image and the drop image are both the exact same size as the spider.
[09:08] image the full size of it.
[09:13] and now we go to the spawning.
[09:20] and we're going to create both of those.
[09:22] objects shadow.
[09:25] and the drop.
[09:30] move the spider down here.
[09:34] add a weight action.
[09:37] let's say one second.
[09:42] and I need to give both of these objects.
[09:45] the tween Behavior.
[09:50] tween.
[09:52] wait.
[09:53] not between Z order.
[09:57] just a normal tween.
[09:59] okay.
[10:01] drop.
[10:03] add the.
[10:05] tween Behavior.
[10:09] there it is.
[10:13] all right and then tween.
[10:17] uh y position.
[10:24] now we'll start with scale.
[10:32] we'll call the train grow and we'll go to full scale.
[10:37] easing can be linear I guess.
[10:40] again this can be changed because it's not a big deal.
[10:43] one thousand milliseconds and then destroy.
[10:50] I'm not going to scale from the center.
[10:52] I'm going to scale from the origin I believe.
[10:56] move this here.
[11:00] we're going to change the spot that this spawns at to the spider spawn point.
[11:05] and the same thing for the drop object.
[11:13] We'll pick a random spider spawn point.
[11:19] And we'll do another tween for the Y position of the drop object.
[11:31] And call this drop.
[11:39] And we'll go down.
[11:41] We'll go down a hundred so we fall down a hundred.
[11:44] And again we'll stick with linear a thousand milliseconds destroy object when it's done.
[11:52] All right so these here are here.
[11:55] Now we need to spawn above the spider spawn point 100 pixels so that way when we drop we go.
[12:04] Hold on.
[12:06] Negative negative is up.
[12:08] And so that way when we drop we go from 100 above down.
[12:14] to the actual position itself.
[12:18] also spawn at the same spider spawner.
[12:23] what's gonna happen is we're going to spawn these objects between them to the right position.
[12:29] and then have the spider spawn at those positions when they get destroyed by the tweening event.
[12:40] I'm going to change this to zero for right now to make it Force the spiders to spawn first.
[12:50] see there's one.
[12:52] okay all right.
[12:55] so they are dropping not exactly greatly but they're dropping properly.
[13:01] what's not happening is a scale event.
[13:07] so we'll scale the Sprite object of The Shadow.
[13:15] to zero.
[13:19] so then it's going to start at zero and go to Tween up so let's try that.
[13:27] oh there we go.
[13:30] there's another one.
[13:33] so that looks like they're falling from the ceiling.
[13:38] I'm going to change the position of that spawning point though because that's a bit weird.
[13:43] let's change the spawning point to the center.
[13:46] there we go and.
[13:48] [Music]
[13:59] perfect.
[14:01] [Music]
[14:06] oh.
[14:07] I'm going to actually beginning of scene hide those spider spawners.
[14:11] so they're still there we just can't see.
[14:16] them.
[14:17] Okay, cool.
[14:20] And now you can see the spiders are dropping.
[14:24] And because the object that's dropping is not the spider itself, I can't shoot it.
[14:31] All right, great. So now we have three unique enemies that all act differently.
[14:36] The ghost kind of hovers around and he enters its way to the center.
[14:38] The spider runs towards the center after dropping from the ceiling.
[14:42] And the Imp will actually fire a fireball that I didn't code properly.
[14:49] Hold on.
[14:51] Okay, game over.
[14:56] We'll also add if the enemy bullet hits the center, game over.
[14:59] So we need to use or.
[15:07] And then put this inside of the or condition.
[15:10] So now, if the enemy gets in the center or if the enemy bullet gets to the center, it's game over and we start over.
[15:22] now let me just play test that to make sure it actually works
[15:29] and as a nice twist the ghosts now being afraid of you means that they won't go towards the center
[15:34] so you'll kind of have an ever increasing swarm of ghosts around the center until you choose to run off and grab the experience points
[15:42] or runoff to try to protect the center from one of the Fireballs
[15:45] now there's one thing I did notice though
[15:49] and that's that these enemies aren't necessarily looking the right way anymore because the code has changed for how they spawn
[15:56] so I'm going to need to change this forever so they won't just do it when they spawn they'll do it always
[16:07] okay now I need to fix a bug that somebody mentioned in one of the earlier comments
[16:14] um the leveling up layer exists whether or not you can see it
[16:19] so even during gameplay if you click
[16:24] where that button is on screen you will get that level up without the experience points required.
[16:31] okay so the buttons clicked so we need to add a second condition here for um if the layer is currently visible.
[16:43] so we can search for visibility visibility of a layer the leveling up layer.
[16:50] so we will only be able to click on the button if the leveling up layer is actually showing.
[16:56] so that bug is now fixed.
[17:00] great now the last thing I want to do in this video before I run out of time is ADD mobile controls because people have been asking for that and it's really quick so watch this.
[17:10] joystick.
[17:13] I like these joysticks.
[17:17] okay we'll create another layer call this mobile controls.
[17:26] uh we'll call this movement.
[17:33] plop this down shrink it down a little bit because it's a bit big.
[17:39] you can find the size you want.
[17:41] maybe a little bigger there we go.
[17:43] and then I will duplicate this.
[17:48] and call it aiming.
[17:51] all right so now movement and aiming for the player I'm going to go to behaviors.
[17:57] add a behavior and once you've added a joystick you should have top down multi-touch controller mapper.
[18:09] top down movement analog great.
[18:12] so I've added the behavior to the player.
[18:14] I press preview.
[18:17] ah.
[18:18] I've got to put the object on the layer.
[18:21] right.
[18:23] mobile controls okay preview.
[18:29] Behavior plus this plus the mapper behavior and it works.
[18:33] Now for aiming let's plop this one down.
[18:37] Make it the same size so 96 by 96.
[18:42] And roughly the same spot.
[18:46] Okay all right now for this it's going to be a little bit trickier but we'll collapse all of this.
[18:54] Go to the player go to gun.
[18:58] Check if this is a mobile device.
[19:01] And change this to not.
[19:05] Make a new action move that there.
[19:09] Alright so if it's not a mobile device we will rotate the gun towards the cursor.
[19:13] If it is a mobile device we will rotate the gun towards the angle.
[19:19] Angular speed zero.
[19:22] Angle of that joystick so joystick angle.
[19:30] I think it's two and secondary.
[19:36] We will make sure that's right so we go to here.
[19:39] Go to aiming.
[19:41] Change this to 2 and make this secondary.
[19:45] All right and so now because I'm on a laptop and this is not a mobile device.
[19:53] I'm going to just remove that condition really quickly and disable that just for testing.
[20:02] Huh.
[20:03] And put this on the mobile control layer.
[20:06] [Music]
[20:08] There we go so now the gun aims in the direction of the joystick.
[20:13] Great.
[20:17] [Music]
[20:43] okay so this will work it's just
[20:47] the problem is that it's fighting two
[20:49] conflicting orders so
[20:54] we will copy these
[20:59] [Music]
[21:00] and disable both of these right now
[21:03] just for testing
[21:05] and there we go now the gun and the
[21:07] player rotate with the joystick
[21:15] because we're using the conditioned
[21:16] joystick pushed in a direction and then
[21:19] using the proper number and joystick
[21:22] name
[21:23] and then the direction
[21:25] so if it's pushing right it's gonna not
[21:27] flip if it's pushing left it will flip
[21:30] just like when the cursor was on one
[21:31] side or the other of the player
[21:34] and now we will use the condition
[21:37] mobile device
[21:45] and again but inverted
[21:47] [Music]
[21:52] all right
[21:54] and then put this here and
[21:57] we are good so if it's not a mobile
[22:00] device it's going to use the cursor's
[22:03] position if it is a mobile device
[22:05] it will rotate towards the joysticks
[22:07] angle
[22:11] and then for the flipping this will
[22:13] happen
[22:14] we do need to change it though so that
[22:19] or
[22:22] two here
[22:25] either the left joystick
[22:27] or Mouse button is down
[22:31] no hold on
[22:34] and
[22:39] okay
[22:40] back to the mobile device thing
[22:43] so if it's not a mobile device this is
[22:45] an and condition
[22:47] if the left Mouse button is pushed down
[22:49] and it's not a mobile device
[22:52] then this will be true
[22:54] this is an ore condition
[22:56] so if that is true or
[23:02] the joystick is pushed down
[23:10] let's try that okay so if it's above
[23:12] zero if the force on the joystick is
[23:14] above zero so it's being moved at all
[23:16] yeah so when I'm clicking anywhere else
[23:18] doesn't work holding the joystick does
[23:21] work
[23:22] so I've got movement and joystick
[23:26] we'll change that back to not a mobile
[23:27] device and we have our controls all set
[23:31] up
[23:32] sorry if it looks a little bit
[23:33] complicated but you need to have
[23:34] separate controls for mobile and not
[23:36] mobile so
[23:39] all right
[23:40] that's the game
[23:42] we'll move this down below the
[23:43] transition so you can't see it when you
[23:45] first start the game
[23:47] and we will set it up so that
[23:50] copy this
[23:57] if it is not a mobile device
[24:02] we will just delete the mobile controls
[24:06] which are movement
[24:10] and aiming
[24:13] so now when I start the game and it's
[24:14] not a mobile device because it's my
[24:16] laptop
[24:17] they're gone and the game plays normally
[24:22] all right
[24:24] and that has been the entire series I'm
[24:27] making a wave defense game if you want
[24:30] to learn some more things about game
[24:31] development using gdevelop check out
[24:34] this playlist or if you want to see some
[24:36] cool g-developed games check out this
[24:39] playlist
[24:39] [Music]
[24:49] thank you
