-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
64 lines (54 loc) · 2.62 KB
/
main.cpp
File metadata and controls
64 lines (54 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "src/scenes/GameScene.cpp"
#include <latebit/core/configuration/Configuration.h>
#include <latebit/core/GameManager.h>
#include <latebit/core/ResourceManager.h>
#include <latebit/utils/Logger.h>
using namespace lb;
int main() {
// A configuration file allows to customize certain aspects of the game
// without recompiling. The path is relative to the binary file.
//
// The configuration is optional, the engine will run with sensible defaults
// otherwise, but if you want to use it, you need to load it before starting
// the game.
Configuration::fromFile("latebit.cfg");
// The GameManager (GM) is the main class of the engine. It is responsible for
// initialising all the subsystems, running the game loop, and cleaning up the
// resources when the game ends.
//
// The startUp() method initializes the engine, without starting the game
// loop.
GM.startUp();
// Load resources
// Resources are managed by the ResourceManager (RM). Below you can see how to
// load sprites and audio files. To retrieve loaded resources, you can use the
// get* methods of the RM.
// latebit supports two types of sprites: text and image.
// Text sprites are in a proprietary format. They are as powerful as images,
// but you can work with them directly in your IDE.
// Image sprites are loaded from 16-colors PNG files. That's the only image
// format latebit supports. If the 16 colors of the image are not in the
// latebit palette, the image will be remapped to latebit colors.
//
// No matter what type of sprite you use, you can use them in the same way and
// they abide by the same rules: they can only display the 16 colors of the
// latebit palette.
RM.loadTextSprite("assets/sprites/fish.lbspr", "fish");
RM.loadTextSprite("assets/sprites/bubbles.lbspr", "bubbles");
RM.loadImageSprite("assets/sprites/logo.png", "logo");
// latebit supports two types audio: music and sound effects.
// Loading them is as simple as loading sprites, except that to hear them you
// need to play() them.
RM.loadMusic("assets/audio/music.lbmus", "music");
RM.loadSound("assets/audio/sound.lbsfx", "sound");
// The WorldManager (WM) is responsible for managing the scenes in the game.
auto scene = WM.createScene<GameScene>("game");
// When you create a scene, you need to activate it to see it on the screen.
// Go check the src/scenes/GameScene.cpp file to see how setup a scene and
// make your first game!
scene->activate();
// The GM will run the game loop until GM.setGameOver(true) is called. Every
// iteration of the loop loosely represents a frame in the game.
GM.run();
return 0;
}