-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDesk.hpp
103 lines (85 loc) · 2.75 KB
/
Desk.hpp
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
#include "Ball.hpp"
#include "HumanPlayer.hpp"
#include <iostream>
#include <SFML/Graphics.hpp>
#define IDLE_STATE 0
#define PLAY_STATE 1
#define GAME_FINISHED 2
class Desk
{
private:
int windowWidth;
int windowHeight;
sf::RectangleShape sf_stick;
sf::CircleShape sf_ball;
int state;
public:
Desk(int inputDeskX, int inputDeskY){
windowWidth = inputDeskX;
windowHeight = inputDeskY;
state = PLAY_STATE;
}
int getDeskState(){
return state;
}
void drawStickFirstTime(HumanPlayer& _humanPlayer){
// called once
sf_stick.setFillColor(sf::Color::Blue);
sf_stick.setSize(sf::Vector2f(10, _humanPlayer.getStick().getStickLength() / 100.0 * windowHeight));
sf_stick.setPosition(
10,
_humanPlayer.getStick().getStickPosition() / 100.0 * windowHeight
);
}
void redrawStick(HumanPlayer& _humanPlayer){
sf_stick.setPosition(
10,
_humanPlayer.getStick().getStickPosition() / 100.0 * windowHeight
);
}
void drawBallFirstTime(Ball& _ball){
// called once
sf_ball.setFillColor(sf::Color::Blue);
sf_ball.setRadius(_ball.getBallRadius() / 100 * windowHeight);
sf_ball.setPosition(_ball.getPositionX() / 100 * windowWidth, _ball.getPositionY() / 100 * windowHeight);
}
void redrawBall(Ball& _ball){
sf_ball.setPosition(
_ball.getPositionX() / 100 * windowWidth,
_ball.getPositionY() / 100 * windowHeight
);
sf_ball.setRadius(_ball.getBallRadius() / 100 * windowHeight);
}
sf::RectangleShape& getSFStick(){
return sf_stick;
}
sf::CircleShape& getSFBall(){
return sf_ball;
}
// moves ball based on its speed
void oneFrameBallAction(Ball& _ball){
float bSpeedY = _ball.getSpeedY();
if (bSpeedY > 0 )
{
if (_ball.canMoveUp())
{
_ball.moveYPos();
}
if (_ball.touchingWallBelow()){
_ball.revertSpeedY();
}
}
else if (bSpeedY < 0)
{
if (_ball.canMoveDown()){
_ball.moveYNeg();
}
if (_ball.touchingWallAbove()){
_ball.revertSpeedY();
}
}
else {
std::cout << "[ERR]: ball speed 0" << std::endl;
}
}
};