MCPcopy Create free account
hub / github.com/atraczyk/2d-engine / loadLevel

Method loadLevel

engine/src/world.cpp:24–143  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22}
23
24void World::loadLevel(const char* filename, Camera* camera)
25{
26 printf("Loading level: %s\n", filename);
27
28 level.initializeLevel();
29 enemies.clear();
30
31 string line;
32 ifstream file(resolveResourcePath(filename));
33 istringstream ssf;
34 int done = 0;
35 string layerfile[NUM_LAYERS];
36
37 if (file.is_open())
38 {
39 getline(file, line);
40 if (line.compare(0, 3, "\xEF\xBB\xBF") == 0)
41 line.erase(0, 3);
42 ssf = istringstream(line);
43
44 ssf >> layerfile[0] >> layerfile[1] >> layerfile[2] >> layerfile[3];
45
46 for (int i = 0; i < NUM_LAYERS; i++)
47 {
48 if (layerfile[i] != "null")
49 {
50 switch (i)
51 {
52 case 0:
53 {
54 TileAtlas* farAtlas =
55 (layerfile[1] == "null") ? &game.atlases.abgs
56 : &game.atlases.bgs;
57 level.layer[i].load(layerfile[i].c_str(), farAtlas,
58 camera);
59 break;
60 }
61 case 1:
62 level.layer[i].load(layerfile[i].c_str(),
63 &game.atlases.bgs, camera);
64 break;
65 case 2:
66 case 3:
67 level.layer[i].load(layerfile[i].c_str(),
68 &game.atlases.tiles, camera);
69 break;
70 }
71 }
72 else
73 {
74 level.layer[i].initialize(0, 0, 0, 0, 0, 0, 0, NULL, 0);
75 }
76 }
77
78 getline(file, line);
79 ssf = istringstream(line);
80 ssf >> level.ambientLighting >> level.musicID >> level.reverb;
81

Callers 1

G_loadLevelFunction · 0.80

Calls 8

resolveResourcePathFunction · 0.85
Vector2Class · 0.85
sgnFunction · 0.85
initializeLevelMethod · 0.80
AddMethod · 0.80
WorldRectClass · 0.70
loadMethod · 0.45
initializeMethod · 0.45

Tested by

no test coverage detected