From: NilsForssen Date: Tue, 12 Dec 2023 13:38:17 +0000 (+0100) Subject: removed fullscreen bcs of (bed)bug, added testfile X-Git-Url: https://gitweb.forssennils.se/?a=commitdiff_plain;ds=sidebyside;p=TDDC76_proj.git removed fullscreen bcs of (bed)bug, added testfile --- diff --git a/Makefile b/Makefile index 824b0c1..06933f7 100644 --- a/Makefile +++ b/Makefile @@ -37,7 +37,7 @@ $(OBJDIR)/%.o: %.cc $(SRC_H) run: ./$(EXE) -test: +test_file: ./$(TEST) clean: diff --git a/assets/data.json b/assets/data.json index 54adbb9..0696d3d 100644 --- a/assets/data.json +++ b/assets/data.json @@ -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 diff --git a/assets/highscore.csv b/assets/highscore.csv index 70069af..a16ed2e 100644 --- a/assets/highscore.csv +++ b/assets/highscore.csv @@ -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 8770e09..8a6dfa9 100755 Binary files a/play and b/play differ diff --git a/src/Player.cc b/src/Player.cc index 4ef8b16..db13766 100644 --- a/src/Player.cc +++ b/src/Player.cc @@ -3,13 +3,13 @@ #include "Player.h" #include "Context.h" #include "constants.h" -#include 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; } diff --git a/src/Player.h b/src/Player.h index 76b362d..74b0d83 100644 --- a/src/Player.h +++ b/src/Player.h @@ -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 diff --git a/src/_main.cc b/src/_main.cc index 9322f3f..390b107 100644 --- a/src/_main.cc +++ b/src/_main.cc @@ -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{}; diff --git a/src/_test.cc b/src/_test.cc index 9a3c50f..6914104 100644 --- a/src/_test.cc +++ b/src/_test.cc @@ -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(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 = std::make_unique(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(test_data); + + game_context.next_state = std::make_unique(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 index 0000000..52d8bb3 Binary files /dev/null and b/test differ