summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--res/kumatora.pngbin0 -> 1628 bytes
-rw-r--r--src/consts.h1
-rw-r--r--src/main.cpp8
-rw-r--r--src/party.cpp21
-rw-r--r--src/party.h4
-rw-r--r--src/sprite.cpp3
-rw-r--r--src/sprite.h4
7 files changed, 32 insertions, 9 deletions
diff --git a/res/kumatora.png b/res/kumatora.png new file mode 100644 index 0000000..c355ee9 --- /dev/null +++ b/res/kumatora.png
Binary files differ
diff --git a/src/consts.h b/src/consts.h index 96176a4..d6bf90b 100644 --- a/src/consts.h +++ b/src/consts.h
@@ -5,5 +5,6 @@ const int GAME_WIDTH = 640;
5const int GAME_HEIGHT = 480; 5const int GAME_HEIGHT = 480;
6 6
7const int MOVEMENT_SPEED = 4; 7const int MOVEMENT_SPEED = 4;
8const int PARTY_FRAME_DELAY = 20;// / MOVEMENT_SPEED;
8 9
9#endif /* end of include guard: CONSTS_H_9561E49C */ 10#endif /* end of include guard: CONSTS_H_9561E49C */
diff --git a/src/main.cpp b/src/main.cpp index b282a2e..5a4373b 100644 --- a/src/main.cpp +++ b/src/main.cpp
@@ -5,12 +5,14 @@
5 5
6void loop(Renderer& renderer) { 6void loop(Renderer& renderer) {
7 Game game; 7 Game game;
8 int playerSpriteId = game.addSprite(Sprite("../res/lucas.png", renderer));
9
10 Input keystate; 8 Input keystate;
11 9
10 int kumaSprite = game.addSprite(Sprite("../res/kumatora.png", renderer, 17, 31));
11 int lucasSprite = game.addSprite(Sprite("../res/lucas.png", renderer, 17, 27));
12
12 Party party; 13 Party party;
13 party.addMember(playerSpriteId); 14 party.addMember(game, lucasSprite);
15 party.addMember(game, kumaSprite);
14 16
15 renderer.render(game); 17 renderer.render(game);
16 18
diff --git a/src/party.cpp b/src/party.cpp index 559aacb..6c003b8 100644 --- a/src/party.cpp +++ b/src/party.cpp
@@ -1,10 +1,20 @@
1#include "party.h" 1#include "party.h"
2#include "consts.h" 2#include "consts.h"
3 3
4void Party::addMember(int spriteId) { 4void Party::addMember(Game& game, int spriteId) {
5 int index = members_.size();
6
5 PartyMember newMember; 7 PartyMember newMember;
6 newMember.spriteId = spriteId; 8 newMember.spriteId = spriteId;
7 9
10 if (index > 0) {
11 Sprite& sprite = game.getSprite(spriteId);
12
13 for (int i = 0; i < PARTY_FRAME_DELAY * index; i++) {
14 newMember.nextPosition.push_back(sprite.loc());
15 }
16 }
17
8 members_.push_back(std::move(newMember)); 18 members_.push_back(std::move(newMember));
9} 19}
10 20
@@ -36,7 +46,14 @@ void Party::move(Game& game, const Input& keystate) {
36 pLoc.x() += MOVEMENT_SPEED; 46 pLoc.x() += MOVEMENT_SPEED;
37 } 47 }
38 48
39 if (pLoc != p1.loc()) { 49 if (keystate.up || keystate.down || keystate.left || keystate.right) {
40 p1.loc() = pLoc; 50 p1.loc() = pLoc;
51
52 for (int i = 1; i < members_.size(); i++) {
53 Sprite& pNext = game.getSprite(members_[i].spriteId);
54 members_[i].nextPosition.push_back(pLoc);
55 pNext.loc() = members_[i].nextPosition.front();
56 members_[i].nextPosition.pop_front();
57 }
41 } 58 }
42} \ No newline at end of file 59} \ No newline at end of file
diff --git a/src/party.h b/src/party.h index 18c57b5..2a6ffc9 100644 --- a/src/party.h +++ b/src/party.h
@@ -1,13 +1,14 @@
1#ifndef PARTY_H_826F91BA 1#ifndef PARTY_H_826F91BA
2#define PARTY_H_826F91BA 2#define PARTY_H_826F91BA
3 3
4#include <deque>
4#include <vector> 5#include <vector>
5#include "game.h" 6#include "game.h"
6 7
7class Party { 8class Party {
8public: 9public:
9 10
10 void addMember(int spriteId); 11 void addMember(Game& game, int spriteId);
11 12
12 void move(Game& game, const Input& keystate); 13 void move(Game& game, const Input& keystate);
13 14
@@ -15,6 +16,7 @@ private:
15 16
16 struct PartyMember { 17 struct PartyMember {
17 int spriteId; 18 int spriteId;
19 std::deque<vec2i> nextPosition;
18 }; 20 };
19 21
20 std::vector<PartyMember> members_; 22 std::vector<PartyMember> members_;
diff --git a/src/sprite.cpp b/src/sprite.cpp index 0059f70..c8c4656 100644 --- a/src/sprite.cpp +++ b/src/sprite.cpp
@@ -1,6 +1,7 @@
1#include "sprite.h" 1#include "sprite.h"
2#include <SDL_image.h> 2#include <SDL_image.h>
3 3
4Sprite::Sprite(std::string_view filename, Renderer& renderer) { 4Sprite::Sprite(std::string_view filename, Renderer& renderer, int width, int height) {
5 textureId_ = renderer.loadImageFromFile(filename); 5 textureId_ = renderer.loadImageFromFile(filename);
6 size_ = { width*4, height*4 };
6} \ No newline at end of file 7} \ No newline at end of file
diff --git a/src/sprite.h b/src/sprite.h index c45e208..1f917d9 100644 --- a/src/sprite.h +++ b/src/sprite.h
@@ -8,7 +8,7 @@
8class Sprite { 8class Sprite {
9public: 9public:
10 10
11 Sprite(std::string_view filename, Renderer& renderer); 11 Sprite(std::string_view filename, Renderer& renderer, int width, int height);
12 12
13 int getTextureId() const { 13 int getTextureId() const {
14 return textureId_; 14 return textureId_;
@@ -26,7 +26,7 @@ private:
26 26
27 int textureId_; 27 int textureId_;
28 vec2i loc_ { 0, 0 }; 28 vec2i loc_ { 0, 0 };
29 vec2i size_ { 17*4, 27 * 4 }; 29 vec2i size_;
30}; 30};
31 31
32#endif /* end of include guard: SPRITE_H_70503825 */ 32#endif /* end of include guard: SPRITE_H_70503825 */