IME Documentation

Welcome

Welcome to the official IME documentation. Here you will find a detailed view of all the classes and functions.

Short example

IME is state based, which means that the game flow is controlled by pushing and popping game states at appropriate times. Here is an example, demonstrating how to start the engine. This example will display a knight patrolling a grid kingdom to protect it from scavengers and trolls

You need to do four things to get started:

  1. Define a state/scene
  2. Create engine settings/configurations (Not necessary)
  3. Instantiate the engine and initialize it
  4. Push initial state and start the engine
#include <IME/IME.h>
// Step 1: Define a state
// Define the behaviour of the game state by overriding the scene methods.
// These functions will be called by the engine at specific times. Scene
// methods are overridden by a need to use case, however the 'onEnter'
// function must always be overridden
class Demo : public ime::Scene {
public:
void onEnter() override {
// Lets create our knight object, lets call him 'destroyerOfMen"
auto knight = ime::GameObject::create(*this);
knight->setTag("destroyerOfMen");
knight->getSprite().setTexture("knight.png");
knight->getSprite().scale(0.20f, 0.20f);
gameObjects().add(knight);
// Enable physics so that our knight can move around the grid, otherwise he'll be easily ambushed
auto gravity = ime::Vector2f{0, 9.8f};
createWorld(gravity);
physicsBody->setLinearVelocity(ime::Vector2f{60.0f, 60.0f});
knight->attachRigidBody(physicsBody);
// We now create the grid in which the knight will patrol in
createTilemap(40, 40); // The size of each grid block will be 20x20
tilemap().construct({10, 10}, '.'); // Create a 15x20 grid
tilemap().addChild(knight, ime::Index{1, 1});
// We want our knight to move in the direction we want using the keyboard
auto gridMover = std::make_shared<ime::KeyboardGridMover>(tilemap());
gridMover->setTarget(knight);
gridMover->setMovementRestriction(ime::GridMover::MoveRestriction::NonDiagonal);
gridMovers().addObject(gridMover);
// And just like that, our kingdom is protected!
// Lets play some medieval music for our knight to Keep his spirit up
audio().play(ime::audio::Type::Music, "medievalTheme.wav");
// Lets quit the game when Esc key is pressed
input().onKeyUp([this](ime::Key key) {
if (key == ime::Key::Escape)
engine().quit();
});
// Startle knight when we press S key
input().onKeyUp([this](ime::Key key) {
if (key == ime::Key::S)
gameObjects().findByTag("destroyerOfMen")->getSprite()
.getAnimator().startAnimation("startled");
});
}
};
int main()
{
// Step 2: Create engine configurations (They can also be defined in a text
// file on the disk and loaded by providing the filename to the engines
// constructor)
//
// All these configurations defaults so they can be left undefined.
// However it's better to specify your own settings. You can add you
// own entries if you wish to do so
PropertyContainer settings;
settings.addProperty({"WINDOW_TITLE", std::string("Demo")});
settings.addProperty({"WINDOW_WIDTH", 800});
settings.addProperty({"WINDOW_HEIGHT", 700});
settings.addProperty({"WINDOW_ICON", std::string("assets/bitmap/icon.png")});
settings.addProperty({"FULLSCREEN", false});
settings.addProperty({"FPS_LIMIT", 60});
settings.addProperty({"V_SYNC", true});
settings.addProperty({"FONTS_DIR", std::string("assets/fonts/")});
settings.addProperty({"IMAGES_DIR", std::string("assets/textures/")});
settings.addProperty({"TEXTURES_DIR", std::string("assets/textures/")});
settings.addProperty({"SOUND_EFFECTS_DIR", std::string("assets/soundEffects/")});
settings.addProperty({"MUSIC_DIR", std::string("assets/music/")});
// Step 3: Create the engine and initialize it
auto engine = ime::Engine("Demo", settings);
engine.initialize();
// Step 4: Push the initial state and run the engine
engine.pushScene(std::make_shared<Demo>());
engine.run();
return EXIT_SUCCESS;
}
ime::Scene
Abstract base class for game scenes.
Definition: Scene.h:79
ime::GameObjectContainer::add
void add(GameObject::Ptr gameObject, int renderOrder=0u, const std::string &renderLayer="default")
Add a game object to the container.
ime::audio::AudioManager::play
void play(Type audioType, const std::string &filename, bool isLooped=false)
Play an audio file.
ime::Scene::input
input::InputManager & input()
Get the scenes input manager.
ime::TileMap::addChild
bool addChild(GameObject::Ptr child, const Index &index, bool assignLayer=true)
Add an entity to the tilemap.
ime::Scene::tilemap
TileMap & tilemap()
Get the scene Tilemap.
ime::Body::Type::Kinematic
@ Kinematic
Zero mass, non-zero velocity set by user, moved by physics engine.
ime::Scene::engine
Engine & engine() const
Get a reference to the game engine.
ime::GridMover::MoveRestriction::NonDiagonal
@ NonDiagonal
Target can only move non-diagonally (W, N, E, S)
ime::World::createBody
Body::Ptr createBody(Body::Type type=Body::Type::Static)
Create a rigid body.
ime::input::InputManager::onKeyUp
int onKeyUp(Callback< Keyboard::Key > callback)
Add an event listener to a key up event.
ime::Scene::physics
World & physics()
Get the physics simulation.
ime::input::Keyboard::Key
Key
keyboard key codes
Definition: Keyboard.h:57
ime::Index
Represents a position of a tile in the tilemap.
Definition: Index.h:35
ime::ObjectContainer::addObject
void addObject(ObjectPtr object, const std::string &group="none")
Add an object to the container.
ime::TileMap::construct
void construct(Vector2u size, char id)
Construct a tilemap.
ime::Engine
Runs the main loop.
Definition: Engine.h:46
ime::Scene::gameObjects
GameObjectContainer & gameObjects()
Get the scene game object container.
ime::Vector2< float >
ime::audio::Type::Music
@ Music
Music.
ime::Scene::gridMovers
GridMoverContainer & gridMovers()
Get the scenes grid mover container.
ime::Scene::audio
audio::AudioManager & audio()
Get the scenes audio manager.
ime::input::Keyboard::Key::Escape
@ Escape
The Escape key.
ime::Scene::createTilemap
void createTilemap(unsigned int tileWidth, unsigned int tileHeight)
Create tilemap instance.
ime::Scene::onEnter
virtual void onEnter()=0
Enter the scene.
ime::Scene::createWorld
void createWorld(Vector2f gravity)
Create a physics simulation.
ime::GameObject::create
static GameObject::Ptr create(Scene &scene, Type type=Type::Unknown)
Create a game object.
ime::input::Keyboard::Key::S
@ S
The S key.