Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
SFML Game Development.pdf
Скачиваний:
220
Добавлен:
28.03.2016
Размер:
4 Мб
Скачать
☆

Every Pixel Counts – Adding Visual Effects

We cannot simply check for isDestroyed(), because we have no way of distinguishing between airplanes that are shot down or that leave the screen. We only want the former to explode—hence the Boolean variable mShowExplosion.

Also we have to remember that the animation must be updated or else it won't progress. The return statement prevents destroyed aircraft from further logic processing:

if (isDestroyed())

{

checkPickupDrop(commands);

mExplosion.update(dt);

return;

}

This would run perfectly, except that right now the aircraft would be removed before the explosion would even be shown. We have to make sure the entity stays alive until the animation is over. We mark an aircraft for removal, as soon as it

is destroyed, and either no explosion is shown (when it leaves the screen) or the explosion is finished:

bool Aircraft::isMarkedForRemoval() const

{

return isDestroyed()

&& (mExplosion.isFinished() || !mShowExplosion);

}

And now we finally have our properly exploding planes, which give much more immersion to the game.

The Eagle has rolled!

It would be nice if the player's aircraft, the Eagle, turned around its roll axis (from nose to tail) when moving sideways. If the player moves left or right, the plane's inclination will change. Here, we don't need a full-fledged animation. It is enough to check whether the X velocity is negative (flying left) or positive (flying right), and to set the texture rect accordingly.

In the aircraft data table, we store for each plane a Boolean denoting whether it supports a roll animation. We assume that if it does, there are two texture rectangles located to right of the original rect, with the same size.

void Aircraft::updateRollAnimation()

{

if (Table[mType].hasRollAnimation)

[ 204 ]

www.it-ebooks.info

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]