From d1b297340d275abfc72531d45ac8b4c60d785ade Mon Sep 17 00:00:00 2001 From: =?utf8?q?Nils=20Forss=C3=A9n?= Date: Mon, 13 Nov 2023 11:06:27 +0100 Subject: [PATCH] =?utf8?q?update=20f=C3=B6r=20helper?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- assets/{y6_figur2.png => ysex.png} | Bin src/Autonomous_object.h | 19 +++------ src/Bike_enemy.h | 2 - src/Helper.cc | 60 ++++++++++++++++++++++++++++- src/Helper.h | 26 ++++++------- src/Main_enemy.h | 3 +- src/Moving_object.h | 6 +-- src/Object.h | 3 +- src/States.cc | 4 +- src/States.h | 2 + src/Voi_enemy.h | 1 - 11 files changed, 88 insertions(+), 38 deletions(-) rename assets/{y6_figur2.png => ysex.png} (100%) diff --git a/assets/y6_figur2.png b/assets/ysex.png similarity index 100% rename from assets/y6_figur2.png rename to assets/ysex.png diff --git a/src/Autonomous_object.h b/src/Autonomous_object.h index ae3bb53..4fa676f 100644 --- a/src/Autonomous_object.h +++ b/src/Autonomous_object.h @@ -1,21 +1,14 @@ #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 diff --git a/src/Bike_enemy.h b/src/Bike_enemy.h index 1120661..b00fbc9 100644 --- a/src/Bike_enemy.h +++ b/src/Bike_enemy.h @@ -1,8 +1,6 @@ #ifndef BIKE_ENEMY_H #define BIKE_ENEMY_H -#include "Autonomous_object.h" - class Bike_enemy { public: diff --git a/src/Helper.cc b/src/Helper.cc index 665fe0a..89fe161 100644 --- a/src/Helper.cc +++ b/src/Helper.cc @@ -1 +1,59 @@ -#include "Helper.h" \ No newline at end of file +#include "Helper.h" +#include "constants.h" +#include "States.h" +#include "Context.h" + + +#include + +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(context.current_state.get()); + sprite.setPosition(position); + + return; +} + +void Helper::render(sf::RenderWindow& window) const +{ + window.draw(sprite); +} \ No newline at end of file diff --git a/src/Helper.h b/src/Helper.h index 0aa1c54..c848c09 100644 --- a/src/Helper.h +++ b/src/Helper.h @@ -2,23 +2,23 @@ #define HELPER_H #include +#include "Autonomous_object.h" -#include "Autonomus_object.h - -#include - -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 diff --git a/src/Main_enemy.h b/src/Main_enemy.h index d3aefb8..4370d69 100644 --- a/src/Main_enemy.h +++ b/src/Main_enemy.h @@ -3,12 +3,11 @@ #include -#include "Autonomus_object.h" #include "Bottle.h" #include -class Main_enemy : public Autonomus_object +class Main_enemy { public: bool collides(Object& other) override; diff --git a/src/Moving_object.h b/src/Moving_object.h index aa26add..6afe41a 100644 --- a/src/Moving_object.h +++ b/src/Moving_object.h @@ -6,11 +6,9 @@ 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 diff --git a/src/Object.h b/src/Object.h index bf5bbe4..56e11e3 100644 --- a/src/Object.h +++ b/src/Object.h @@ -8,7 +8,7 @@ struct Context; class Object { public: - Object() : position{}, sprite{}, texture{} {}; + Object() : position{}, sprite{}, texture{}, direction{} {}; virtual ~Object() = default; virtual bool collides(Object& other) = 0; @@ -20,6 +20,7 @@ protected: sf::Vector2f position; sf::Sprite sprite; sf::Texture texture; + sf::Vector2f direction; private: }; diff --git a/src/States.cc b/src/States.cc index 97faf60..4b66310 100644 --- a/src/States.cc +++ b/src/States.cc @@ -4,7 +4,7 @@ #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} { } @@ -20,12 +20,14 @@ void Game_state::update(Context& context) } 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) diff --git a/src/States.h b/src/States.h index 8664b0f..a2340e3 100644 --- a/src/States.h +++ b/src/States.h @@ -5,6 +5,7 @@ #include "Map.h" #include "Player.h" +#include "Helper.h" struct Context; //finns en strukt som säger att Context finns innan den är deklarerad @@ -30,6 +31,7 @@ protected: private: Map game_map; Player player; + Helper helper; bool pause_game; }; diff --git a/src/Voi_enemy.h b/src/Voi_enemy.h index bcde053..4401545 100644 --- a/src/Voi_enemy.h +++ b/src/Voi_enemy.h @@ -2,7 +2,6 @@ #define VOI_ENEMY_H #include -#include "Autonomous_object.h" class Voi_enemy { -- 2.30.2