summary refs log tree commit diff stats
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
parentf648c6776e0a1c5e1e3f6fcf9c81fefcb67a0c3e (diff)
downloadtanetane-908f792db6fdc04fde4b48e8873767edd5d59cea.tar.gz
tanetane-908f792db6fdc04fde4b48e8873767edd5d59cea.tar.bz2
tanetane-908f792db6fdc04fde4b48e8873767edd5d59cea.zip
Made use of new sprite sheet data!
-rw-r--r--res/lucas.pngbin10009 -> 90846 bytes
-rw-r--r--res/lucas_anim.txt66
-rw-r--r--res/lucas_frames.txt403
-rw-r--r--src/main.cpp2
-rw-r--r--src/renderer.cpp5
-rw-r--r--src/sprite.cpp45
-rw-r--r--src/sprite.h14
7 files changed, 491 insertions, 44 deletions
diff --git a/res/lucas.png b/res/lucas.png index c059f96..dd053e5 100644 --- a/res/lucas.png +++ b/res/lucas.png
Binary files differ
diff --git a/res/lucas_anim.txt b/res/lucas_anim.txt index 19b1d67..daef503 100644 --- a/res/lucas_anim.txt +++ b/res/lucas_anim.txt
@@ -1,34 +1,34 @@
1../res/lucas.png 1../res/lucas.png
217,26 2../res/lucas_frames.txt
3still[down]: 1 3still[down]: 0
4still[left]: 4 4still[down_left]: 1
5still[down_left]: 7 5still[left]: 2
6still[down_right]: 10 6still[up_left]: 3
7still[up]: 13 7still[up]: 4
8still[right]: 16 8still[up_right]: 5
9still[up_left]: 19 9still[right]: 6
10still[up_right]: 22 10still[down_right]: 7
11walk[down]: 0,1,2 11walk[down]: 40,0,48
12walk[left]: 3,4,5 12walk[down_left]: 41,1,49
13walk[down_left]: 6,7,8 13walk[left]: 42,2,50
14walk[down_right]: 9,10,11 14walk[up_left]: 43,3,51
15walk[up]: 12,13,14 15walk[up]: 44,4,52
16walk[right]: 15,16,17 16walk[up_right]: 45,5,53
17walk[up_left]: 18,19,20 17walk[right]: 46,6,54
18walk[up_right]: 21,22,23 18walk[down_right]: 47,7,55
19crouch[down]: 24 19crouch[down]: 107
20crouch[down_left]: 25 20crouch[down_left]: 108
21crouch[left]: 26 21crouch[left]: 109
22crouch[up_left]: 27 22crouch[up_left]: 110
23crouch[up]: 28 23crouch[up]: 111
24crouch[up_right]: 29 24crouch[up_right]: 112
25crouch[right]: 30 25crouch[right]: 113
26crouch[down_right]: 31 26crouch[down_right]: 114
27run[down]: 32,33,34,35 27run[down]: 67,75,83,91
28run[right]: 36,37,38,39 28run[down_left]: 68,76,84,92
29run[down_right]: 40,41,42,43 29run[left]: 69,77,85,93
30run[up_right]: 44,45,46,47 30run[up_left]: 70,78,86,94
31run[up]: 48,49,50,51 31run[up]: 71,79,87,95
32run[left]: 52,53,54,55 32run[up_right]: 72,80,88,96
33run[up_left]: 56,57,58,59 33run[right]: 73,81,89,97
34run[down_left]: 60,61,62,63 \ No newline at end of file 34run[down_right]: 74,82,90,98 \ No newline at end of file
diff --git a/res/lucas_frames.txt b/res/lucas_frames.txt new file mode 100644 index 0000000..e64d1e1 --- /dev/null +++ b/res/lucas_frames.txt
@@ -0,0 +1,403 @@
132,64 cell size
210 frames per row
3399 frames
4
516,32,8,32
616,32,8,32
716,32,8,32
816,32,8,32
916,32,9,32
1016,32,9,32
1116,32,9,32
1216,32,9,32
1316,32,8,32
1416,32,8,32
1516,32,8,32
1616,32,8,32
1716,32,9,32
1816,32,9,32
1916,32,9,32
2016,32,9,32
2116,24,8,24
2216,24,9,24
2317,32,10,32
2416,24,8,24
2516,24,8,24
2616,24,9,24
2717,32,7,32
2816,24,8,24
2916,24,8,24
3016,24,9,24
3117,24,10,24
3216,24,8,24
3316,24,9,24
3416,24,9,24
3517,24,7,24
3616,24,8,24
3717,24,9,24
3816,24,9,24
3917,24,10,24
4016,24,8,24
4117,24,9,24
4216,24,9,24
4317,24,7,24
4416,24,8,24
4516,24,8,24
4616,24,8,24
4716,24,8,24
4816,24,8,24
4916,24,9,24
5016,24,9,24
5116,24,9,24
5216,24,9,24
5317,24,9,24
5416,24,8,24
5516,24,8,24
5616,24,8,24
5717,24,9,24
5816,24,9,24
5916,24,9,24
6016,24,9,24
6116,32,8,32
6216,32,8,32
6316,32,8,32
6416,32,8,32
6517,32,9,32
6616,32,9,32
6716,32,9,32
6816,32,9,32
6916,24,8,24
7016,24,8,24
7116,24,7,24
7216,32,8,32
7316,32,8,32
7416,32,8,32
7516,32,8,32
7616,32,8,32
7716,32,8,32
7816,32,8,32
7916,32,8,32
8016,24,8,24
8116,24,8,24
8216,24,8,24
8316,24,8,24
8416,24,8,24
8516,24,8,24
8616,24,8,24
8716,24,8,24
8817,32,9,32
8916,32,8,32
9016,32,8,32
9116,32,8,32
9217,32,8,32
9316,32,8,32
9416,32,8,32
9516,32,8,32
9617,24,9,24
9716,24,8,24
9816,24,8,24
9916,24,8,24
10017,24,8,24
10116,24,8,24
10216,24,8,24
10316,24,8,24
10416,24,8,24
10516,24,8,24
10616,24,8,24
10716,24,8,24
10816,24,8,24
10916,24,8,24
11016,24,8,24
11116,24,8,24
11216,24,8,24
11316,24,8,24
11416,24,8,24
11516,24,8,24
11616,24,8,24
11716,24,8,24
11816,24,8,24
11916,24,8,24
12016,24,8,24
12132,32,16,32
12232,32,16,32
12332,32,16,32
12432,32,16,32
12532,24,16,24
12632,24,16,24
12716,24,8,24
12816,32,8,33
12916,32,8,32
13016,32,8,31
13116,32,8,33
13216,32,8,32
13316,32,8,31
13417,32,9,33
13517,32,9,32
13617,32,9,31
13717,32,12,14
13817,32,12,14
13916,32,9,15
14016,32,9,15
14116,32,5,15
14216,32,5,15
14316,32,5,15
14416,32,5,15
14516,32,3,16
14616,32,3,16
14716,32,4,16
14816,32,4,16
14916,32,6,18
15016,32,6,18
15116,32,8,18
15216,32,8,18
15316,32,8,20
15416,32,8,20
15516,32,10,16
15616,32,10,16
15732,24,16,6
15832,24,20,10
15932,16,26,8
16032,24,22,21
16116,32,8,25
16232,24,10,21
16332,16,6,10
16432,24,12,10
16516,32,9,32
16632,32,17,32
16732,24,17,24
16816,24,9,24
16932,32,17,32
17017,32,9,32
17132,32,17,32
17216,32,8,29
17316,32,8,29
17416,32,8,29
17516,32,8,29
17616,24,8,21
17716,24,8,21
17816,32,8,29
17916,32,8,29
18016,32,8,29
18116,32,8,29
18216,32,8,29
18316,32,8,29
18416,32,8,29
18516,32,8,29
18616,32,8,29
18732,32,16,32
18832,32,16,29
18932,32,16,29
19032,32,16,29
19132,32,16,29
19232,32,16,32
19332,32,16,32
19416,32,8,32
19516,32,8,32
19616,32,8,32
19716,32,9,32
19816,32,9,32
19916,32,9,35
20016,32,9,35
20116,32,6,36
20216,32,6,36
20316,32,2,36
20416,32,2,36
20516,32,2,36
20616,32,2,36
20716,32,0,37
20816,32,0,37
20916,32,1,37
21016,32,1,37
21116,32,3,39
21216,32,3,39
21316,32,5,39
21416,32,5,39
21516,32,5,41
21616,32,5,41
21716,32,7,37
21816,32,7,37
21916,32,4,14
22016,32,4,14
22116,32,7,15
22216,32,7,15
22316,32,11,15
22416,32,11,15
22516,32,11,15
22616,32,11,15
22716,32,13,16
22816,32,13,16
22916,32,12,16
23016,32,12,16
23116,32,10,18
23216,32,10,18
23316,32,8,18
23416,32,8,18
23516,32,8,20
23616,32,8,20
23716,32,6,16
23816,32,6,16
23916,32,9,32
24016,32,8,32
24116,32,8,32
24216,32,8,32
24316,32,8,32
24432,16,16,16
24516,32,10,28
24616,32,7,32
24716,32,8,32
24832,32,16,32
24932,32,16,32
25016,32,9,32
25132,32,9,32
25232,32,17,32
25332,32,17,32
25432,32,17,32
25516,32,8,32
25616,32,8,32
25716,32,9,32
25816,32,9,32
25916,32,8,32
26016,32,8,32
26116,32,8,32
26216,32,8,31
26316,32,8,32
26417,39,9,40
26517,54,9,56
26617,53,9,55
26717,64,9,70
26818,63,6,69
26917,64,7,70
27018,64,7,70
27117,64,9,70
27216,64,8,70
27317,63,9,69
27418,64,11,70
27516,63,9,68
27617,64,11,70
27716,63,12,69
27817,39,9,40
27917,38,9,39
28017,37,9,37
28116,40,8,40
28216,37,8,37
28317,53,9,77
28417,45,9,83
28517,36,9,86
28616,32,9,87
28716,23,8,86
28832,24,16,89
28917,24,8,94
29032,32,16,101
29117,24,8,95
29232,32,16,100
29332,24,17,89
29432,24,17,85
29532,24,17,79
29632,18,19,65
29732,16,19,60
29832,16,18,60
29932,16,18,15
30032,24,14,22
30116,24,8,24
30216,24,9,23
30316,24,10,24
30416,32,8,32
30516,32,8,32
30616,32,8,32
30716,24,8,24
30816,24,8,24
30918,32,11,32
31017,24,10,24
31118,32,11,32
31217,24,10,24
31316,32,11,32
31417,24,11,24
31516,32,11,32
31617,24,11,24
31716,32,13,32
31816,32,15,32
31916,32,17,33
32016,32,19,33
32117,24,21,26
32217,24,23,26
32317,24,25,27
32417,24,27,28
32516,32,29,36
32616,32,31,37
32716,32,33,38
32816,32,35,39
32916,32,37,39
33016,32,39,38
33116,32,41,37
33216,32,43,36
33316,32,43,35
33416,32,45,34
33516,32,46,33
33616,32,48,32
33716,32,50,30
33816,32,52,28
33916,32,53,25
34016,32,54,22
34116,32,55,20
34216,32,56,17
34317,32,57,11
34417,32,57,6
34517,32,59,1
34616,32,8,32
34716,32,8,32
34816,32,8,32
34916,32,8,32
35016,32,8,32
35116,32,8,32
35216,32,8,32
35316,32,8,32
35416,24,8,24
35516,32,8,32
35632,32,16,32
35732,32,16,32
35832,32,16,32
35932,32,16,32
36032,32,16,32
3618,8,4,8
3628,8,4,8
3638,8,3,8
36416,32,8,32
36532,32,16,32
36632,32,16,32
36732,32,16,32
36816,24,8,18
36916,24,8,18
37016,24,8,18
37116,24,8,18
37216,24,8,18
37316,32,8,26
37416,32,8,26
37516,32,8,26
37616,32,8,26
37716,32,8,26
37816,32,8,26
37916,32,8,26
38016,32,8,26
38116,32,8,26
38232,32,16,26
38332,32,16,26
38432,32,16,26
38532,32,16,26
38632,32,16,26
38732,32,16,26
38832,32,16,26
38916,32,8,26
39032,16,16,12
39116,32,8,32
39216,32,9,32
39317,32,8,32
39416,24,10,26
39516,24,10,26
39616,24,11,26
39716,24,11,26
39816,31,10,33
39916,32,9,34
40016,32,8,34
40116,24,9,25
40216,24,9,24
40316,32,8,32
diff --git a/src/main.cpp b/src/main.cpp index f9db18d..65b322e 100644 --- a/src/main.cpp +++ b/src/main.cpp
@@ -12,6 +12,8 @@ void loop(Renderer& renderer) {
12 int lucasSprite = game.addSprite(Sprite("../res/lucas_anim.txt", renderer)); 12 int lucasSprite = game.addSprite(Sprite("../res/lucas_anim.txt", renderer));
13 int lucasSprite2 = game.addSprite(Sprite("../res/lucas_anim.txt", renderer)); 13 int lucasSprite2 = game.addSprite(Sprite("../res/lucas_anim.txt", renderer));
14 14
15 game.moveSprite(lucasSprite, {32,32});
16
15 Party party; 17 Party party;
16 party.addMember(game, lucasSprite); 18 party.addMember(game, lucasSprite);
17 party.addMember(game, lucasSprite2); 19 party.addMember(game, lucasSprite2);
diff --git a/src/renderer.cpp b/src/renderer.cpp index 18b8ed8..931e699 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp
@@ -49,8 +49,9 @@ void Renderer::render(Game& game) {
49 SDL_RenderClear(ren_.get()); 49 SDL_RenderClear(ren_.get());
50 50
51 for (const Sprite& sprite : game.getSpritesByY() | game.spriteView()) { 51 for (const Sprite& sprite : game.getSpritesByY() | game.spriteView()) {
52 SDL_Rect src { sprite.getFrame() * sprite.size().w(), 0, sprite.size().w(), sprite.size().h() }; 52 const SpriteFrame& frame = sprite.getFrame();
53 SDL_Rect dest { sprite.loc().x(), sprite.loc().y(), sprite.size().w(), sprite.size().h() }; 53 const SDL_Rect& src = frame.srcRect;
54 SDL_Rect dest { sprite.loc().x() - frame.center.x(), sprite.loc().y() - frame.center.y(), frame.size.w(), frame.size.h() };
54 SDL_RenderCopy(ren_.get(), textures_.at(sprite.getTextureId()).get(), &src, &dest); 55 SDL_RenderCopy(ren_.get(), textures_.at(sprite.getTextureId()).get(), &src, &dest);
55 } 56 }
56 57
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
diff --git a/src/sprite.h b/src/sprite.h index 82ea90c..dc26fad 100644 --- a/src/sprite.h +++ b/src/sprite.h
@@ -8,6 +8,12 @@
8#include "renderer.h" 8#include "renderer.h"
9#include "vector.h" 9#include "vector.h"
10 10
11struct SpriteFrame {
12 SDL_Rect srcRect;
13 vec2i center;
14 vec2i size;
15};
16
11class Sprite { 17class Sprite {
12public: 18public:
13 19
@@ -21,11 +27,7 @@ public:
21 27
22 vec2i& loc() { return loc_; } 28 vec2i& loc() { return loc_; }
23 29
24 const vec2i& size() const { return size_; } 30 const SpriteFrame& getFrame() const { return frames_.at(animations_[curAnim_][curFrame_]); }
25
26 vec2i& size() { return size_; }
27
28 int getFrame() const { return animations_[curAnim_][curFrame_]; }
29 31
30 void setDirection(Direction dir); 32 void setDirection(Direction dir);
31 33
@@ -41,11 +43,11 @@ private:
41 43
42 int textureId_; 44 int textureId_;
43 vec2i loc_ { 0, 0 }; 45 vec2i loc_ { 0, 0 };
44 vec2i size_;
45 Direction curDir_ = Direction::down; 46 Direction curDir_ = Direction::down;
46 std::string state_; 47 std::string state_;
47 int curAnim_ = 0; 48 int curAnim_ = 0;
48 int curFrame_ = 0; 49 int curFrame_ = 0;
50 std::vector<SpriteFrame> frames_;
49 std::vector<std::vector<int>> animations_; 51 std::vector<std::vector<int>> animations_;
50 std::map<std::string, std::map<Direction, int>> stateDirToAnim_; 52 std::map<std::string, std::map<Direction, int>> stateDirToAnim_;
51}; 53};