-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathball.h
98 lines (68 loc) · 2.97 KB
/
ball.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
/*
Copyright (C) 2002-2005, Jason Katz-Brown <[email protected]>
Copyright 2010 Stefan Majewsky <[email protected]>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef KOLF_BALL_H
#define KOLF_BALL_H
#include "canvasitem.h"
enum BallState { Rolling = 0, Stopped, Holed };
class Ball : public EllipticalCanvasItem
{
public:
Ball(QGraphicsItem* parent, b2World* world);
BallState currentState();
void moveBy(double dx, double dy) override;
BallState curState() const { return state; }
void setState(BallState newState);
QColor color() const { return ellipseItem()->brush().color(); }
void setColor(const QColor& color) { ellipseItem()->setBrush(color); }
void setFrictionMultiplier(double news) { frictionMultiplier = news; }
void friction();
void collisionDetect();
int addStroke() const { return m_addStroke; }
bool placeOnGround(Vector &v) { v = m_pogOldVelocity; return m_placeOnGround; }
void setAddStroke(int newStrokes) { m_addStroke = newStrokes; }
void setPlaceOnGround(bool placeOnGround) { m_placeOnGround = placeOnGround; m_pogOldVelocity = velocity(); }
bool beginningOfHole() const { return m_beginningOfHole; }
void setBeginningOfHole(bool yes) { m_beginningOfHole = yes; }
bool forceStillGoing() const { return m_forceStillGoing; }
void setForceStillGoing(bool yes) { m_forceStillGoing = yes; }
void shotStarted() override { maxBumperBounceSpeed = 8; }
void setDoDetect(bool yes) { m_doDetect = yes; }
bool doDetect() const { return m_doDetect; }
QList<QGraphicsItem*> infoItems() const override;
virtual void setName(const QString &);
virtual void setVisible(bool yes);
double getMaxBumperBounceSpeed() { return maxBumperBounceSpeed; }
void reduceMaxBumperBounceSpeed() { if(maxBumperBounceSpeed > 0.4) maxBumperBounceSpeed -= 0.35; }
public Q_SLOTS:
void update() { }
protected:
Kolf::Overlay* createOverlay() override;
void endSimulation() override;
private:
BallState state;
int m_collisionId;
double frictionMultiplier;
//the maximum speed of the ball after hitting a bumper, this will decrease ith each bounce so that the ball does not bounce against bumpers forever
double maxBumperBounceSpeed;
int m_addStroke;
bool m_placeOnGround;
Vector m_pogOldVelocity;
bool m_beginningOfHole;
bool m_forceStillGoing;
bool m_doDetect;
QGraphicsSimpleTextItem *label;
};
#endif