#include "constants.h"
-Player::Player(json& params) : collected{0}, max_speed{params["max_speed"]}
+Player::Player(json& params) : collected{0}, max_speed{params["max_speed"]}/*, falling {false},
+ rotation{params["degrees_per_second"]}, degrees{0}*/
{
position = {params["start_pos"][0], params["start_pos"][1]};
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)
+ {
+
+ degrees += rotation/FPS;
+ sprite.rotate(degrees);
+ falling = false;
+ }*/
}
void Player::move(bool forward)
void Player::handle_input(sf::Event& event)
{
- direction = {0,0};
+ //while (falling == false)
+ //{
+ direction = {0,0};
- if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::W))
- {
- direction.y -= 1;
- }
- if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::S))
- {
- direction.y += 1;
- }
- if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::D))
- {
- direction.x += 1;
- }
- if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::A))
- {
- direction.x -= 1;
- }
+ if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::W))
+ {
+ direction.y -= 1;
+ }
+ if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::S))
+ {
+ direction.y += 1;
+ }
+ if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::D))
+ {
+ direction.x += 1;
+ }
+ if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::A))
+ {
+ direction.x -= 1;
+ }
- // If the vector is diagonal, normalize its length
- if (abs(direction.x) + abs(direction.y) == 2)
- {
- direction.x *= M_SQRT1_2;
- direction.y *= M_SQRT1_2;
- }
+ // If the vector is diagonal, normalize its length
+ if (abs(direction.x) + abs(direction.y) == 2)
+ {
+ direction.x *= M_SQRT1_2;
+ direction.y *= M_SQRT1_2;
+ }
+
+ //}
}
void Player::add_collected()
void Player::zero_collected()
{
collected = 0;
-}
\ No newline at end of file
+}
+/*void Player::tumble()
+{
+ falling = true;
+}*/
\ No newline at end of file
player->collision(*helper);
helper->collision(*player);
}
+ if(yf.size()>0)
+ {
+ if (player->collides(*yf[0]))
+ {
+ player->zero_collected();
+ player->collision(*yf[0]);
+
+ //player->tumble();
+
+ }
+ }
+
/*
if (player->get_x() < 0) player->set_x(0);
if (player->get_x() > S_WIDTH) player->set_x(S_WIDTH);