-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.cpp
28 lines (23 loc) · 821 Bytes
/
Player.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include "Player.hpp"
#include <iostream>
Player::Player(b2World& world, float x, float y, sf::Texture& texture)
: GameObject(world, x, y, texture, 0.1, b2_dynamicBody)
{
b2MassData mass{5, physicalBody->GetLocalCenter(), physicalBody->GetInertia()};
physicalBody->SetMassData(&mass);
}
void Player::moveLeft()
{
if (physicalBody->GetLinearVelocity().x > -maxSpeed)
physicalBody->ApplyForce(b2Vec2(-force, 0), physicalBody->GetWorldCenter());
}
void Player::moveRight()
{
if (physicalBody->GetLinearVelocity().x < maxSpeed)
physicalBody->ApplyForce(b2Vec2(force, 0), physicalBody->GetWorldCenter());
}
void Player::jump()
{
float impulse = -physicalBody->GetMass() * 3.5;
physicalBody->ApplyLinearImpulse(b2Vec2(0,impulse), physicalBody->GetWorldCenter() );
}