-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathball.cpp
45 lines (36 loc) · 867 Bytes
/
ball.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "ball.h"
Ball::Ball(Ball::Color theColor) :
color(theColor),
state(JustCreated),
locked(false)
{}
bool Ball::advance()
{
Ball::State lastState = state;
// If there is a position to stop
if (!stopPositions.empty())
{
// Change the state
state = SystemMoving;
// Change the position
position = stopPositions[stopPositions.size() - 1];
// Delete the position in the vector
stopPositions.pop_back();
// Currently not used, may be used later to speed up
// if (stopPositions.size() < 2)
// state = AlmostStable;
// Change the state
if (stopPositions.size() == 0)
state = Stable;
}
return state != lastState;
}
void Ball::moveToStablePos()
{
if (!stopPositions.empty())
{
position = stopPositions[0];
stopPositions.clear();
}
state = Stable;
}