Creating a world¶
This page will guide you through the process of creating a world using the BBOC engine.
The world is a major part of your game, it contains the camera and all the actors that will be displayed on the screen. The world is responsible for updating and rendering all the actors in the game.
Creating a World¶
To create a world, you need to create a new class that inherits from the World class. The World class is an abstract class that provides the basic functionality for a world.
Here is an example of a simple world class:
class WorldOne : public BBOC::World {
public:
WorldOne();
void updateState(double delta) override;
private:
double _delta{0.};
};
In this example, we have created a new class called WorldOne that inherits from the World class. We have also added a private member variable _delta that will be used to store the delta time between frames.
Implementing the World¶
To implement the world, you need to define the updateState() method. This method is called every frame and is responsible for updating the state of the world.
Here is an example of the updateState() method:
void WorldOne::updateState(double delta) {
this->_delta += delta;
if (this->_delta < 100.)
return;
this->_delta = 0.;
#if defined(BBOC_SERVER)
this->getCamera().setPosition(this->getCamera().getPosition() + BBOC::Vector2d(1., 0.));
#endif
}
In this example, we have implemented the updateState() method to move the camera to the right by 1 unit every 100 frames. We have also added a preprocessor directive to only run this code on the server because in our game the server has autority as its a game engine working in multiplayers.
Adding Actors to the World¶
To add actors to the world, you need to create a new actor and add it to the world using the addActor() method.
Here is an example of how to add an actor to the world:
auto actor = std::make_shared<BBOC::Actor>();
this->addActor(actor);
In this example, we have created a new actor and added it to the world.
Note
Refer to the Creating an Actor page for more information on how to create an actor.
Running the World¶
Note
The world is automatically run by the engine, you do not need to call any methods to run the world. Refer to the Create the Game page for more information on how to create the game.