0
0
mirror of https://github.com/Nimac0/SDL_Minigame synced 2026-01-12 13:43:41 +00:00

sprites walking directions done

This commit is contained in:
ineslelin 2024-01-24 14:22:25 +01:00
parent 4ae462136e
commit 9351307290
6 changed files with 41 additions and 35 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

View File

@ -19,5 +19,9 @@ struct Animation
enum AnimationType enum AnimationType
{ {
IDLE = 0, IDLE = 0,
WALK = 1 WALK_R = 1,
WALK_L = 2
}; };

View File

@ -28,19 +28,19 @@ void KeyboardController::update()
if (keystates[this->up]) { if (keystates[this->up]) {
transform->velocity.y = -1; transform->velocity.y = -1;
sprite->play(WALK); sprite->play(WALK_R);
} }
if (keystates[this->left]) { if (keystates[this->left]) {
transform->velocity.x = -1; transform->velocity.x = -1;
sprite->play(WALK); sprite->play(WALK_L);
} }
if (keystates[this->down]) { if (keystates[this->down]) {
transform->velocity.y = 1; transform->velocity.y = 1;
sprite->play(WALK); sprite->play(WALK_R);
} }
if (keystates[this->right]) { if (keystates[this->right]) {
transform->velocity.x = 1; transform->velocity.x = 1;
sprite->play(WALK); sprite->play(WALK_R);
} }
if (keystates[this->fire]) { if (keystates[this->fire]) {

View File

@ -13,10 +13,12 @@ SpriteComponent::SpriteComponent(const char* path, bool isAnimated)
animated = isAnimated; animated = isAnimated;
Animation* idle = new Animation((int)AnimationType::IDLE, 2, 200); Animation* idle = new Animation((int)AnimationType::IDLE, 2, 200);
Animation* walk = new Animation((int)AnimationType::WALK, 2, 200); Animation* walkR = new Animation((int)AnimationType::WALK_R, 2, 200);
Animation* walkL = new Animation((int)AnimationType::WALK_L, 2, 200);
animations.emplace(IDLE, idle); animations.emplace(IDLE, idle);
animations.emplace(WALK, walk); animations.emplace(WALK_R, walkR);
animations.emplace(WALK_L, walkL);
play(IDLE); play(IDLE);