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

Chapter 10

AcceptCoopPartner: This is used to tell the client that it is free to spawn another local plane. It takes a sf::Int32 value and two float values with the identifier of the aircraft to be spawned and its initial position.

SpawnEnemy: This takes one sf::Int32 value with the type of the aircraft as declared in Aircraft class and two float values indicating where the enemy should spawn.

SpawnPickup: Similar to SpawnEnemy, but applies for the spawn of a pickup in the world. The first sf::Int32 value to be packed is declared inside the

Pickup class.

UpdateClientState: This takes one float value with the current scrolling of the world in the server, and then a sf::Int32 value with the aircraft count. For each aircraft, it packs one sf::Int32 value with the identifier and two float values for position.

MissionSuccess: This has no arguments. It is simply used to inform the client that the game is over.

Understanding the ticks and updates

In the pseudo-code, we referred to the updateLogic(), now let's take a look at what it actually does:

while (stepTime >= stepInterval)

{

mBattleFieldRect.top += mBattleFieldScrollSpeed * stepInterval.asSeconds();

stepTime -= stepInterval;

}

Comments are probably not needed, as fixed time steps were already explained in Chapter 1, Making a Game Tick. All that is being actually updated in here is the mBattleFieldRect variable, which scrolls upwards into the end of the level—an

exact replica of what happens in the client with the world view.

Simple enough, let's now look at a more important code, the ticks, which we use to maximize the synchrony between both server and client. Let's use some pseudo-code:

while (tickTime >= tickInterval)

{

updateClientState();

checkMissionEnd();

spawnEnemies();

spawnPickups;

tickTime -= tickInterval;

}

[ 257 ]

www.it-ebooks.info

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