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
26enum BallState { Rolling = 0, Stopped, Holed };
27
28class Ball : public EllipticalCanvasItem
29{
30public:
31 Ball(QGraphicsItem* parent, b2World* world);
32
33 BallState currentState();
34
35 virtual void moveBy(double dx, double dy);
36
37 BallState curState() const { return state; }
38 void setState(BallState newState);
39
40 QColor color() const { return ellipseItem()->brush().color(); }
41 void setColor(const QColor& color) { ellipseItem()->setBrush(color); }
42
43 void setFrictionMultiplier(double news) { frictionMultiplier = news; }
44 void friction();
45 void collisionDetect();
46
47 int addStroke() const { return m_addStroke; }
48 bool placeOnGround(Vector &v) { v = m_pogOldVelocity; return m_placeOnGround; }
49 void setAddStroke(int newStrokes) { m_addStroke = newStrokes; }
50 void setPlaceOnGround(bool placeOnGround) { m_placeOnGround = placeOnGround; m_pogOldVelocity = velocity(); }
51
52 bool beginningOfHole() const { return m_beginningOfHole; }
53 void setBeginningOfHole(bool yes) { m_beginningOfHole = yes; }
54
55 bool forceStillGoing() const { return m_forceStillGoing; }
56 void setForceStillGoing(bool yes) { m_forceStillGoing = yes; }
57
58 void shotStarted() { maxBumperBounceSpeed = 8; }
59
60 void setDoDetect(bool yes) { m_doDetect = yes; }
61 bool doDetect() const { return m_doDetect; }
62
63 virtual QList<QGraphicsItem*> infoItems() const;
64 virtual void setName(const QString &);
65 virtual void setVisible(bool yes);
66
67 double getMaxBumperBounceSpeed() { return maxBumperBounceSpeed; }
68 void reduceMaxBumperBounceSpeed() { if(maxBumperBounceSpeed > 0.4) maxBumperBounceSpeed -= 0.35; }
69
70public slots:
71 void update() { }
72
73protected:
74 virtual Kolf::Overlay* createOverlay();
75 virtual void endSimulation();
76
77private:
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