|
|
|
@ -7,6 +7,7 @@
|
|
|
|
|
#include <random>
|
|
|
|
|
|
|
|
|
|
#define SIMPLE_ENEMY_SPEED 20
|
|
|
|
|
#define SIMPLE_ENEMY_SCALE 1.5f
|
|
|
|
|
|
|
|
|
|
game::actor::SimpleEnemy::SimpleEnemy() : Base() {}
|
|
|
|
|
|
|
|
|
@ -36,10 +37,11 @@ void game::actor::SimpleEnemy::update(float dt, sf::RenderTarget* window, std::v
|
|
|
|
|
this->m_movementClock.restart();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float deltaValue = SIMPLE_ENEMY_SPEED * this->randomGenerator() * dt;
|
|
|
|
|
float deltaValue = this->m_speed * this->randomGenerator() * dt;
|
|
|
|
|
game::actor::AnimationState nextState = game::actor::Idle;
|
|
|
|
|
float diffValue;
|
|
|
|
|
|
|
|
|
|
// Up
|
|
|
|
|
if (this->m_direction == 0 || this->m_direction == 4 || this->m_direction == 5) {
|
|
|
|
|
diffValue = shapeBound.top - deltaValue;
|
|
|
|
|
if (diffValue > 0 && !this->doesCollideWithAny(diffValue, shapeBound.left, others)) {
|
|
|
|
@ -48,6 +50,7 @@ void game::actor::SimpleEnemy::update(float dt, sf::RenderTarget* window, std::v
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Down
|
|
|
|
|
if (this->m_direction == 1 || this->m_direction == 6 || this->m_direction == 7) {
|
|
|
|
|
diffValue = shapeBound.top + shapeBound.height + deltaValue;
|
|
|
|
|
if (diffValue < float(windowBound.y) && !this->doesCollideWithAny(diffValue, shapeBound.left, others)) {
|
|
|
|
@ -56,37 +59,71 @@ void game::actor::SimpleEnemy::update(float dt, sf::RenderTarget* window, std::v
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Left
|
|
|
|
|
if (this->m_direction == 2 || this->m_direction == 4 || this->m_direction == 6) {
|
|
|
|
|
diffValue = shapeBound.left - deltaValue;
|
|
|
|
|
if (diffValue > 0 && !this->doesCollideWithAny(shapeBound.top, diffValue, others)) {
|
|
|
|
|
this->moveLeft(deltaValue);
|
|
|
|
|
nextState = game::actor::Walk;
|
|
|
|
|
this->m_facing = game::actor::Left;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Right
|
|
|
|
|
if (this->m_direction == 3 || this->m_direction == 5 || this->m_direction == 7) {
|
|
|
|
|
diffValue = shapeBound.left + shapeBound.width + deltaValue;
|
|
|
|
|
if (diffValue < float(windowBound.x) && !this->doesCollideWithAny(shapeBound.top, diffValue, others)) {
|
|
|
|
|
this->moveRight(deltaValue);
|
|
|
|
|
nextState = game::actor::Walk;
|
|
|
|
|
this->m_facing = game::actor::Right;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this->updateAnimation(nextState);
|
|
|
|
|
|
|
|
|
|
this->m_currentAnimation->setScale((this->m_facing == game::actor::Left ? -1.f : 1.f) * SIMPLE_ENEMY_SCALE, SIMPLE_ENEMY_SCALE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void game::actor::SimpleEnemy::initSprite(ds::Vector position, sf::Sprite sprite) {
|
|
|
|
|
Base::initSprite(position, std::move(sprite));
|
|
|
|
|
|
|
|
|
|
std::basic_string<char> path;
|
|
|
|
|
int variant = (int(this->randomGenerator()) % 3) + 49;
|
|
|
|
|
|
|
|
|
|
if (variant == '1')
|
|
|
|
|
this->m_speed = SIMPLE_ENEMY_SPEED * 1.5;
|
|
|
|
|
else if (variant == '2')
|
|
|
|
|
this->m_speed = SIMPLE_ENEMY_SPEED;
|
|
|
|
|
else if (variant == '3')
|
|
|
|
|
this->m_speed = SIMPLE_ENEMY_SPEED * 0.5;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Idle
|
|
|
|
|
this->m_animation_idle.setSize(48, 48);
|
|
|
|
|
this->m_animation_idle.setSize(48, 48, 32, 0);
|
|
|
|
|
this->m_animation_idle.setLength(4);
|
|
|
|
|
path = "assets/sprite/simpleEnemy_idle_";
|
|
|
|
|
path.push_back(char(variant));
|
|
|
|
|
path.append(".png");
|
|
|
|
|
this->m_animation_idle.setTexture(path);
|
|
|
|
|
this->m_animation_idle.setScale(SIMPLE_ENEMY_SCALE, SIMPLE_ENEMY_SCALE);
|
|
|
|
|
|
|
|
|
|
// Special (nothing)
|
|
|
|
|
this->m_animation_idle.setSize(48, 48, 32, 0);
|
|
|
|
|
this->m_animation_idle.setLength(4);
|
|
|
|
|
this->m_animation_idle.setTexture("assets/sprite/simpleEnemy_idle.png");
|
|
|
|
|
path = "assets/sprite/simpleEnemy_idle_";
|
|
|
|
|
path.push_back(char(variant));
|
|
|
|
|
path.append(".png");
|
|
|
|
|
this->m_animation_idle.setTexture(path);
|
|
|
|
|
this->m_animation_idle.setScale(SIMPLE_ENEMY_SCALE, SIMPLE_ENEMY_SCALE);
|
|
|
|
|
|
|
|
|
|
// Walk
|
|
|
|
|
this->m_animation_walk.setSize(48, 48);
|
|
|
|
|
this->m_animation_walk.setSize(48, 48, 32, 0);
|
|
|
|
|
this->m_animation_walk.setLength(6);
|
|
|
|
|
this->m_animation_walk.setTexture("assets/sprite/simpleEnemy_walk.png");
|
|
|
|
|
path = "assets/sprite/simpleEnemy_walk_";
|
|
|
|
|
path.push_back(char(variant));
|
|
|
|
|
path.append(".png");
|
|
|
|
|
this->m_animation_walk.setTexture(path);
|
|
|
|
|
this->m_animation_idle.setScale(SIMPLE_ENEMY_SCALE, SIMPLE_ENEMY_SCALE);
|
|
|
|
|
|
|
|
|
|
this->updateTexture(game::actor::Idle);
|
|
|
|
|
|
|
|
|
|