something changed
This commit is contained in:
+26
-18
@@ -14,16 +14,29 @@
|
||||
*
|
||||
* */
|
||||
|
||||
|
||||
// CollisionDir Entity::getCollisionDirection(const sf::FloatRect& a, const sf::FloatRect& b) {
|
||||
|
||||
Entity::Entity(sf::Vector2<float> size, sf::Vector2<float> starting_position, sf::Vector2f initial_velocity, float thickness, sf::Color inside_color, sf::Color border_color) {
|
||||
Entity::Entity(sf::Vector2<float> size, sf::Vector2<float> pos, sf::Vector2f velocity, float border_thickness, sf::Color inside_color, sf::Color border_color) {
|
||||
rect.setSize(size);
|
||||
rect.setPosition(starting_position);
|
||||
rect.setOutlineThickness(thickness); // Needs to be the same as floor height to be properly on the line; else it will just show up above the line or in the line
|
||||
rect.setPosition(pos);
|
||||
rect.setOutlineThickness(border_thickness);
|
||||
rect.setFillColor(inside_color);
|
||||
rect.setOutlineColor(border_color);
|
||||
velocity = initial_velocity;
|
||||
_velocity = velocity;
|
||||
}
|
||||
|
||||
void Entity::set_velocity(sf::Vector2<float> velocity) {
|
||||
_velocity = velocity;
|
||||
}
|
||||
|
||||
void Entity::set_velocity_x(int velocity) {
|
||||
_velocity.x = velocity;
|
||||
}
|
||||
|
||||
void Entity::set_velocity_y(int velocity) {
|
||||
_velocity.y = velocity;
|
||||
}
|
||||
|
||||
sf::Vector2<float> Entity::get_velocity() {
|
||||
return _velocity;
|
||||
}
|
||||
|
||||
CollisionDir Entity::find_intersection(Entity &entity) {
|
||||
@@ -53,25 +66,20 @@ CollisionDir Entity::find_intersection(Entity &entity) {
|
||||
}
|
||||
}
|
||||
|
||||
Player::Player(sf::Vector2<float> size, sf::Vector2<float> starting_position, float acceleration, float initial_acceleration, float thickness, sf::Vector2f initial_velocity, sf::Color inside_color, sf::Color border_color) : Entity(size, starting_position, initial_velocity, thickness, inside_color, border_color) {
|
||||
m_acceleration = acceleration;
|
||||
m_jump_strength = initial_acceleration;
|
||||
Player::Player(sf::Vector2<float> size, sf::Vector2<float> pos, sf::Vector2f velocity, float border_thickness, float gravity, float max_acceleration, sf::Color inside_color, sf::Color border_color) : Entity(size, pos, velocity, border_thickness, inside_color, border_color) {
|
||||
m_acceleration = gravity;
|
||||
m_jump_strength = max_acceleration;
|
||||
}
|
||||
|
||||
void Player::handle_movment() {
|
||||
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::D)) {
|
||||
rect.move({velocity.x, 0});
|
||||
rect.move({_velocity.x, 0});
|
||||
} if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::A)) {
|
||||
rect.move({-velocity.x, 0});
|
||||
rect.move({-_velocity.x, 0});
|
||||
}
|
||||
// if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::W)) {
|
||||
// rect.move({0, -2.5});
|
||||
// } if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::S)) {
|
||||
// rect.move({0, 2.5});
|
||||
// }
|
||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Space) && !m_jumping) {
|
||||
m_jumping = true;
|
||||
velocity.y = -m_jump_strength; // push up
|
||||
_velocity.y = -m_jump_strength; // push up
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user