mirror of
https://github.com/Nimac0/SDL_Minigame
synced 2026-01-12 15:53:42 +00:00
sprites walking directions done
This commit is contained in:
parent
4ae462136e
commit
9351307290
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 |
@ -19,5 +19,9 @@ struct Animation
|
|||||||
enum AnimationType
|
enum AnimationType
|
||||||
{
|
{
|
||||||
IDLE = 0,
|
IDLE = 0,
|
||||||
WALK = 1
|
WALK_R = 1,
|
||||||
|
WALK_L = 2
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -19,9 +19,9 @@ public:
|
|||||||
|
|
||||||
SpriteComponent* sprite;
|
SpriteComponent* sprite;
|
||||||
|
|
||||||
//for attack cooldown in between shots
|
//for attack cooldown in between shots
|
||||||
Uint32 lastFireTime;
|
Uint32 lastFireTime;
|
||||||
Uint32 fireCooldown = 1000; //in ms can be adjusted to change possible attack-speed
|
Uint32 fireCooldown = 1000; //in ms can be adjusted to change possible attack-speed
|
||||||
|
|
||||||
KeyboardController() = default;
|
KeyboardController() = default;
|
||||||
KeyboardController(SDL_Scancode up, SDL_Scancode down, SDL_Scancode left, SDL_Scancode right, SDL_Scancode fire, Vector2D fireVelocity);
|
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;
|
void update() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//for creation of projectiles
|
//for creation of projectiles
|
||||||
TransformComponent* player; //for starting position of projectile
|
TransformComponent* player; //for starting position of projectile
|
||||||
Vector2D fireVelocity; //decide source of projectile and flying direction
|
Vector2D fireVelocity; //decide source of projectile and flying direction
|
||||||
};
|
};
|
||||||
@ -10,8 +10,8 @@ KeyboardController::KeyboardController(SDL_Scancode up, SDL_Scancode down, SDL_S
|
|||||||
this->down = down;
|
this->down = down;
|
||||||
this->left = left;
|
this->left = left;
|
||||||
this->right = right;
|
this->right = right;
|
||||||
this->fire = fire;
|
this->fire = fire;
|
||||||
this->fireVelocity = fireVelocity;
|
this->fireVelocity = fireVelocity;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeyboardController::init()
|
void KeyboardController::init()
|
||||||
@ -28,42 +28,42 @@ 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]) {
|
||||||
|
|
||||||
Uint32 currentTicks = SDL_GetTicks();
|
Uint32 currentTicks = SDL_GetTicks();
|
||||||
|
|
||||||
if (currentTicks - lastFireTime >= fireCooldown) {
|
if (currentTicks - lastFireTime >= fireCooldown) {
|
||||||
|
|
||||||
player = &entity->getComponent<TransformComponent>();
|
player = &entity->getComponent<TransformComponent>();
|
||||||
|
|
||||||
//checks player source via the firing velocity
|
//checks player source via the firing velocity
|
||||||
//TODO: adding actual projectile textures
|
//TODO: adding actual projectile textures
|
||||||
if(fireVelocity.x > 0) {
|
if (fireVelocity.x > 0) {
|
||||||
Game::assets->createProjectile(Vector2D(player->position.x, player->position.y), fireVelocity,
|
Game::assets->createProjectile(Vector2D(player->position.x, player->position.y), fireVelocity,
|
||||||
false,1, 180, 1, "assets/egg.png");
|
false, 1, 180, 1, "assets/egg.png");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Game::assets->createProjectile(Vector2D(player->position.x, player->position.y), fireVelocity,
|
Game::assets->createProjectile(Vector2D(player->position.x, player->position.y), fireVelocity,
|
||||||
true,1, 180, 1, "assets/egg.png");
|
true, 1, 180, 1, "assets/egg.png");
|
||||||
}
|
}
|
||||||
|
|
||||||
lastFireTime = currentTicks;
|
lastFireTime = currentTicks;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -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);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user