-
Notifications
You must be signed in to change notification settings - Fork 1
/
Player.h
73 lines (54 loc) · 1.36 KB
/
Player.h
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#pragma once
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <box2d/box2d.h>
#include "constants.h"
#include "GlobalContactListener.h"
#include "Enemy.h"
enum class PlayerState {
Idle = 0,
Move,
Jump,
};
class Player : public ContactListener
{
private:
sf::Texture _texture;
sf::Sprite* _sprite;
sf::SoundBuffer _buffer;
sf::Sound _sound;
b2Body* _body;
float _width = 32.0f;
float _height = 54.0f;
b2Vec2 _startingPosition;
bool _isJumping = false;
bool _isFalling = false;
bool _isWalking = false;
bool _isDucking = false;
bool _didJump = false;
b2Vec2 _velocity{ 0.0f , 0.0f };
float _moveSpeed = 10.0f;
float _stateTime = 0.0f;
float _frame = 0.0f;
PlayerState _state = PlayerState::Idle;
bool _onGround = false;
bool _death = false;
bool _onRoof = false;
FixtureData _fixtureData;
b2Fixture* _groundFixture;
b2Fixture* _spikeFixture;
b2Fixture* _rightEnemyFixture;
b2Fixture* _leftEnemyFixture;
b2Fixture* _topFixture;
public:
Player(b2World& world, b2Vec2 position);
~Player();
sf::Vector2f getPosition();
void update();
void render(sf::RenderWindow& window);
void cmd();
void drawFixture(b2Fixture* fixture, sf::RenderWindow& window, sf::Color color);
bool isDead();
virtual void onBeginContact(b2Fixture* self, b2Fixture* other) override;
virtual void onEndContact(b2Fixture* self, b2Fixture* other) override;
};