börjat på placering av flaskor arvid, stina
authorArvid Sjöblom <arvsj277@student.liu.se>
Mon, 13 Nov 2023 10:06:28 +0000 (11:06 +0100)
committerArvid Sjöblom <arvsj277@student.liu.se>
Mon, 13 Nov 2023 10:06:28 +0000 (11:06 +0100)
src/Bottle.cc
src/Bottle.h
src/Context.h
src/Moving_object.h
src/States.cc
src/States.h
src/Static_object.h
src/_main.cc

index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..709ce1602f0153a5d81b23ceb53b3c2ab0c02836 100644 (file)
@@ -0,0 +1,32 @@
+#include "Bottle.h"
+#include "constants.h"
+#include "Context.h"
+#include <random>
+
+Bottle::Bottle() 
+{
+    texture.loadFromFile("assets/kir.png");
+    sprite.setTexture(texture);
+    position ={rand()%(S_WIDTH*5/7 - S_WIDTH/5 +1) + S_WIDTH/5, rand()%S_HEIGHT+1}; //x-pixel WIDTH/5 - WIDTH*5/7
+    sprite.setScale(S_SCALE_KOEFF, S_SCALE_KOEFF);
+    sf::FloatRect gb {sprite.getGlobalBounds()};
+    sprite.setOrigin(gb.width / 2, gb.height / 2);
+    sprite.setPosition(position);
+}
+bool Bottle::collides(Object& other)
+{
+
+}
+void Bottle::collision(Object& other) 
+{
+
+}
+void Bottle::update(Context& context) 
+{
+
+}
+
+void Bottle::render(sf::RenderWindow& window) const
+{
+    window.draw(sprite);
+}
\ No newline at end of file
index ea25e434509b326a93dab2a90fd0af27f90a7e25..1dfabfa4e1e13f7b6f7e315747f3e7686ec8dacc 100644 (file)
@@ -1,22 +1,20 @@
-#include "Static_object.h"
-#include <SFML/Graphics.hpp>
-
-
 #ifndef BOTTLE_H
 #define BOTTLE_H
 
+#include "Static_object.h"
+#include <SFML/Graphics.hpp>
 
-class Bottle : Static_object
+class Bottle : public Static_object
 {
-    public:
-        Object();
-        ~Object();
-        
-        bool collides(Object& other) override;
-        void collision(Object& other) override;
-        void update() override;
-        void render(sf::RenderWindow& window) override;
-    private:
+public:
+    Bottle();
+    
+    
+    bool collides(Object& other) override;
+    void collision(Object& other) override;
+    void update(Context& context) override;
+    void render(sf::RenderWindow& window) const override;
+private:
         
 };
 
index 6f99ae2295583656818498863aec2a20de7dee56..bdf0d1c649644491f25e6c534912fcc11d063bbb 100644 (file)
@@ -2,12 +2,14 @@
 #define CONTEXT_H
 
 #include "States.h"
+#include <SFML/Graphics.hpp>
 
 struct Context 
 {
     std::unique_ptr<State> current_state {nullptr};
     std::unique_ptr<State> next_state {nullptr};
     std::unique_ptr<Game_state> saved_game {nullptr};
+    sf::Int32 time;
 };
 
 #endif
\ No newline at end of file
index aa26add3f282d16948e80e2d6d0485b197abaa6d..d017195a6e9cf68734ed3b15140fa480021bf225 100644 (file)
@@ -1,5 +1,5 @@
-#ifndef MOVING_OBJECTS_H
-#define MOVING_OBJECTS_H
+#ifndef MOVING_OBJECT_H
+#define MOVING_OBJECT_H
 
 #include "Object.h"
 
index 97faf60e81df22edc1805aecdc36704ae77554e5..b7002510c8e5c622dfdbf2262033b5925de517a0 100644 (file)
@@ -1,11 +1,13 @@
 #include <memory>
-
+#include <iostream>
 #include "States.h"
 #include "Context.h"
 #include "constants.h"
 
-Game_state::Game_state() : game_map{}, player{}, pause_game{false}
+Game_state::Game_state() : game_map{}, player{}, pause_game{false}, bottles{}
 {
+    Bottle* bottle = new Bottle {};
+    bottles.push_back(bottle);
 }
 
 void Game_state::update(Context& context)
@@ -18,6 +20,16 @@ void Game_state::update(Context& context)
         pause_game = false;
         return;
     }
+    time_since_last_bottle += context.time;
+    //std::cout << time_since_last_bottle << std::endl;
+    if (time_since_last_bottle >= 2)
+    {
+        Bottle* bottle = new Bottle {};
+        bottles.push_back(bottle);
+        std::cout << "placed bottle"<< std::endl;
+        time_since_last_bottle = 0;
+
+    }
     game_map.update(context);
     player.update(context);
 }
@@ -26,6 +38,11 @@ void Game_state::render(sf::RenderWindow& window) const
 {
     game_map.render(window);
     player.render(window);
+    for (int i {}; i < int(bottles.size()); ++i)
+    {
+        bottles[i]->render(window);
+    } 
+        
 }
 
 void Game_state::handle_input(sf::Event& event)
index 8664b0f000fa1b16e513b95e1d56ec082c42ab8f..a9a73580ec713f825008f05975190a3c856e7a34 100644 (file)
@@ -2,9 +2,11 @@
 #define STATES_H
 
 #include "SFML/Graphics.hpp"
+#include <vector>
 
 #include "Map.h"
 #include "Player.h"
+#include "Bottle.h"
 
 struct Context; //finns en strukt som säger att Context finns innan den är deklarerad
 
@@ -28,6 +30,8 @@ public:
     void handle_input(sf::Event& event) override;
 protected:
 private:
+    float time_since_last_bottle {0};
+    std::vector<Bottle*> bottles;
     Map game_map;
     Player player;
     bool pause_game;
index 0f62fdb0e1b7d8ec35c1e04048d01a85a32d368c..2b63c0a0edc8505d7daf0d6b6f51af051ab85099 100644 (file)
@@ -1,18 +1,14 @@
 #ifndef STATIC_OBJECT_H
 #define STATIC_OBJECT_H
 
-#include <Object.h>
+#include "Object.h"
 #include <SFML/Graphics.hpp>
 
-class Static_obejct : public Object
+class Static_object : public Object
 {
 public:
     Static_object() = default;
-    virtual ~Static_object() = default;
-    virtual bool collides(Object &other) = 0;
-    virtual void collision(Object &other) = 0;
-    virtual void update() = 0;
-    virtual void render(sf::RenderWindow &window) = 0;
+    ~Static_object() = default;
 
 private:
 };
index d61c135ffccba2cdf6e62676931fc407fb93192c..7b58650ad29bca59a00918880c81c170813b506e 100644 (file)
@@ -41,6 +41,7 @@ int main ()
             game_context.current_state->handle_input(event);
         }
 
+        //game_context.time = game_clock.getElapsedtime().asSeconds()
         // Update startmeny
         game_context.current_state->update(game_context);