update för helper
authorNils Forssén <nilfo359@student.liu.se>
Mon, 13 Nov 2023 10:06:27 +0000 (11:06 +0100)
committerNils Forssén <nilfo359@student.liu.se>
Mon, 13 Nov 2023 10:06:27 +0000 (11:06 +0100)
12 files changed:
assets/y6_figur2.png [deleted file]
assets/ysex.png [new file with mode: 0644]
src/Autonomous_object.h
src/Bike_enemy.h
src/Helper.cc
src/Helper.h
src/Main_enemy.h
src/Moving_object.h
src/Object.h
src/States.cc
src/States.h
src/Voi_enemy.h

diff --git a/assets/y6_figur2.png b/assets/y6_figur2.png
deleted file mode 100644 (file)
index e9c31ab..0000000
Binary files a/assets/y6_figur2.png and /dev/null differ
diff --git a/assets/ysex.png b/assets/ysex.png
new file mode 100644 (file)
index 0000000..e9c31ab
Binary files /dev/null and b/assets/ysex.png differ
index ae3bb53e31ad16aeeddc12f3dcdd331d55565f6e..4fa676fd1192cc99c93881572a63f55a7ac0ddcc 100644 (file)
@@ -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
index 112066170c2c0588cc18cc32cbacbb41c4f3c5d4..b00fbc959e8f36b5a23f55db5a5e691ad55f4e97 100644 (file)
@@ -1,8 +1,6 @@
 #ifndef  BIKE_ENEMY_H
 #define BIKE_ENEMY_H
 
-#include "Autonomous_object.h"
-
 class Bike_enemy
 {
 public:
index 665fe0a6ea660278e956caa5fcc4859e08450f24..89fe1611d8af182d9a7c077bfcd73f21648448c4 100644 (file)
@@ -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 <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
index 0aa1c54d700e4d8333d46c996987ac45aa0103d8..c848c0991be1dcd9e3314e6a00a4c80a095af986 100644 (file)
@@ -2,23 +2,23 @@
 #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
index d3aefb828ff1eaf8f6e4b5f6ec1b8040dc2b19fc..4370d69b4b928af7b614947b8291273d0497d6e5 100644 (file)
@@ -3,12 +3,11 @@
 
 #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;
index aa26add3f282d16948e80e2d6d0485b197abaa6d..6afe41a653334fdca692ddb627d3ad665e86d77e 100644 (file)
@@ -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
index bf5bbe40ad626a5720167eb88b41f5513e90485c..56e11e3f0af8cdf98b483c85c3370ad2e6ec705b 100644 (file)
@@ -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:
 };
 
index 97faf60e81df22edc1805aecdc36704ae77554e5..4b6631017fea406b27df9f35462b34c035b9a505 100644 (file)
@@ -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)
index 8664b0f000fa1b16e513b95e1d56ec082c42ab8f..a2340e3416652ee30cbda3874e489e3ff11aac24 100644 (file)
@@ -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;
 };
 
index bcde05386c333e1558468764e42197c2d3a6d93f..44015458bb190856fb171c3d5d0e2fc39672cd5d 100644 (file)
@@ -2,7 +2,6 @@
 #define VOI_ENEMY_H
 
 #include <SFML/Graphics.hpp>
-#include "Autonomous_object.h"
 
 class Voi_enemy
 {