removed fullscreen bcs of (bed)bug, added testfile main
authorNilsForssen <forssennils@gmail.com>
Tue, 12 Dec 2023 13:38:17 +0000 (14:38 +0100)
committerNilsForssen <forssennils@gmail.com>
Tue, 12 Dec 2023 13:38:17 +0000 (14:38 +0100)
Makefile
assets/data.json
assets/highscore.csv
play
src/Player.cc
src/Player.h
src/_main.cc
src/_test.cc
test [new file with mode: 0755]

index 824b0c158491849491545c9debafd1d23b6c0747..06933f7b1d572f6f6ac68bb8101ae979195e0ce1 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -37,7 +37,7 @@ $(OBJDIR)/%.o: %.cc $(SRC_H)
 run:
        ./$(EXE)
 
-test:
+test_file:
        ./$(TEST)
 
 clean:
index 54adbb92df8af346bd10f977d914675dd8256d88..0696d3d4f133b9dd2fed6fb1e7ca3e206d53ec0c 100644 (file)
@@ -20,7 +20,8 @@
                 0.4
             ],
             "angle": -25
-        }
+        },
+        "speed_percentagae_per_bottle": 0.95
     },
     "helper": {
         "start_pos": [
@@ -87,7 +88,7 @@
             1.25,
             1.25
         ],
-        "max_speed": 4.5,
+        "max_speed": 4,
         "direction": [
             0,
             -1
index 70069afdfbde107c641ad14bf71c76c59fb03320..a16ed2ee0ddcb50b8a0cad7b17b675659d2f21b0 100644 (file)
@@ -1,5 +1,5 @@
 NissePisse is KING, 51
 Lukas IS king, 50
-NissePisse, 30
-, 25
-arre, 15
+ddddssss, 39
+Nissemedcash, 39
+erra, 37
diff --git a/play b/play
index 8770e09ac3ec158863f92fc406ec040093f79844..8a6dfa9cbff7f342471512ff642903369dd3baf7 100755 (executable)
Binary files a/play and b/play differ
index 4ef8b168845aa2a6da2f35a7ffdccae8afee2a2b..db137668fadbd118c2ff0b55dcd3d8490dd2633b 100644 (file)
@@ -3,13 +3,13 @@
 #include "Player.h"
 #include "Context.h"
 #include "constants.h"
-#include <iostream>
 
 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"]},
+    speed_percentage_per_bottle{params["speed_percentagae_per_bottle"]},
 
     tumbling{false},
 
@@ -162,7 +162,7 @@ void Player::handle_input(sf::Event& event)
 void Player::add_collected()
 {
     collected += 1;
-    max_speed *= 0.9;
+    max_speed *= speed_percentage_per_bottle;
 }
 
 int Player::get_collected()
@@ -172,8 +172,7 @@ int Player::get_collected()
 
 void Player::zero_collected()
 {
-    std::cout << max_speed << std::endl;
-    max_speed /= pow(0.9, collected);
+    max_speed /= pow(speed_percentage_per_bottle, collected);
     
     collected = 0;
 }
index 76b362d1e75b9a36ce603c6b24f2adf255fd304b..74b0d83ff9f70785feea4c6539c62fd225f9fff8 100644 (file)
@@ -40,12 +40,15 @@ private:
     int rotation; 
     float tumble_degrees;
     float max_speed;
+    float speed_percentage_per_bottle;
 
     bool tumbling;
     
     sf::Sprite sack;
     sf::Texture sack_texture;
-    sf::Vector2f sack_offset; 
+    sf::Vector2f sack_offset;
+
+    
 };
 
 #endif
\ No newline at end of file
index 9322f3f548785919613a9cfc5a77061c74432f91..390b107a844fa693350aaedbfbd4be6bd7c78db7 100644 (file)
@@ -21,8 +21,8 @@ int main ()
 {
     sf::RenderWindow window{
         sf::VideoMode{S_WIDTH, S_HEIGHT}, 
-        "DespYrat",
-        sf::Style::Fullscreen
+        "DespYrat"
+        //sf::Style::Fullscreen
     };
     //skapar en start meny
     Context game_context{};
index 9a3c50f1e45d5a9b32ca525301d81045ef520689..6914104ac30d7fdd812821c5a242d727b942c8a7 100644 (file)
@@ -21,75 +21,60 @@ using json = nlohmann::json;
 
 TEST_CASE("functions")
 {
-    SECTION("Start_menu")
+    SECTION("Helper")
     {
         Context game_context{};
 
         std::ifstream f("assets/data_test.json");
         json test_data = json::parse(f);
-        game_context.current_state = std::make_unique<Start_menu>(test_data);
         f.close();
 
         sf::Texture helper_texture;
         helper_texture.loadFromFile(test_data["game_state_assets"]["helper_file"]);
-        Helper helper {helper_texture, test_data["helper"]};
-        CHECK(helper.get_hitbox().getPosition().x == 989.33502f);
-        CHECK(helper.get_hitbox().getPosition().y == 37.94f);
-        helper.update(game_context);
-        CHECK_FALSE(helper.get_hitbox().getPosition().x == 1000);
-        CHECK_FALSE(helper.get_hitbox().getPosition().y == 50);
+        std::unique_ptr<Helper> helper = std::make_unique<Helper>(helper_texture, test_data["helper"]);
+
+        CHECK(helper->get_hitbox().left == 989.33502f);
+        CHECK(helper->get_hitbox().top == 37.94f);
+
+        helper->update(game_context);
+
+        CHECK_FALSE(helper->get_hitbox().left == 989.33502f);
+        CHECK_FALSE(helper->get_hitbox().top == 37.94f);
+
+        helper->collision_player();
 
+        CHECK(helper->get_hitbox().left == 989.33502f);
+        CHECK(helper->get_hitbox().top == 37.94f);
 
+        CHECK_FALSE(helper.get() == nullptr);   
 
-        
+        delete helper.release();
+
+        CHECK(helper.get() == nullptr);
     }
-}
 
-    /*
-    SECTION("Default")
+    SECTION("State switching")
     {
+        Context game_context{};
+
+        std::ifstream f("assets/data_test.json");
+        json test_data = json::parse(f);
+        f.close();
+
+        game_context.current_state = std::make_unique<Start_menu>(test_data);
+
+        game_context.next_state = std::make_unique<Game_state>(test_data);
 
-        Stack empty {};
-        CHECK(empty.is_empty());
-        empty.push(89);
-        empty.push(5);
-        empty.push(3);
-        CHECK((empty.to_string() == "[3, 5, 89]"));
-     
-        Stack copy {empty};
-        CHECK(copy.to_string() == "[3, 5, 89]");
-        copy.push(8);
-        CHECK(copy.to_string() == "[8, 3, 5, 89]");
-        CHECK(empty.to_string() == "[3, 5, 89]");
-        copy = empty;
-        CHECK(empty.to_string() == "[3, 5, 89]");
-        CHECK(copy.to_string() == "[3, 5, 89]");
-        
-        
-        CHECK(empty.get_len() == 3);
-        CHECK(empty.get(2) == 89);
-        CHECK(empty.back() == 89);
-        empty.pop();
-        CHECK( empty.to_string() == "[5, 89]");
-        CHECK_FALSE(empty.is_empty());
-        empty.remove_last();
-        CHECK(empty.to_string() == "[5]");
-        CHECK(empty.front() == 5);
-        CHECK_FALSE(empty.front() == 7);
-        empty.~Stack();
-        CHECK(empty.is_empty());
-        CHECK(empty.get_len() == 0);
-        CHECK (empty.to_string() == "[]");
-        
-        CHECK_THROWS(empty.pop());
-        cout << empty.to_string() << "hej" << endl;
-        CHECK(empty.to_string() == "[]");
-        CHECK(empty.get_len() == 0);
-        CHECK_THROWS(empty.remove_last());
-        CHECK(empty.to_string() == "[]");
-        CHECK(empty.get_len() == 0);
-        empty.push(5);
-        cout << empty.to_string() << "hej" << endl;
-        CHECK(empty.to_string() == "[5]");
-    }*/
+        game_context.current_state = std::move(game_context.next_state);
+        game_context.next_state = nullptr;
 
+
+        CHECK_FALSE(game_context.current_state.get() == nullptr);
+        CHECK(game_context.next_state.get() == nullptr); 
+
+        delete game_context.current_state.release();
+
+        CHECK(game_context.current_state.get() == nullptr);
+        CHECK(game_context.next_state.get() == nullptr);
+    }
+}
\ No newline at end of file
diff --git a/test b/test
new file mode 100755 (executable)
index 0000000..52d8bb3
Binary files /dev/null and b/test differ