# 200th day of development. New enemies

This week I spent 5 hours fighting with corona’s sprites and physics. Lucky for me — they have an “idiot-proof system”, so I couldn’t break them and had to do things the right way.

The main problem was that there are several thing that can happen after a hero hits an enemy with a bullet.

Option 1. The element of the bullet can be the same as the element of the enemy — in which case the enemy goes kaboom, and the hero gets a coin.

Option 2. The elements of the bullet and the enemy are different, and the hero has the right element — but just didn’t use it for some reason. In this case nothing happens, the enemy is still alive and well.

Option 3. The elements of the bullet and the enemy are different, and the hero doesn’t have the element necessary to kill the enemy at all. In this case we need to change enemy’s element to make it “killable”.

In the previous version of the game, this problem was solved by using “shields” — instead of changing the element of the enemy itself, I added a shield and kept changing its element until the hero hit it with the right one.

That worked from the logical point of view, but it was a disaster from the gameplay point of view.

To instantly let the player know that this enemy belongs to a fire element, the enemy was of red colour. But then I generated a shield, and the shield would have a water element, so it was blue. As a result a clear message “identify the element by its colour” was lost — because there was a red enemy, with a blue shield around him.

So in the new version I decided to ged rid of shields, and instead of changing the colour of a shield “bubble” around the enemy — change the enemy’s image itself.

The problem that I ran into is that Corona doesn’t allow you to :swipeSprite()

So I went the most logical way (at least I thought I did).

On the hero’s bullet collision… If bullet’s element != enemy’s element… If hero doesn’t have the enemy’s element… Destroy the old enemy and Load a new enemy in it’s place.

It sounded fine to me, so I worked on that for a while.

The problem is — all enemies are pre-created. They are loaded at the level creation, and then they are configured with a random element and lots of other stuff that’s used for statistics etc. They have their coordinates, transitions and animations.

And if you destroy an enemy, and load another at runtime — it raises all kinds of problems with enemies’ metadata.

After 5 hours, I gave up and went to read documentation (reading documentation is always the last resort for me. Don’t ask…)

And apparently — it was all for nothing. Because Corona gives you a simple solution. You can not swipe a sprite itself, but you can replace an imageSheet in the animation data.

So all you actually need is to create a set of animations with different imageSheets. And swipe them all you want on collision with hero’s bullet. This way enemy’s information and physics created when level was loaded are still intact — you just change the imageSeet and enemy’s element.

Would be nice to know that 5 hours earlier, but that’s how I learn things. The hard way.

Also here are enemies’ animations. I think they are funny 8)