Saturday, November 22, 2008

Dog Ticks Affect Humans

Dev - A smarter enemy

Hi everyone!
I finally decided to write an article after a long absence. So I speak here of a new enemy that I created for my game and has the distinction of not falling off a platform when it reaches the edge. He prefers to make a U-turn to chase you better. Here's my reasoning:

My enemy is moving normally. it detects if a soil is beneath him and he acts accordingly: it stops falling. Now, think Why this enemy drops it? Answer: because there is a serious and there is no floor beneath him. We can predict whether or not the enemy will fall to the next execution of code just to test, in addition to the ground below it, whoever is in front. The result is a pseudo code like:
if (soldevant = 1) enemy-> speed *=- 1;

.
It detects the first floor to the left of sprite with this:


(GetTile (fix_norm (bady-> x) -2, fix_norm (bady-> y) + bady-> height) == 0)

then left with:


(GetTile (fix_norm (bady-> x) + bady-> weight, x_norm (bady-> y ) + bady-> height) == 0)
We realize that by testing these collisions are continuously tested: gold, we only need to test if the enemy is moving in the right direction. Thus, we add the condition:


((GetTile (fix_norm (bady-> x) -2, fix_norm (bady-> y) + bady-> height) == 0) & & (bady-> variables
and


((GetTile (fix_norm (bady-> x) + bady-> weight, fix_norm (bady-> y) + bady-> height) == 0) & & bady-> variables> 0))
I said that bady-> variables is the speed of the character.

Voila, we now have an enemy who does not fall platforms.

<0)