#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},
void Player::add_collected()
{
collected += 1;
- max_speed *= 0.9;
+ max_speed *= speed_percentage_per_bottle;
}
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;
}
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