-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.h
111 lines (79 loc) · 2.01 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
* Player.h
*
* Created on: 4 maj 2010
* Author: meros
*/
#ifndef PLAYER_H_
#define PLAYER_H_
#include "IDrawable.h"
#include "IPositionable.h"
#include "Sprite.h"
#include "ContactListener.h"
#include "DummyDrawable.h"
#include <Box2D/Box2D.h>
#define PLAYER_USER_DATA "Player"
#include <SFML/Window.hpp>
class Player: public IDrawable,
public IPositionable,
public UserData,
public b2ContactFilter {
public:
Player(b2World& aWorld, float aXStartPos, float aYStartPos);
virtual ~Player();
void Update();
void Draw(sf::RenderTarget& aTarget, float aXScale, float aYScale,
float aXTranslate, float aYTranslate);
void SetPosition(float aX, float aY);
Point GetPosition();
protected:
void PostSolve(b2Contact* contact, const b2ContactImpulse* impulse);
void TouchedRope(Rope* aRope, b2Body* aBpdy);
private:
enum State {
STATE_MidAir, STATE_MidJump, STATE_Ground, STATE_Rope,
} myState;
bool myDirectionIsRight;
bool myIsBreaking;
int myTouchingGroundContacts;
int myTouchingRoofContacts;
float myDX;
float myDY;
b2Body* myCollisionBody;
bool myJumpBtnReleased;
float myJumpStartY;
Sprite myClimbRightSprite;
Sprite myClimbLeftSprite;
Sprite myStandRightSprite;
Sprite myBreakRightSprite;
Sprite myWalk1RightSprite;
Sprite myWalk2RightSprite;
Sprite myJumpRightSprite;
Sprite myStandLeftSprite;
Sprite myBreakLeftSprite;
Sprite myWalk1LeftSprite;
Sprite myWalk2LeftSprite;
Sprite myJumpLeftSprite;
int myAnimationCounter;
b2Body* myNewlyTouchedRopeBody;
Rope* myNewlyTouchedRope;
b2Joint* myRopeJoint;
Rope* myRope;
b2World& myWorld;
bool PrivDoJump() {
return sf::Keyboard::isKeyPressed(sf::Keyboard::Space);
}
bool PrivDoRight() {
return sf::Keyboard::isKeyPressed(sf::Keyboard::Right);
}
bool PrivDoLeft() {
return sf::Keyboard::isKeyPressed(sf::Keyboard::Left);
}
bool PrivDoUp() {
return sf::Keyboard::isKeyPressed(sf::Keyboard::Up);
}
bool PrivDoDown() {
return sf::Keyboard::isKeyPressed(sf::Keyboard::Down);
}
};
#endif /* PLAYER_H_ */