1 /*
2     Copyright (C) 2002-2005, Jason Katz-Brown <jasonkb@mit.edu>
3     Copyright 2010 Stefan Majewsky <majewsky@gmx.net>
4 
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9 
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14 
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18 */
19 
20 #ifndef KOLF_BALL_H
21 #define KOLF_BALL_H
22 
23 #include "canvasitem.h"
24 
25 
26 enum BallState { Rolling = 0, Stopped, Holed };
27 
28 class Ball : public EllipticalCanvasItem
29 {
30 public:
31 	Ball(QGraphicsItem* parent, b2World* world);
32 
33 	BallState currentState();
34 
35 	void moveBy(double dx, double dy) override;
36 
curState()37 	BallState curState() const { return state; }
38 	void setState(BallState newState);
39 
color()40 	QColor color() const { return ellipseItem()->brush().color(); }
setColor(const QColor & color)41 	void setColor(const QColor& color) { ellipseItem()->setBrush(color); }
42 
setFrictionMultiplier(double news)43 	void setFrictionMultiplier(double news) { frictionMultiplier = news; }
44 	void friction();
45 	void collisionDetect();
46 
addStroke()47 	int addStroke() const { return m_addStroke; }
placeOnGround(Vector & v)48 	bool placeOnGround(Vector &v) { v = m_pogOldVelocity; return m_placeOnGround; }
setAddStroke(int newStrokes)49 	void setAddStroke(int newStrokes) { m_addStroke = newStrokes; }
setPlaceOnGround(bool placeOnGround)50 	void setPlaceOnGround(bool placeOnGround) { m_placeOnGround = placeOnGround; m_pogOldVelocity = velocity(); }
51 
beginningOfHole()52 	bool beginningOfHole() const { return m_beginningOfHole; }
setBeginningOfHole(bool yes)53 	void setBeginningOfHole(bool yes) { m_beginningOfHole = yes; }
54 
forceStillGoing()55 	bool forceStillGoing() const { return m_forceStillGoing; }
setForceStillGoing(bool yes)56 	void setForceStillGoing(bool yes) { m_forceStillGoing = yes; }
57 
shotStarted()58 	void shotStarted() override { maxBumperBounceSpeed = 8; }
59 
setDoDetect(bool yes)60 	void setDoDetect(bool yes) { m_doDetect = yes; }
doDetect()61 	bool doDetect() const { return m_doDetect; }
62 
63 	QList<QGraphicsItem*> infoItems() const override;
64 	virtual void setName(const QString &);
65 	virtual void setVisible(bool yes);
66 
getMaxBumperBounceSpeed()67 	double getMaxBumperBounceSpeed() { return maxBumperBounceSpeed; }
reduceMaxBumperBounceSpeed()68 	void reduceMaxBumperBounceSpeed() { if(maxBumperBounceSpeed > 0.4) maxBumperBounceSpeed -= 0.35; }
69 
70 public Q_SLOTS:
update()71 	void update() { }
72 
73 protected:
74 	Kolf::Overlay* createOverlay() override;
75 	void endSimulation() override;
76 
77 private:
78 	BallState state;
79 
80 	int m_collisionId;
81 	double frictionMultiplier;
82 
83 	//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
84 	double maxBumperBounceSpeed;
85 
86 	int m_addStroke;
87 	bool m_placeOnGround;
88 	Vector m_pogOldVelocity;
89 
90 	bool m_beginningOfHole;
91 	bool m_forceStillGoing;
92 
93 	bool m_doDetect;
94 
95 	QGraphicsSimpleTextItem *label;
96 };
97 
98 #endif
99