diff --git a/assets/chicken_knight_spritesheet.png b/assets/chicken_knight_spritesheet.png index 9e6939d..e9bd505 100644 Binary files a/assets/chicken_knight_spritesheet.png and b/assets/chicken_knight_spritesheet.png differ diff --git a/assets/chicken_spritesheet.png b/assets/chicken_spritesheet.png index ba003eb..0e69278 100644 Binary files a/assets/chicken_spritesheet.png and b/assets/chicken_spritesheet.png differ diff --git a/include/AnimationHandler.h b/include/AnimationHandler.h index 0473651..ea6bf71 100644 --- a/include/AnimationHandler.h +++ b/include/AnimationHandler.h @@ -19,5 +19,9 @@ struct Animation enum AnimationType { IDLE = 0, - WALK = 1 -}; \ No newline at end of file + WALK_R = 1, + WALK_L = 2 +}; + + + diff --git a/include/KeyboardController.h b/include/KeyboardController.h index b353183..d22e14f 100644 --- a/include/KeyboardController.h +++ b/include/KeyboardController.h @@ -19,9 +19,9 @@ public: SpriteComponent* sprite; - //for attack cooldown in between shots - Uint32 lastFireTime; - Uint32 fireCooldown = 1000; //in ms can be adjusted to change possible attack-speed + //for attack cooldown in between shots + Uint32 lastFireTime; + Uint32 fireCooldown = 1000; //in ms can be adjusted to change possible attack-speed KeyboardController() = default; KeyboardController(SDL_Scancode up, SDL_Scancode down, SDL_Scancode left, SDL_Scancode right, SDL_Scancode fire, Vector2D fireVelocity); @@ -31,7 +31,7 @@ public: void update() override; private: - //for creation of projectiles - TransformComponent* player; //for starting position of projectile - Vector2D fireVelocity; //decide source of projectile and flying direction -}; + //for creation of projectiles + TransformComponent* player; //for starting position of projectile + Vector2D fireVelocity; //decide source of projectile and flying direction +}; \ No newline at end of file diff --git a/src/KeyboardController.cpp b/src/KeyboardController.cpp index 8ddd753..0094dda 100644 --- a/src/KeyboardController.cpp +++ b/src/KeyboardController.cpp @@ -10,8 +10,8 @@ KeyboardController::KeyboardController(SDL_Scancode up, SDL_Scancode down, SDL_S this->down = down; this->left = left; this->right = right; - this->fire = fire; - this->fireVelocity = fireVelocity; + this->fire = fire; + this->fireVelocity = fireVelocity; } void KeyboardController::init() @@ -28,42 +28,42 @@ void KeyboardController::update() if (keystates[this->up]) { transform->velocity.y = -1; - sprite->play(WALK); + sprite->play(WALK_R); } if (keystates[this->left]) { transform->velocity.x = -1; - sprite->play(WALK); + sprite->play(WALK_L); } if (keystates[this->down]) { transform->velocity.y = 1; - sprite->play(WALK); + sprite->play(WALK_R); } if (keystates[this->right]) { transform->velocity.x = 1; - sprite->play(WALK); + sprite->play(WALK_R); } - if (keystates[this->fire]) { + if (keystates[this->fire]) { - Uint32 currentTicks = SDL_GetTicks(); + Uint32 currentTicks = SDL_GetTicks(); - if (currentTicks - lastFireTime >= fireCooldown) { + if (currentTicks - lastFireTime >= fireCooldown) { - player = &entity->getComponent(); + player = &entity->getComponent(); - //checks player source via the firing velocity - //TODO: adding actual projectile textures - if(fireVelocity.x > 0) { - Game::assets->createProjectile(Vector2D(player->position.x, player->position.y), fireVelocity, - false,1, 180, 1, "assets/egg.png"); - } - else { - Game::assets->createProjectile(Vector2D(player->position.x, player->position.y), fireVelocity, - true,1, 180, 1, "assets/egg.png"); - } + //checks player source via the firing velocity + //TODO: adding actual projectile textures + if (fireVelocity.x > 0) { + Game::assets->createProjectile(Vector2D(player->position.x, player->position.y), fireVelocity, + false, 1, 180, 1, "assets/egg.png"); + } + else { + Game::assets->createProjectile(Vector2D(player->position.x, player->position.y), fireVelocity, + true, 1, 180, 1, "assets/egg.png"); + } - lastFireTime = currentTicks; - } + lastFireTime = currentTicks; + } - } + } } \ No newline at end of file diff --git a/src/SpriteComponent.cpp b/src/SpriteComponent.cpp index 1afe232..2339a2f 100644 --- a/src/SpriteComponent.cpp +++ b/src/SpriteComponent.cpp @@ -13,10 +13,12 @@ SpriteComponent::SpriteComponent(const char* path, bool isAnimated) animated = isAnimated; 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(WALK, walk); + animations.emplace(WALK_R, walkR); + animations.emplace(WALK_L, walkL); play(IDLE); @@ -61,7 +63,7 @@ void SpriteComponent::draw() TextureManager::get().draw(this->texture, this->srcRect, this->destRect); } -void SpriteComponent::play(AnimationType type) +void SpriteComponent::play(AnimationType type) { animationIndex = animations.at(type)->index; frames = animations.at(type)->frames;