Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Armor
- {
- private:
- float body_size;
- sf::Color body_color;
- int defense;
- public:
- Armor(float body_r, sf::Color c, int d) : body_size(body_r), body_color(c), defense(d) {}
- float& GetBodySize() { return body_size; }
- sf::Color& GetBodyColor() { return body_color; }
- int& GetDefense() { return defense; }
- };
- class Turret
- {
- private:
- float rotor_radius;
- sf::Color rot_col;
- sf::Vector2f barrel_size;
- sf::Color barrel_col;
- public:
- Turret(float rr, sf::Color rc, sf::Vector2f bs, sf::Color bc)
- : rotor_radius(rr), rot_col(rc), barrel_size(bs), barrel_col(bc) {}
- float& GetRotorSize() { return rotor_radius; }
- sf::Color& GetRotorColor() { return rot_col; }
- sf::Vector2f& GetBarrelSize() { return barrel_size; }
- sf::Color& GetBarrelColor() { return barrel_col; }
- };
- class Robot
- {
- private:
- sf::CircleShape bot_body;
- Armor bot_armor;
- sf::CircleShape turret_body;
- sf::RectangleShape barrel_body;
- Turret bot_turret;
- float barrel_angle;
- sf::Clock barrel_clock;
- float current_x;
- float current_y;
- float velocity_x;
- float velocity_y;
- float max_velocity;
- ParticleSystem particles;
- protected:
- void BotUpdate(sf::Time t)
- {
- bot_body.setPosition(sf::Vector2f(current_x, current_y));
- turret_body.setPosition(sf::Vector2f(current_x, current_y));
- sf::Color reskin = turret_body.getFillColor();
- sf::Uint8 alpha = (sf::Uint8)std::rand() % 255;
- if (alpha > 127)
- if (sf::Uint8(reskin.g + 5) < reskin.g)
- reskin.g = 255;
- else reskin.g += 5;
- else
- if (sf::Uint8(reskin.g - 5) > reskin.g)
- reskin.g = 0;
- else reskin.g -= 5;
- turret_body.setFillColor(reskin);
- barrel_body.setPosition(sf::Vector2f(current_x, current_y));
- barrel_body.setRotation(barrel_angle);
- particles.setEmitter(GetCircumferencePoint(barrel_body.getPosition(), barrel_body.getSize().x, barrel_angle));
- particles.update(t);
- }
- public:
- Robot(Armor a, Turret t, float cx, float cy): bot_armor(a), bot_turret(t), current_x(cx), current_y(cy), particles(1000)
- {
- bot_body.setRadius(bot_armor.GetBodySize());
- bot_body.setFillColor(bot_armor.GetBodyColor());
- bot_body.setOrigin(sf::Vector2f(bot_body.getRadius(), bot_body.getRadius()));
- bot_body.setPosition(sf::Vector2f(current_x, current_y));
- turret_body.setRadius(bot_turret.GetRotorSize());
- turret_body.setFillColor(bot_turret.GetRotorColor());
- turret_body.setOrigin(sf::Vector2f(turret_body.getRadius(), turret_body.getRadius()));
- turret_body.setPosition(sf::Vector2f(current_x, current_y));
- barrel_body.setSize(bot_turret.GetBarrelSize());
- barrel_body.setFillColor(bot_turret.GetBarrelColor());
- barrel_body.setOrigin(sf::Vector2f(0, barrel_body.getSize().y / 2));
- barrel_body.setPosition(sf::Vector2f(current_x, current_y));
- barrel_angle = 90;
- velocity_x = 0;
- velocity_y = 0;
- max_velocity = 300;
- }
- void DrawBot(sf::RenderWindow* w)
- {
- w->draw(bot_body);
- w->draw(turret_body);
- w->draw(barrel_body);
- w->draw(particles);
- }
- void Update(sf::Time t)
- {
- BotUpdate(t);
- }
- void AccelerateX(float x)
- {
- velocity_x += x;
- if (velocity_x > max_velocity) velocity_x = max_velocity;
- else if (velocity_x < -max_velocity) velocity_x = -max_velocity;
- }
- void AccelerateY(float y)
- {
- velocity_y += y;
- if (velocity_y > max_velocity) velocity_y = max_velocity;
- else if (velocity_y < -max_velocity) velocity_y = -max_velocity;
- }
- sf::Vector2f GetVelocity() { return sf::Vector2f(velocity_x, velocity_y); }
- sf::Vector2f GetPosition() { return sf::Vector2f(current_x, current_y); }
- void SetPosition(float x, float y)
- {
- current_x = x;
- current_y = y;
- }
- bool IsUnderAcceleration() { return (velocity_x != 0 || velocity_y != 0); }
- void SetVelocityX(float v)
- {
- velocity_x = v;
- }
- void SetVelocityY(float v)
- {
- velocity_y = v;
- }
- float& GetMaxVelocity() { return max_velocity; }
- void BarrelRPMOffset(float offset)
- {
- if (barrel_angle + offset > 360) barrel_angle -= 360;
- else if (barrel_angle + offset < 0) barrel_angle += 360;
- barrel_angle += offset;
- }
- float GetBarrelAngle() { return barrel_angle; }
- };
Advertisement
Add Comment
Please, Sign In to add comment