Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include "game.h"
- #include "entity.h"
- class Enemy : public sf::RectangleShape, public Entity {
- public:
- Enemy(const sf::Vector2f &size = sf::Vector2f(0, 0)) : RectangleShape(size), Entity("", 100.0f, 10.0f, 5.0f)
- {
- std::cout << "Inside constructor for Enemy" << std::endl;
- }
- ~Enemy()
- {
- std::cout << "Inside destructor for Enemy" << std::endl;
- }
- sf::Vector2f getMoveDirection() const { return m_MoveDirection; }
- void setMoveDirection(const sf::Vector2f &moveDirection) { m_MoveDirection = moveDirection; }
- void setMoveDirection(float x, float y) { m_MoveDirection.x = x; m_MoveDirection.y = y; }
- void changeDirection();
- void update();
- private:
- sf::Vector2f m_MoveDirection;
- };
- void Enemy::changeDirection() {
- float new_x, new_y,
- x_neg, y_neg;
- new_x = rand() % 2;
- new_y = rand() % 2;
- x_neg = rand() % 2;
- y_neg = rand() % 2;
- if (x_neg == 1)
- new_x = -new_x;
- if (y_neg == 1)
- new_y = -new_y;
- setMoveDirection(new_x, new_y);
- }
- void Enemy::update() {
- move(m_MoveDirection * getSpeed());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement