Go to our browserquest-images -> img -> 2 folder, and we'll pick an enemy from there. For now, let's use a rat as an enemy because it looks like it's easy to kill and fits for our first encounter. So, open our project again if you haven't already and insert a new Sprite object called "rat". We'll use the rat.png file from the folder we just opened, import the frames from sprite strip like we usually do. For this spritesheet there are 6 horizontal cells, and 10 vertical cells.
After you split it correctly you'll get a few animations divided like this:
- Idle / default animation: one frame, the first frame on first row
- Destroyed animation: three frames, starting from second frame on first row
- Attack right / left animation: five frames, second row
- Walk right / left animation: four frames, one from second row and three from the third row
- Sniffing right / left animation: two frames, fourth row
- Attacking up animation: four frames, fifth row
- Walking up animation: four frames, sixth row
- Sniffing up animation: four animations, seventh row
- Attacking down animation: four frames, eight row
- Walking down animation: four frames, ninth row
- Sniffing down animation: four frames, tenth row
Enemy's animations |
- Default animation: speed 5, no loop
- Destroyed animation: speed 9, no loop
- AttackRight animation: speed 15, no loop
- WalkRight animation: speed 15, loop
- SniffingRight animation: speed 5, no loop, repeat count 3
- AttackUp animation: speed 12, no loop
- WalkUp animation: speed 12, loop
- SniffUp animation: speed 4, no loop, repeat count 3
- AttackDown animation: speed 12, no loop
- WalkDown animation: speed 12, loop
- SniffDown animation: speed 4, no loop, repeat count 3
Add the 8 Direction behavior to the rat,and change both the "Set angle" and "Default controls" to no. Then we'll switch to the event sheet, before we move the rat it must first make a random decision about where to go: is it to go left, up, right, or down? Construct 2 has an expression to randomly select a set of options, called "choose". For now add a new event to compare the rat's playing animation, if it's the Default animation then we'll start randomly choosing a direction.