Tying up loose ends

The game is almost complete. There are just a few final adjustments to be made for all the sprites to interact properly.

Engage thrusters

Let's first solve the issue where the enemies don't respond to being hit by the sword or the arrow. What we are lacking is a collision check for these items. This can be easily fixed by the following steps:

  1. We look at the Knight scripts.
  2. In the clone script, we find a collision detection for the explosion block. We can add more checks here.
  3. We expand the existing condition with the or touching <sword>? or touching <arrow>? block.
  4. Then, we switch to the ghost sprite and add the same blocks there.
    Engage thrusters

That fixes our collision problem, but not all the problems. As you may have noticed, the cat isn't actually harmed when touched by either one of the enemies. That's rather unfair, so let's change that as well.

  1. We check the scripts for the cat sprite.
  2. There we also find a collision check for explosion.
  3. We add to this an if touching <Knight>? or touching <Ghost2>? construction.
    Engage thrusters

That's more fair now that the cat will be reset and lose points by anything bad happening to it.

While we're reviewing the points system, let's add to that as well. The cat loses points when touched by an enemy. So it should also gain points on hitting an enemy.

  1. We copy the changePoints function from the cat sprite to both the Knight and Ghost2 sprites to be able to use it there.
  2. At the end of either of the clone scripts, just before deleting the clone, let's reward points for defeating the enemy.
  3. For the Knight sprite, we award 10 points.
  4. For the Ghost sprite, we award 20 points, because it is more difficult to hit the ghost.
    Engage thrusters

Now to prevent the players from uncontrollably pressing the weapon buttons, let's deduct points again for using a weapon. That way, there is a limit to how many times the weapons can be used. It will encourage the player to make a deliberate choice and not get into a mad killing frenzy.

  1. We also copy the changePoints function to both sword and arrow.
  2. In either of the () key pressed scripts, we call the changePoints function, just after we have confirmed the player actually has the item in the inventory.
  3. For each use of an item, we deduct 5 points.
    Engage thrusters

As a final step, we will also reset the items for each new level played. So at each level the player has to collect the items before he/she can use them.

  1. We move to the tileGenerator scripts, as that's where we set most of the variables.
  2. At the top of the list, we add a delete <all> of items block to empty the list.
    Engage thrusters

Test the game and see how many levels you can clear before getting defeated.

Objective complete – mini debriefing

We cleaned up the game and tied all the loose ends together. You'll often find that while developing games, you will try and add new features piece by piece. This often requires some rethinking and later adjustments to the parts of the game that we have already (thought were) finished.

Therefore, it's a good idea to keep the way you write games clear and consistent. Set variables at the start of a script. It's even better if you can collect them in the Stage object. Using functions also helps to separate different pieces of functionality.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.136.63