#include "Context.h"
#include "constants.h"
-
-Player::Player(json& params) : collected{0}, max_speed{params["max_speed"]}/*, falling {false},
- rotation{params["degrees_per_second"]}, degrees{0}*/
+Player::Player(json& params) : collected{0}, max_speed{params["max_speed"]}, tumbling{false}, tumble_degrees{0}, rotation{params["degrees_per_second"]}
{
position = {params["start_pos"][0], params["start_pos"][1]};
sack_offset = {params["sack"]["offset"][0], params["sack"]["offset"][1]};
sack.rotate(params["sack"]["angle"]);
sack.setPosition(position + sack_offset);
-
}
move(false);
}
+void Player::collision(YF& yf)
+{
+ move(false);
+ tumbling = true;
+}
+
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());
- move();
- /*if(falling == true)
+
+ if(tumbling)
{
-
- degrees += rotation/FPS;
- sprite.rotate(degrees);
- falling = false;
- }*/
+ sprite.rotate(rotation/FPS);
+ tumble_degrees += rotation/FPS;
+ if (tumble_degrees >= 360)
+ {
+ tumbling = false;
+ tumble_degrees = 0;
+ direction = {0,0};
+ }
+ }
+ else
+ {
+ move();
+ }
}
void Player::move(bool forward)
void Player::handle_input(sf::Event& event)
{
//while (falling == false)
- //{
+ //{
+ if (!tumbling)
+ {
direction = {0,0};
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::W))
{
direction.x *= M_SQRT1_2;
direction.y *= M_SQRT1_2;
- }
+ }
+ }
+
//}
}
#include "Moving_object.h"
#include "json.hpp"
+#include "YF.h"
using json = nlohmann::json;
~Player() = default;
void collision(Object& other) override;
+ void collision(YF& yf);
void update(Context& context) override;
void render(sf::RenderWindow& window) const override;
void handle_input(sf::Event& event);
private:
void move(bool forward=true);
int collected;
- //float degrees;
- //float rotation;
+ float tumble_degrees;
+ int rotation;
float max_speed;
- //bool falling;
+ bool tumbling;
sf::Sprite sack;
sf::Texture sack_texture;
sf::Vector2f sack_offset; //{20, -30};