Removed warnings
authorNilsForssen <forssennils@gmail.com>
Fri, 8 Dec 2023 11:04:27 +0000 (12:04 +0100)
committerNilsForssen <forssennils@gmail.com>
Fri, 8 Dec 2023 11:07:10 +0000 (12:07 +0100)
23 files changed:
assets/data.json
assets/highscore.csv
src/Bike_enemy.cc
src/Bike_enemy.h
src/Bottle.cc
src/Bottle.h
src/GameOver_menu.cc
src/Helper.cc
src/Helper.h
src/Main_enemy.cc
src/Main_enemy.h
src/Map.cc
src/Map.h
src/Object.h
src/Pause_menu.cc
src/Player.cc
src/Player.h
src/Scoreboard_menu.cc
src/Start_menu.cc
src/States.cc
src/States.h
src/YF.cc
src/YF.h

index df0fe2437e499a6e1cd619193fa61b197fc9a617..a2352628ee456f5408e20a6ae77ca5fe86359ab5 100644 (file)
 {
-    "player" : 
-    {
-        "start_pos": [200, 200],
-        "scale": [0.5, 0.5],
+    "player": {
+        "start_pos": [
+            200,
+            200
+        ],
+        "scale": [
+            0.5,
+            0.5
+        ],
         "max_speed": 5,
         "degrees_per_second": 360,
-        "sack" : 
-        {
-            "offset" : [25, -5],
-            "scale" : [0.3, 0.3],
-            "angle" : -25
+        "sack": {
+            "offset": [
+                25,
+                -5
+            ],
+            "scale": [
+                0.3,
+                0.3
+            ],
+            "angle": -25
         }
-        
     },
     "helper": {
-        "start_pos": [1000, 50],
-        "scale": [0.3, 0.3],
+        "start_pos": [
+            1000,
+            50
+        ],
+        "scale": [
+            0.3,
+            0.3
+        ],
         "max_speed": 2,
-
-        "direction": [0.35, 1],
+        "direction": [
+            0.35,
+            1
+        ],
         "stop_top": 50,
         "stop_bot": 500
     },
-    "bottle": 
-    {
-        "scale": [0.5, 0.5]   
+    "bottle": {
+        "scale": [
+            0.5,
+            0.5
+        ]
     },
-    "game_constants":
-    {
-        "scoreboard" : 5,
-        "bottles_per_second" : 1.5,
-        "game_time" : 10,
+    "game_constants": {
+        "scoreboard": 5,
+        "bottles_per_second": 1.5,
+        "game_time": 30,
         "yf_per_second": 0.125,
         "bikes_per_second": 0.17,
         "point_scale_div": 3.0,
         "highscore_file": "assets/highscore.csv"
     },
-    "map":
-    {
-        "points_pos": [5, 38],
-        "collected_pos": [5, 76],
-        "time_pos": [5, 0],
+    "map": {
+        "points_pos": [
+            5,
+            38
+        ],
+        "collected_pos": [
+            5,
+            76
+        ],
+        "time_pos": [
+            5,
+            0
+        ],
         "font_size": 36
     },
-
-    "main_enemy":
-    {
-        "scale" : [0.35, 0.35],
-        "start_pos" : [50, 600],
+    "main_enemy": {
+        "scale": [
+            0.35,
+            0.35
+        ],
+        "start_pos": [
+            50,
+            600
+        ],
         "max_speed": 2.0,
         "degrees_per_second": 360
     },
-    "yf":
-    {
-        "scale" : [1, 1],
-        "max_speed" : 2.0,
-        "direction": [0, -1]
-        
+    "yf": {
+        "scale": [
+            1,
+            1
+        ],
+        "max_speed": 2.0,
+        "direction": [
+            0,
+            -1
+        ]
     },
-
-    "bike_enemy":
-    {
-        "scale" : [0.25, 0.25],
-        "max_speed" : 5.0,
-        "direction": [0, 1],
+    "bike_enemy": {
+        "scale": [
+            0.25,
+            0.25
+        ],
+        "max_speed": 5.0,
+        "direction": [
+            0,
+            1
+        ],
         "sin_amplitude": 50,
         "sin_omega": 5
     },
-
-    "game_state_assets":
-    {
+    "game_state_assets": {
         "kir_file": "assets/kir.png",
         "YF_file": "assets/YF.png",
         "cyklist_file": "assets/cyklist.png",
         "helper_file": "assets/ysex.png",
         "map_file": "assets/bakgrund.png"
     },
-    "gameover_menu":
-    {
+    "gameover_menu": {
         "texture": "assets/game_over.png",
-        "texture_mouse" : "assets/muspekareRed.png",
-        "font" : "assets/fonts/Philosopher-Regular.ttf"
+        "texture_mouse": "assets/muspekareRed.png",
+        "font": "assets/fonts/Philosopher-Regular.ttf"
     },
-
-    "pause_menu":
-    {
+    "pause_menu": {
         "texture": "assets/Pause_bild.png",
-        "texture_mouse" : "assets/muspekareGul.png",
+        "texture_mouse": "assets/muspekareGul.png",
         "font": "assets/fonts/Philosopher-Regular.ttf"
     },
-    "scoreboard_menu": 
-    {
+    "scoreboard_menu": {
         "texture": "assets/scoreboard.png",
-        "texture_mouse" : "assets/muspekare2.png",
+        "texture_mouse": "assets/muspekare2.png",
         "font": "assets/fonts/Philosopher-Regular.ttf"
     },
-    "start_menu":
-    {
-     "texture": "assets/meny_bild.png",
-     "texture_mouse" : "assets/muspekareGul.png",
-     "font": "assets/fonts/Philosopher-Regular.ttf"     
+    "start_menu": {
+        "texture": "assets/meny_bild.png",
+        "texture_mouse": "assets/muspekareGul.png",
+        "font": "assets/fonts/Philosopher-Regular.ttf"
     }
-
 }
\ No newline at end of file
index 4f8ab68fbee6c5e1f7d0111c582a608acc16ac29..b569f5551707d493a3bab745667ee2f39afcd892 100644 (file)
@@ -1,3 +1,4 @@
 Nisseboi, 5
 Lukas is KUNG, 5
+NissePisse, 4
 Nils, 1
index fcaed4772f7fb93c7de5fa144549c15819e281d8..360866b9dbd38a379eb2a2def7b3d71e12dfeb1a 100644 (file)
@@ -20,11 +20,12 @@ Bike_enemy::Bike_enemy(sf::Texture& txtr, json& params) : max_speed{params["max_
     sprite.setPosition(position);
 }
 
+void Bike_enemy::collision_player() 
+{}
 
-void Bike_enemy::collision(Object &other) 
-{
+void Bike_enemy::collision_enemy()
+{}
 
-}
 void Bike_enemy::update(Context& context)
 {
     //Game_state* game = static_cast<Game_state*>(context.current_state.get());
index 03b88d587f79ca54112396ec109909720c6aa200..125415766313ca8dee42a2448841ea40cab46efa 100644 (file)
@@ -13,7 +13,8 @@ class Bike_enemy : public Moving_object
 public:
     Bike_enemy(sf::Texture& txtr, json& params);
     ~Bike_enemy() = default;
-    void collision(Object &other) override;
+    void collision_player();
+    void collision_enemy();
     void update(Context& context) override;
     void render(sf::RenderWindow &window) const override;
     
index 2ead9464fef5e938682e7968a854cf1bfa10c8fb..64b2d3c315a90ab85f42a8f9346a4d2b57255c05 100644 (file)
@@ -3,26 +3,24 @@
 #include "Bottle.h"
 #include "constants.h"
 #include "Context.h"
+#include "States.h"
 
 
 Bottle::Bottle(sf::Texture& txtr, json& params)
 {
     texture = txtr;
     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
+    position ={rand()%static_cast<int>(S_WIDTH*5/7.0f - S_WIDTH/5.0f +1) + S_WIDTH/5.0f,
+        static_cast<float>(rand()%static_cast<int>(S_HEIGHT+1))};
     sprite.setScale(params["scale"][0], params["scale"][1]);
     sf::FloatRect gb {sprite.getGlobalBounds()};
     sprite.setOrigin(gb.width / 2, gb.height / 2);
     sprite.setPosition(position);
 }
 
-void Bottle::collision(Object& other) 
-{
-
-}
 void Bottle::update(Context& context) 
 {
-
+    static_cast<Game_state*>(context.current_state.get());
 }
 
 void Bottle::render(sf::RenderWindow& window) const
index 15d605660dbb69a7777064b06031f1e3460c0cb5..645dc7cfc612949773d164935068907d7a2d2431 100644 (file)
@@ -14,7 +14,6 @@ class Bottle : public Static_object
 public:
     Bottle(sf::Texture& txtr, json& params);
     
-    void collision(Object& other) override;
     void update(Context& context) override;
     void render(sf::RenderWindow& window) const override;
     void set_texture(sf::Texture& txtr);
index b54de21e93485cd96764ac50b8c55dbfc892ccce..f298b6b5fbaa1f2046304ef56999858cd051c0de 100644 (file)
 using json = nlohmann::json;
 
 
-GameOver_menu::GameOver_menu(int const points, json& params) : 
+GameOver_menu::GameOver_menu(int const points, json& params) :
+    menu_index{1}, 
+    points{points},
+
+    exit_game{false}, 
+    menu{false}, 
+
     texture{}, 
     texture2{}, 
+
     sprite{}, 
-    rectangle{}, 
     mouse_l{}, 
     mouse_r{}, 
+
+    rectangle{},
+
+    playerInput{}, 
+
+    playerText{}, 
     linetext{}, 
     funfacttext{}, 
     entertext{}, 
     pointstext{}, 
-    playerInput{},  
-    playerText{}, 
-    data{}, 
     savetext{}, 
     quittext{}, 
+
     font{}, 
-    exit_game{false}, 
-    menu{false}, 
-    menu_index{1}, 
-    points{points}
+
+    data{}
 {
     data = std::move(params);
     texture.loadFromFile(data["gameover_menu"]["texture"]);
@@ -178,7 +186,7 @@ void GameOver_menu::handle_input(sf::Event& event)
             case 0: // A
                 if(menu_index == 1)
                 {
-                    load_to_csv(playerText);
+                    load_to_csv();
                     menu = true;
                     menu_index = 1;
                 }
@@ -227,6 +235,9 @@ void GameOver_menu::handle_input(sf::Event& event)
                 break; 
             }
             break;
+
+        default:
+            break;
         }
         break;
     case sf::Event::KeyPressed:
@@ -236,7 +247,7 @@ void GameOver_menu::handle_input(sf::Event& event)
 
             if(menu_index == 1)
             {
-                load_to_csv(playerText);
+                load_to_csv();
                 menu = true;
                 menu_index = 1;
             }
@@ -299,22 +310,17 @@ void GameOver_menu::handle_input(sf::Event& event)
             }
 
         }
-
         // if not backspace, print letters
         else if(playerInput.getSize() < 20)
         {
             playerInput += event.text.unicode;
         }
-
         playerText.setString(playerInput);
-
     }
-
-
 }
 
 //spara namn till fil
-void GameOver_menu::load_to_csv(sf::Text playertext)
+void GameOver_menu::load_to_csv()
 {   
 
     std::string current_line{playerText.getString() + ", " + std::to_string(points)};
index 7bcd2a74451dca46f46a5c671253a3cc02d8054f..65169561cd9055330fce893bef1abaf7f6aeb8bd 100644 (file)
@@ -5,7 +5,11 @@
 #include "constants.h"
 #include "Context.h"
 
-Helper::Helper(sf::Texture& txtr, json& params) : stop_bot{params["stop_bot"]}, stop_top{params["stop_top"]}, max_speed{params["max_speed"]}, movement{}
+Helper::Helper(sf::Texture& txtr, json& params) :
+    stop_bot{params["stop_bot"]},
+    stop_top{params["stop_top"]},
+    max_speed{params["max_speed"]},
+    movement{}
 {
     texture = txtr;
     position = {params["start_pos"][0], params["start_pos"][1]};
@@ -23,18 +27,16 @@ Helper::Helper(sf::Texture& txtr, json& params) : stop_bot{params["stop_bot"]},
 }
 
 
-void Helper::collision(Object& other)
+void Helper::collision_player()
 {
     move(false);
 }
 
 
 void Helper::update(Context& context)
-{       
+{    
+    static_cast<Game_state*>(context.current_state.get());
     move();
-
-    //Game_state* game = static_cast<Game_state*>(context.current_state.get());
-    
 }
 
 void Helper::move(bool forward)
index 5db3cea37b455aa4786a742bc1f700ae8584fe3d..7b92ff78323a73dac7ab3ea0ad136bf7f6517db5 100644 (file)
@@ -15,7 +15,7 @@ public:
     Helper(sf::Texture& txtr, json& params);
     ~Helper() = default;
 
-    void collision(Object& other) override;
+    void collision_player();
     void update(Context& context) override;
     void render(sf::RenderWindow& window) const override;
 
@@ -23,9 +23,11 @@ protected:
     //void move(Time);
 private:
     void move(bool forward=true);
+
     float stop_bot;
     float stop_top;
     float max_speed;
+    
     sf::Vector2f movement;
 };
 
index f9f9d9e686763d309618ca460f23c2ec6181c30c..52dcc25d3965d2578904b1ecd606fd1f80b2d3f0 100644 (file)
@@ -5,7 +5,13 @@
 #include "Context.h"
 #include "constants.h"
 
-Main_enemy::Main_enemy(sf::Texture& txtr, json& params): max_speed{params["max_speed"]}, moving_to_bottle{false}, tumbling{false}, tumble_degrees{0}, rotation{params["degrees_per_second"]}
+Main_enemy::Main_enemy(sf::Texture& txtr, json& params):
+    max_speed{params["max_speed"]},
+    tumble_degrees{0},
+    rotation{params["degrees_per_second"]},
+
+    tumbling{false},
+    moving_to_bottle{false}
 {
     //texture.loadFromFile("assets/6Ling_figur2.png");
     texture = txtr;
@@ -18,10 +24,22 @@ Main_enemy::Main_enemy(sf::Texture& txtr, json& params): max_speed{params["max_s
     
 } 
 
-void Main_enemy::collision(Object& other) 
+void Main_enemy::collision_yf() 
+{
+    move(false);
+}
+
+void Main_enemy::collision_bike()
+{
+    move(false);
+}
+
+void Main_enemy::collision_player()
 {
     move(false);
+    tumbling = true;
 }
+
 void Main_enemy::update(Context& context) 
 {
     if(tumbling)
@@ -57,12 +75,6 @@ void Main_enemy::render(sf::RenderWindow& window) const
     window.draw(sprite);
 }
 
-void Main_enemy::collision(Player& player)
-{
-    move(false);
-    tumbling = true;
-}
-
 void Main_enemy::move(bool forward)
 {
     if (moving_to_bottle)
index dad5e8a8d83bbefe7da67e63ab8987509e41b3e6..087fa2f94cb3e764faa12d56e2864cf5ae2933b9 100644 (file)
@@ -18,22 +18,25 @@ class Main_enemy : public Moving_object
 public:
     Main_enemy(sf::Texture& txtr, json& params);
     ~Main_enemy() = default;
-    void collision(Object& other) override;
-    void collision(Player& player);
+    void collision_yf();
+    void collision_bike();
+    void collision_player();
     void update(Context& context) override;
     void render(sf::RenderWindow& window) const override;
 
 protected:
 
 private:
+    float bottle_dist(std::unique_ptr<Bottle> const& bottle);
+    sf::Vector2f find_closest_bottle(std::vector<std::unique_ptr<Bottle>> & bottles);
+    void move(bool forward = true);
+
     float max_speed;
     float tumble_degrees;
-    int rotation; 
+    int rotation;
+    
     bool tumbling;
     bool moving_to_bottle;
-    void move(bool forward = true);
-    float bottle_dist(std::unique_ptr<Bottle> const& bottle);
-    sf::Vector2f find_closest_bottle(std::vector<std::unique_ptr<Bottle>> & bottles);
 };
 
 #endif
\ No newline at end of file
index 4be2c42a105c1da89035de6a0771c7733ce1f943..9b6b80d82d2b37fb00016f2cd3e3b52a2955ff5d 100644 (file)
@@ -3,7 +3,18 @@
 
 #include <string>
 
-Map::Map(sf::Texture& txtr, sf::Texture& bottle_txtr, json& params) : texture{txtr}, sprite{}, point_text{}, collected_text{}, time_text{}, bottle_texture{bottle_txtr}, bottle_sprite{}, font{}
+Map::Map(sf::Texture& txtr, sf::Texture& bottle_txtr, json& params) :
+    texture{txtr},
+    bottle_texture{bottle_txtr},
+
+    sprite{},
+    bottle_sprite{},
+
+    point_text{},
+    collected_text{},
+    time_text{},
+
+    font{}
 {
     sprite.setTexture(texture);
 
@@ -61,6 +72,9 @@ void Map::update(int const collected, int const points, int const time_left)
     time_text.setString("Time left: " + std::to_string(time_left) + " s");
 }
 
+void Map::collision_player()
+{}
+
 void Map::render(sf::RenderWindow& window) const
 {
     window.draw(sprite);
index a5e26437b6827604f68cfff12be836366123096f..58c7569a7337033bfee24b702fbe912fd6cb035b 100644 (file)
--- a/src/Map.h
+++ b/src/Map.h
@@ -13,19 +13,22 @@ class Map
 public:
     Map(sf::Texture& txtr, sf::Texture& bottle_txtr, json& params);
     ~Map() = default;
-
+    void collision_player();
     void update(int const collected, int const points, int const time_left);
     void render(sf::RenderWindow& window) const;
     bool collides(Object& other);
 protected:
 private:
     sf::Texture texture;
-    sf::Sprite sprite;
     sf::Texture bottle_texture;
+    
+    sf::Sprite sprite;
     sf::Sprite bottle_sprite;
+
     sf::Text point_text;
     sf::Text collected_text;
     sf::Text time_text;
+    
     sf::Font font;
 };
 
index 2b7e6607ad3685289f45b7a5b7a087b5cc8768e1..20c564a6afebda85b1b3ae12ab0f770045ccb108 100644 (file)
@@ -15,7 +15,6 @@ public:
     {
         return get_hitbox().intersects(other.get_hitbox());
     }
-    virtual void collision(Object& other) = 0;
     virtual void update(Context& context) = 0;
     virtual void render(sf::RenderWindow& window) const = 0;
 
index cacd995955211895c3e882282d454b0644764d8a..8f51a2985d66183cdd04a114a9e72fc3702e6a2e 100644 (file)
@@ -8,8 +8,27 @@
 using json = nlohmann::json;
 
 
-Pause_menu::Pause_menu(json& params) : texture{}, texture2{}, sprite{}, mouse_l{}, mouse_r{}, resumetext{}, startmenutext{}, 
-                           quittext{}, font{}, resume_game{false}, exit_game{false}, menu{false}, menu_index{1}, data{}
+Pause_menu::Pause_menu(json& params) :
+    menu_index{1},
+
+    resume_game{false},
+    exit_game{false},
+    menu{false},
+
+    texture{},
+    texture2{},
+
+    sprite{},
+    mouse_l{},
+    mouse_r{},
+
+    resumetext{},
+    startmenutext{},
+    quittext{},
+
+    font{},
+
+    data{}
 {
     data = params;
     texture.loadFromFile(data["pause_menu"]["texture"]);
@@ -173,6 +192,8 @@ void Pause_menu::handle_input(sf::Event& event)
                 break; 
             }
             break;
+        default:
+            break;
         }
         break;
     case sf::Event::KeyPressed:
index a4fdef070253b95577c34a7fc22075250a2e7e56..cec7c490d8efefb32ca4a966739c9db166778bc4 100644 (file)
@@ -4,8 +4,19 @@
 #include "Context.h"
 #include "constants.h"
 
-Player::Player(sf::Texture& player_txtr, sf::Texture& sack_txtr, json& params) : sack_texture{sack_txtr}, collected{0}, max_speed{params["max_speed"]}, tumbling{false}, tumble_degrees{0}, rotation{params["degrees_per_second"]}
+Player::Player(sf::Texture& player_txtr, sf::Texture& sack_txtr, json& params) :
+    collected{0},
+    rotation{params["degrees_per_second"]},
+    tumble_degrees{0},
+    max_speed{params["max_speed"]},
+
+    tumbling{false},
+
+    sack{},
+    sack_texture{sack_txtr},
+    sack_offset{params["sack"]["offset"][0], params["sack"]["offset"][1]}
 {
+
     texture = player_txtr;
     position = {params["start_pos"][0], params["start_pos"][1]};
 
@@ -22,19 +33,17 @@ Player::Player(sf::Texture& player_txtr, sf::Texture& sack_txtr, json& params) :
     
     sf::FloatRect gb_s {sack.getLocalBounds()};
     sack.setOrigin(gb_s.width / 3, gb_s.height / 5);
-    sack_offset = {params["sack"]["offset"][0], params["sack"]["offset"][1]};
     sack.rotate(params["sack"]["angle"]);
     sack.setPosition(position + sack_offset);
 }
 
 
-void Player::collision(Object& other)
+void Player::collision_helper()
 {
     move(false);
-
 }
 
-void Player::collision(Map& map)
+void Player::collision_map()
 {
     if (tumbling)
     {
@@ -46,24 +55,25 @@ void Player::collision(Map& map)
     }
 }
 
-void Player::collision(YF& yf)
+void Player::collision_yf()
 {
     move(false);
     tumbling = true;
 }
-void Player::collision(Bike_enemy& bike)
+
+void Player::collision_bike()
 {
     move(false);
     tumbling = true;
 }
 
+void Player::collision_enemy()
+{}
+
 void Player::update(Context& context)
 {
-    
-    // Get game_state from context, static_cast since we know that game is currently running
-    // game_state is still managed by context
-    //Game_state* game = static_cast<Game_state*>(context.current_state.get());
-    
+    static_cast<Game_state*>(context.current_state.get());
+
     if(tumbling)
     {
         sprite.rotate(-1*std::copysign(1, direction.x)*rotation/FPS);
@@ -95,7 +105,12 @@ void Player::render(sf::RenderWindow& window) const
 }
 
 void Player::handle_input(sf::Event& event)
-{ 
+{   
+    switch(event.type)
+    {
+        default:
+            break;
+    }
     if (!tumbling)
     {
         if (!sf::Joystick::isConnected(0))
@@ -133,7 +148,7 @@ void Player::handle_input(sf::Event& event)
                 sf::Joystick::getAxisPosition(0, sf::Joystick::Y) / 100
             };
             
-            float len{pow(direction.x, 2) + pow(direction.y, 2)};
+            double len{pow(direction.x, 2) + pow(direction.y, 2)};
             if (len > 1) 
             {
                 direction.x /= sqrt(len);
index 6bfef298fb6ee0a8fe2fc282bb40143eacc95fb2..76b362d1e75b9a36ce603c6b24f2adf255fd304b 100644 (file)
@@ -20,10 +20,11 @@ public:
     Player(sf::Texture& player_txtr, sf::Texture& sack_txtr, json& params);
     ~Player() = default;
     
-    void collision(Object& other) override;
-    void collision(Map& map);
-    void collision(YF& yf);
-    void collision(Bike_enemy& bike);
+    void collision_yf();
+    void collision_helper();
+    void collision_enemy();
+    void collision_bike();
+    void collision_map();
     void update(Context& context) override;
     void render(sf::RenderWindow& window) const override;
     void handle_input(sf::Event& event);
@@ -34,11 +35,14 @@ public:
 protected:
 private:
     void move(bool forward=true);
+
     int collected;
-    float tumble_degrees;
     int rotation; 
+    float tumble_degrees;
     float max_speed;
+
     bool tumbling;
+    
     sf::Sprite sack;
     sf::Texture sack_texture;
     sf::Vector2f sack_offset; 
index daa70dd9b47dba72e5553cbc754072f9128d0574..33fc74b690aad197a90e5ffddf03e2c9f5c928f1 100644 (file)
@@ -9,9 +9,27 @@
 using json = nlohmann::json;
 
 
-Scoreboard_menu::Scoreboard_menu(json& params) : texture{}, texture2{}, sprite{}, menu{false}, exit_game{false}, 
-                                 startmenutext{}, quittext{}, mouse_r{}, mouse_l{}, font{}, menu_index{1}, data{}
-                                 
+Scoreboard_menu::Scoreboard_menu(json& params) :
+    menu_index{1},
+
+    exit_game{false},
+    menu{false},
+
+    texture{},
+    texture2{},
+
+    sprite{},
+    mouse_l{},
+    mouse_r{},
+
+    scoreboardtext{},
+    firstplacetext{},
+    startmenutext{},
+    quittext{},
+
+    font{},
+    
+    data{}                             
 {
     data = std::move(params);
     texture.loadFromFile(data["scoreboard_menu"]["texture"]);
@@ -180,6 +198,8 @@ void Scoreboard_menu::handle_input(sf::Event& event)
                 break; 
             }
             break;
+        default:
+            break;
         }
         break;
     case sf::Event::KeyPressed:
index e5c4b85b840feab696a2dadf3a474de2f93979fb..1531c519bcf96c6e9b2ec1d7f402f7e87601a96e 100644 (file)
@@ -8,8 +8,27 @@
 using json = nlohmann::json;
 
 
-Start_menu::Start_menu(json& params) : texture{},  texture2{}, sprite{}, mouse_l{}, mouse_r{}, starttext{}, scoreboardtext{},
-                           quittext{}, font{}, start_game{false}, exit_game{false}, scoreboard{false}, menu_index{1}, data{}
+Start_menu::Start_menu(json& params) :
+    start_game{false},
+    exit_game{false},
+    scoreboard{false},
+    
+    menu_index{1},
+
+    texture{},
+    texture2{},
+
+    sprite{},
+    mouse_l{},
+    mouse_r{},
+
+    starttext{},
+    scoreboardtext{},
+    quittext{},
+
+    font{},
+
+    data{}
 {   
     data = std::move(params);
                 
@@ -176,6 +195,8 @@ void Start_menu::handle_input(sf::Event& event)
                 break; 
             }
             break;
+        default:
+            break;
         }
         break;
     case sf::Event::KeyPressed:
index 6063c652647858cf01fff133339a36c24402ec37..65b46ebfd2ef0a9565c8010e3f7fb5f4ae75be99 100644 (file)
@@ -9,24 +9,29 @@
 
 using json = nlohmann::json;
 
-Game_state::Game_state(json& params) : 
-    game_map{}, 
-    pause_game{false},
-    player{},
+Game_state::Game_state(json& params) :
     bottles{}, 
-    helper{},
-    bike{},
+
     time_since_last_bottle{0.0f},
     game_time{0},
     time_since_last_yf{0.0f},
     time_since_last_bike{0.0f},
+    points{0},
+
+    pause_game{false},
+
+    game_map{}, 
+    player{},
+    helper{},
+    enemy{},
+    yf{},
+    bike{},
+
     bottle_texture {},
     YF_texture {},
     bike_texture{},
-    yf{},
-    data{},
-    enemy{},
-    points{0}
+
+    data{}
 {
     data = std::move(params);
     sf::Texture main_enemy_texture;
@@ -73,59 +78,79 @@ void Game_state::update(Context &context)
         return;
     }
     
+    // Update player and helper
 
-    for (unsigned int i {0}; i < bottles.size(); ++i)
-    {
-        if (enemy->collides(*(bottles[i])))
-        {
-            
-            bottles.erase(bottles.begin() + i);
-            
-        }
-        else if (player->collides(*(bottles[i])))
-        {
-            bottles.erase(bottles.begin() + i);
-            player->add_collected();
-        }
-    }
-    
     player->update(context);
     helper->update(context);
 
+    // Handle collision
+
     if (player->collides(*helper))
     {
         points += player->get_collected() + floor(player->get_collected() / static_cast<float>(data["game_constants"]["point_scale_div"]));
         player->zero_collected();
 
-        player->collision(*helper);
-        helper->collision(*player);
+        player->collision_helper();
+        helper->collision_player();
     }
     if (player->collides(*enemy))
     {
-        enemy->collision(*player);
+        enemy->collision_player();
+        player->collision_enemy();
     }
+
     if(yf != nullptr)
     {    
         if (player->collides(*yf))
         {
             player->zero_collected();
-            player->collision(*yf);
+
+            player->collision_yf();
+            yf->collision_player();
         }
         if(enemy->collides(*yf))
         {
-            enemy->collision(*yf);
+            enemy->collision_yf();
+            yf->collision_enemy();
         }
     }
+
     if(bike != nullptr)
     {    
         if (player->collides(*bike))
         {
             player->zero_collected();
-            player->collision(*bike);
+
+            player->collision_bike();
+            bike->collision_player();
         }
         if(enemy->collides(*bike))
         {
-            enemy->collision(*bike);
+            enemy->collision_bike();
+            bike->collision_enemy();
+        }
+    }
+
+    if(game_map->collides(*player))
+    {
+        player->collision_map();
+        game_map->collision_player();
+    }
+
+    // Collect bottles
+
+    for (unsigned int i {0}; i < bottles.size(); ++i)
+    {
+        if (enemy->collides(*(bottles[i])))
+        {
+            
+            bottles.erase(bottles.begin() + i);
+            
+        }
+        else if (player->collides(*(bottles[i])))
+        {
+            bottles.erase(bottles.begin() + i);
+            player->add_collected();
         }
     }
     
@@ -159,10 +184,6 @@ void Game_state::update(Context &context)
     {
         bike->update(context);
     }
-    if(game_map->collides(*player))
-    {
-        player->collision(*game_map);
-    }
 }
 
 void Game_state::render(sf::RenderWindow &window) const
index 8e97c34315666263ba4e4f1f4720f09673ddc724..77f8bd31029b5eace36b43f4a26697f8b601bb49 100644 (file)
@@ -43,6 +43,9 @@ private:
     float game_time;
     float time_since_last_yf;
     float time_since_last_bike;
+    int points;
+
+    bool pause_game;
     
     std::unique_ptr<Map> game_map;
     std::unique_ptr<Player> player;
@@ -51,12 +54,11 @@ private:
     std::unique_ptr<YF> yf;
     std::unique_ptr<Bike_enemy> bike;
 
-    bool pause_game;
     sf::Texture bottle_texture;
     sf::Texture YF_texture;
     sf::Texture bike_texture;
+
     json data;
-    int points;
 };
 
 class Start_menu : public State
@@ -69,22 +71,26 @@ public:
     void handle_input(sf::Event& event) override;
 
 private:
+    bool start_game;
+    bool exit_game;
+    bool scoreboard;
+
+    int menu_index;
+    
     sf::Texture texture;
     sf::Texture texture2;
+
     sf::Sprite sprite;
     sf::Sprite mouse_l;
     sf::Sprite mouse_r;
+
     sf::Text starttext;
     sf::Text scoreboardtext;
     sf::Text quittext;
+
     sf::Font font;
 
-    bool start_game;
-    bool exit_game;
-    bool scoreboard;
     json data;
-
-    int menu_index;
 };
 
 class Pause_menu : public State
@@ -96,22 +102,26 @@ public:
     void render(sf::RenderWindow& window) const override;
     void handle_input(sf::Event& event) override;
 private:
+    int menu_index;
+
+    bool resume_game;
+    bool exit_game;
+    bool menu;
+
     sf::Texture texture;
     sf::Texture texture2;
+
     sf::Sprite sprite;
     sf::Sprite mouse_l;
     sf::Sprite mouse_r;
+
     sf::Text resumetext;
     sf::Text startmenutext;
     sf::Text quittext;
+    
     sf::Font font;
 
-    bool resume_game;
-    bool exit_game;
-    bool menu;
     json data;
-
-    int menu_index;
 };
 
 
@@ -123,22 +133,27 @@ public:
     void update(Context& context) override;
     void render(sf::RenderWindow& window) const override;
     void handle_input(sf::Event& event) override;
-private:
+private: 
+    int menu_index;
+
+    bool exit_game;
+    bool menu;
+
     sf::Texture texture;
     sf::Texture texture2;
+
     sf::Sprite sprite;
     sf::Sprite mouse_l;
     sf::Sprite mouse_r;
+
     sf::Text scoreboardtext;
     sf::Text firstplacetext;
     sf::Text startmenutext;    
     sf::Text quittext;
+
     sf::Font font;
 
-    bool exit_game;
-    bool menu;
     json data;
-    int menu_index;
 };
 
 
@@ -150,16 +165,26 @@ public:
     void update(Context& context) override;
     void render(sf::RenderWindow& window) const override;
     void handle_input(sf::Event& event) override;
-    void load_to_csv(sf::Text playerText);
+    void load_to_csv();
 
 private:
+    int menu_index;
+    int points;
+
+    bool exit_game;
+    bool menu;
+
     sf::Texture texture;
     sf::Texture texture2;
+
     sf::Sprite sprite;
-    sf::CircleShape rectangle;
     sf::Sprite mouse_l;
     sf::Sprite mouse_r;
+
+    sf::CircleShape rectangle;
+
     sf::String playerInput;
+
     sf::Text playerText;
     sf::Text linetext;
     sf::Text funfacttext;
@@ -167,13 +192,10 @@ private:
     sf::Text pointstext;
     sf::Text savetext;    
     sf::Text quittext;
+
     sf::Font font;
 
-    bool exit_game;
-    bool menu;
     json data;
-    int menu_index;
-    int points;
 };
 
 
index 803ed255423d62a1b1ec136f6aaa9ec22fb052a6..831812b4a727618b84d2ffc37ab4472306bc5968 100644 (file)
--- a/src/YF.cc
+++ b/src/YF.cc
@@ -3,13 +3,14 @@
 #include "YF.h"
 #include "constants.h"
 #include "Context.h"
+#include "States.h"
 
 YF::YF(sf::Texture& txtr, json& params) : max_speed{params["max_speed"]}
 {
     texture = txtr;
     sprite.setTexture(texture);
     //position = {500, 500};
-    position ={rand()%(S_WIDTH*5/7 - S_WIDTH/5 +1) + S_WIDTH/5, S_HEIGHT}; //x-pixel WIDTH/5 - WIDTH*5/7
+    position ={rand()%static_cast<int>(S_WIDTH*5/7.0f - S_WIDTH/5.0f +1) + S_WIDTH/5.0f, S_HEIGHT}; //x-pixel WIDTH/5 - WIDTH*5/7
     //sprite.setScale(params["scale"][0], params["scale"][1]);
     sprite.setScale(params["scale"][0],params["scale"][1]);
     sf::FloatRect gb {sprite.getGlobalBounds()};
@@ -19,14 +20,16 @@ YF::YF(sf::Texture& txtr, json& params) : max_speed{params["max_speed"]}
 
 }
 
+void YF::collision_player() 
+{}
 
-void YF::collision(Object &other) 
-{
+void YF::collision_enemy()
+{}
 
-}
 void YF::update(Context& context)
 {
-    //Game_state* game = static_cast<Game_state*>(context.current_state.get());
+    static_cast<Game_state*>(context.current_state.get());
+    
     position += direction*max_speed;
     sprite.setPosition(position);
 }
index 97f4e71676fd6b0678bd5b77fd44b6e5eaa8244d..340e43567115be6c6815e13c01d654f8aa9fdd30 100644 (file)
--- a/src/YF.h
+++ b/src/YF.h
@@ -14,7 +14,8 @@ class YF : public Moving_object
 public:
     YF(sf::Texture& txtr, json& params);
     ~YF() = default;
-    void collision(Object &other) override;
+    void collision_enemy();
+    void collision_player();
     void update(Context& context) override;
     void render(sf::RenderWindow &window) const override;