summary refs log tree commit diff stats
path: root/src/game.cpp
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2021-02-09 22:28:27 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2021-02-09 22:28:27 -0500
commit5931470800c43260f600303d1231dbaf586f26fc (patch)
treeaaaa30ee6bae81c1badc8b70d2fbdce33a058d5a /src/game.cpp
parent315ca2fb388f790791c9ce372cf44e00d51e0e7f (diff)
downloadtanetane-5931470800c43260f600303d1231dbaf586f26fc.tar.gz
tanetane-5931470800c43260f600303d1231dbaf586f26fc.tar.bz2
tanetane-5931470800c43260f600303d1231dbaf586f26fc.zip
Map changing!
Also removed some dependencies on the Renderer. More changes need to be made. Fading to black before the change would be good. And making sure the characters are facing the right direction. Maybe that code shouldn't live in Game, either. Later we also want to combine the tilesets for these two maps (and any others that are on Tanetane).
Diffstat (limited to 'src/game.cpp')
-rw-r--r--src/game.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/game.cpp b/src/game.cpp index 447b62a..861e8ee 100644 --- a/src/game.cpp +++ b/src/game.cpp
@@ -1,4 +1,8 @@
1#include "game.h" 1#include "game.h"
2#include "transform_system.h"
3#include "animation_system.h"
4#include "character_system.h"
5#include "camera_system.h"
2 6
3int Game::emplaceSprite(std::string alias) { 7int Game::emplaceSprite(std::string alias) {
4 int id = sprites_.size(); 8 int id = sprites_.size();
@@ -7,3 +11,59 @@ int Game::emplaceSprite(std::string alias) {
7 spritesByAlias_[alias] = id; 11 spritesByAlias_[alias] = id;
8 return id; 12 return id;
9} 13}
14
15void Game::clearSprites() {
16 sprites_.clear();
17 spriteIds_.clear();
18 spritesByAlias_.clear();
19
20 for (std::unique_ptr<System>& system : systems_) {
21 system->clearSpriteCache();
22 }
23}
24
25void Game::loadMap(std::string filename, std::string warpPoint) {
26 clearSprites();
27
28 map_ = std::make_unique<Map>(filename);
29
30 int lucasSprite = emplaceSprite("lucas");
31 getSystem<TransformSystem>().initSprite(lucasSprite, map_->getWarpPoint(warpPoint));
32 getSystem<TransformSystem>().setUpCollision(lucasSprite, {-8, -8}, {12, 8}, true);
33 getSystem<AnimationSystem>().initSprite(lucasSprite, "../res/sprites/lucas_anim.txt");
34 getSprite(lucasSprite).controllable = true;
35 getSystem<CharacterSystem>().initSprite(lucasSprite);
36
37 int kumaSprite = emplaceSprite("kuma");
38 getSystem<TransformSystem>().initSprite(kumaSprite, {32, 32});
39 getSystem<AnimationSystem>().initSprite(kumaSprite, "../res/sprites/kuma_anim.txt");
40 getSystem<CharacterSystem>().addSpriteToParty(lucasSprite, kumaSprite);
41
42 int dusterSprite = emplaceSprite("duster");
43 getSystem<TransformSystem>().initSprite(dusterSprite, {32, 32});
44 getSystem<AnimationSystem>().initSprite(dusterSprite, "../res/sprites/duster_anim.txt");
45 getSystem<CharacterSystem>().addSpriteToParty(lucasSprite, dusterSprite);
46
47 int boneySprite = emplaceSprite("boney");
48 getSystem<TransformSystem>().initSprite(boneySprite, {32, 32});
49 getSystem<AnimationSystem>().initSprite(boneySprite, "../res/sprites/boney_anim.txt");
50 getSystem<CharacterSystem>().addSpriteToParty(lucasSprite, boneySprite);
51
52 for (const Prototype& p : map_->getPrototypes()) {
53 int spriteId = emplaceSprite(p.name);
54 getSystem<TransformSystem>().initSprite(spriteId, p.pos);
55 getSystem<TransformSystem>().setUpCollision(spriteId, p.collisionOffset, p.collisionSize, true);
56 getSystem<AnimationSystem>().initSprite(spriteId, p.animationFilename);
57 getSprite(spriteId).interactionScript = p.interactionScript;
58 }
59
60 for (const Trigger& t : map_->getTriggers()) {
61 int spriteId = emplaceSprite(t.name);
62 getSystem<TransformSystem>().initSprite(spriteId, t.pos);
63 getSystem<TransformSystem>().setUpCollision(spriteId, {0, 0}, t.size, false);
64 getSprite(spriteId).walkthroughScript = t.script;
65 }
66
67 getSystem<CameraSystem>().setFollowingSprite(lucasSprite);
68 getSystem<CameraSystem>().unlockCamera();
69}