#ifndef AUTONOMOUS_OBJECT_H
#define AUTONOMOUS_OBJECT_H
-#include "Object.h"
-class Autonomous_object
+#include "Moving_object.h"
+
+class Autonomous_object : public Moving_object
{
public:
- virtual bool collides(Object& other) = 0;
- virtual void collision(Object& other) = 0;
- virtual void update() = 0;
- virtual void render(sf::RenderWindow& window) = 0;
-
- virtual ~Autonomous_object() = default;
-private:
- virtual void move(Time) = 0;
+ Autonomous_object() = default;
+ ~Autonomous_object() = default;
protected:
- double x_pos;
- double y_pos;
- sf::Sprite sprite;
+private:
};
#endif
\ No newline at end of file
#ifndef BIKE_ENEMY_H
#define BIKE_ENEMY_H
-#include "Autonomous_object.h"
-
class Bike_enemy
{
public:
-#include "Helper.h"
\ No newline at end of file
+#include "Helper.h"
+#include "constants.h"
+#include "States.h"
+#include "Context.h"
+
+
+#include <iostream>
+
+Helper::Helper() : stop_pos{500}
+{
+ texture.loadFromFile("assets/ysex.png");
+ sprite.setTexture(texture);
+
+ sprite.setScale(S_SCALE_KOEFF, S_SCALE_KOEFF);
+ sf::FloatRect gb {sprite.getGlobalBounds()};
+ sprite.setOrigin(gb.width / 2, gb.height / 2);
+ position = {1000, 50};
+ sprite.setPosition(position);
+}
+
+
+bool Helper::collides(Object& other)
+{
+
+}
+
+void Helper::collision(Object& other)
+{
+
+
+}
+
+void Helper::update(Context& context)
+{
+ direction = {0.35, 1};
+ if (position.y == stop_pos && stop_pos > 50)
+ {
+ position -= direction;
+ stop_pos -= 1;
+ }
+ else
+ {
+ position += direction;
+ if (stop_pos == 50)
+ {
+ stop_pos = 500;
+ std::cout << stop_pos << std::endl;
+ }
+ }
+ //Game_state* game = static_cast<Game_state*>(context.current_state.get());
+ sprite.setPosition(position);
+
+ return;
+}
+
+void Helper::render(sf::RenderWindow& window) const
+{
+ window.draw(sprite);
+}
\ No newline at end of file
#define HELPER_H
#include <SFML/Graphics.hpp>
+#include "Autonomous_object.h"
-#include "Autonomus_object.h
-
-#include <vector>
-
-class Helper : public Autonomus_object
+class Helper : public Autonomous_object
{
- public:
- bool collides(Object& other) override;
- void collision(Object& other) override;
- void update() override;
- void render(sf::RenderWindow& window) override;
+public:
+ Helper();
+ ~Helper() = default;
- protected:
- void move(Time) override;
+ bool collides(Object& other) override;
+ void collision(Object& other) override;
+ void update(Context& context) override;
+ void render(sf::RenderWindow& window) const override;
- private:
+protected:
+ //void move(Time);
+private:
+ int stop_pos;
};
#endif
\ No newline at end of file
#include <SFML/Graphics.hpp>
-#include "Autonomus_object.h"
#include "Bottle.h"
#include <vector>
-class Main_enemy : public Autonomus_object
+class Main_enemy
{
public:
bool collides(Object& other) override;
class Moving_object : public Object
{
public:
- Moving_object() : direction{} {};
+ Moving_object() = default;
~Moving_object() = default;
-protected:
- sf::Vector2f direction; // Treat like unit-vector for movement
-
+protected:
private:
};
#endif
\ No newline at end of file
class Object
{
public:
- Object() : position{}, sprite{}, texture{} {};
+ Object() : position{}, sprite{}, texture{}, direction{} {};
virtual ~Object() = default;
virtual bool collides(Object& other) = 0;
sf::Vector2f position;
sf::Sprite sprite;
sf::Texture texture;
+ sf::Vector2f direction;
private:
};
#include "Context.h"
#include "constants.h"
-Game_state::Game_state() : game_map{}, player{}, pause_game{false}
+Game_state::Game_state() : game_map{}, player{}, helper{}, pause_game{false}
{
}
}
game_map.update(context);
player.update(context);
+ helper.update(context);
}
void Game_state::render(sf::RenderWindow& window) const
{
game_map.render(window);
player.render(window);
+ helper.render(window);
}
void Game_state::handle_input(sf::Event& event)
#include "Map.h"
#include "Player.h"
+#include "Helper.h"
struct Context; //finns en strukt som säger att Context finns innan den är deklarerad
private:
Map game_map;
Player player;
+ Helper helper;
bool pause_game;
};
#define VOI_ENEMY_H
#include <SFML/Graphics.hpp>
-#include "Autonomous_object.h"
class Voi_enemy
{