Game Development Reference
In-Depth Information
_gravity = levelData.at("gravity").asInt();
switch (_gravity) {
case kDirectionUp:
_world->SetGravity(b2Vec2(0,FORCE_GRAVITY));
break;
case kDirectionDown:
_world->SetGravity(b2Vec2(0,-FORCE_GRAVITY));
break;
case kDirectionLeft:
_world->SetGravity(b2Vec2(-FORCE_GRAVITY, 0));
break;
case kDirectionRight:
_world->SetGravity(b2Vec2(FORCE_GRAVITY, 0));
break;
}
_player->setSpritePosition(Vec2(
levelData.at("startx").asFloat() * TILE,
levelData.at("starty").asFloat() * TILE
));
_igloo->initIgloo(_gravity, Vec2(
levelData.at("endx").asFloat() * TILE,
levelData.at("endy").asFloat() * TILE
));
4. Inside this same dictionary, we have an array for platforms and an array for grav-
ity switches. These are retrieved like this:
ValueVector platforms =
levelData.at("platforms").asValueVector();
ValueVector switches =
levelData.at("switches").asValueVector();
5. These arrays contain even more dictionaries containing data for the creation and
placement of platforms and gravity switches in each level. This data is passed to
the corresponding Platform and GSwitch classes, and boom—you've got
yourself a level.
Search WWH ::




Custom Search