summary refs log tree commit diff stats
path: root/src/sprite.cpp
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2021-01-31 12:08:02 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2021-01-31 12:08:02 -0500
commit908f792db6fdc04fde4b48e8873767edd5d59cea (patch)
treee1ec1659bfe9d7389d1dbc52aaa7045fdb652279 /src/sprite.cpp
parentf648c6776e0a1c5e1e3f6fcf9c81fefcb67a0c3e (diff)
downloadtanetane-908f792db6fdc04fde4b48e8873767edd5d59cea.tar.gz
tanetane-908f792db6fdc04fde4b48e8873767edd5d59cea.tar.bz2
tanetane-908f792db6fdc04fde4b48e8873767edd5d59cea.zip
Made use of new sprite sheet data!
Diffstat (limited to 'src/sprite.cpp')
-rw-r--r--src/sprite.cpp45
1 files changed, 42 insertions, 3 deletions
diff --git a/src/sprite.cpp b/src/sprite.cpp index c52807a..b84f4ce 100644 --- a/src/sprite.cpp +++ b/src/sprite.cpp
@@ -12,14 +12,53 @@ Sprite::Sprite(std::string_view filename, Renderer& renderer) {
12 } 12 }
13 13
14 char ch; 14 char ch;
15 std::string line;
15 16
16 std::string imagename; 17 std::string imagename;
17 datafile >> imagename; 18 datafile >> imagename;
18 textureId_ = renderer.loadImageFromFile(imagename); 19 textureId_ = renderer.loadImageFromFile(imagename);
19 20
20 datafile >> size_.w(); 21 std::string framefilename;
21 datafile >> ch; //, 22 datafile >> framefilename;
22 datafile >> size_.h(); 23
24 std::ifstream framefile(framefilename);
25 if (!framefile.is_open()) {
26 throw std::invalid_argument("Could not find frame datafile: " + framefilename);
27 }
28
29 vec2i cellSize;
30 framefile >> cellSize.w();
31 framefile >> ch; //,
32 framefile >> cellSize.h();
33 std::getline(framefile, line); // cell size
34
35 int framesPerRow;
36 framefile >> framesPerRow;
37 std::getline(framefile, line); // frames per row
38
39 int numFrames;
40 framefile >> numFrames;
41 std::getline(framefile, line); // frames
42 std::getline(framefile, line); // blank
43
44 for (int i=0; i<numFrames; i++) {
45 SpriteFrame f;
46 framefile >> f.size.w();
47 framefile >> ch; //,
48 framefile >> f.size.h();
49 framefile >> ch; //,
50 framefile >> f.center.x();
51 framefile >> ch; //,
52 framefile >> f.center.y();
53 std::getline(framefile, line); // blank
54
55 f.srcRect.x = (i % framesPerRow) * cellSize.w();
56 f.srcRect.y = (i / framesPerRow) * cellSize.h();
57 f.srcRect.w = f.size.w();
58 f.srcRect.h = f.size.h();
59
60 frames_.push_back(std::move(f));
61 }
23 62
24 std::string animLine; 63 std::string animLine;
25 std::getline(datafile, animLine); // blank 64 std::getline(datafile, animLine); // blank