File indexing completed on 2024-05-12 04:04:30

0001 /*
0002     Copyright (C) 2002-2005, Jason Katz-Brown <jasonkb@mit.edu>
0003     Copyright 2010 Stefan Majewsky <majewsky@gmx.net>
0004 
0005     This program is free software; you can redistribute it and/or modify
0006     it under the terms of the GNU General Public License as published by
0007     the Free Software Foundation; either version 2 of the License, or
0008     (at your option) any later version.
0009 
0010     This program is distributed in the hope that it will be useful,
0011     but WITHOUT ANY WARRANTY; without even the implied warranty of
0012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013     GNU General Public License for more details.
0014 
0015     You should have received a copy of the GNU General Public License
0016     along with this program; if not, write to the Free Software
0017     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
0018 */
0019 
0020 #ifndef KOLF_BALL_H
0021 #define KOLF_BALL_H
0022 
0023 #include "canvasitem.h"
0024 
0025 
0026 enum BallState { Rolling = 0, Stopped, Holed };
0027 
0028 class Ball : public EllipticalCanvasItem
0029 {
0030 public:
0031     Ball(QGraphicsItem* parent, b2World* world);
0032 
0033     BallState currentState();
0034 
0035     void moveBy(double dx, double dy) override;
0036 
0037     BallState curState() const { return state; }
0038     void setState(BallState newState);
0039 
0040     QColor color() const { return ellipseItem()->brush().color(); }
0041     void setColor(const QColor& color) { ellipseItem()->setBrush(color); }
0042 
0043     void setFrictionMultiplier(double news) { frictionMultiplier = news; }
0044     void friction();
0045     void collisionDetect();
0046 
0047     int addStroke() const { return m_addStroke; }
0048     bool placeOnGround(Vector &v) { v = m_pogOldVelocity; return m_placeOnGround; }
0049     void setAddStroke(int newStrokes) { m_addStroke = newStrokes; }
0050     void setPlaceOnGround(bool placeOnGround) { m_placeOnGround = placeOnGround; m_pogOldVelocity = velocity(); }
0051 
0052     bool beginningOfHole() const { return m_beginningOfHole; }
0053     void setBeginningOfHole(bool yes) { m_beginningOfHole = yes; }
0054 
0055     bool forceStillGoing() const { return m_forceStillGoing; }
0056     void setForceStillGoing(bool yes) { m_forceStillGoing = yes; }
0057 
0058     void shotStarted() override { maxBumperBounceSpeed = 8; }
0059 
0060     void setDoDetect(bool yes) { m_doDetect = yes; }
0061     bool doDetect() const { return m_doDetect; }
0062 
0063     QList<QGraphicsItem*> infoItems() const override;
0064     virtual void setName(const QString &);
0065     virtual void setVisible(bool yes);
0066 
0067     double getMaxBumperBounceSpeed() { return maxBumperBounceSpeed; }
0068     void reduceMaxBumperBounceSpeed() { if(maxBumperBounceSpeed > 0.4) maxBumperBounceSpeed -= 0.35; }
0069 
0070 public Q_SLOTS:
0071     void update() { }
0072 
0073 protected:
0074     Kolf::Overlay* createOverlay() override;
0075     void endSimulation() override;
0076 
0077 private:
0078     BallState state;
0079 
0080     int m_collisionId;
0081     double frictionMultiplier;
0082 
0083     //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
0084     double maxBumperBounceSpeed;
0085 
0086     int m_addStroke;
0087     bool m_placeOnGround;
0088     Vector m_pogOldVelocity;
0089 
0090     bool m_beginningOfHole;
0091     bool m_forceStillGoing;
0092 
0093     bool m_doDetect;
0094 
0095     QGraphicsSimpleTextItem *label;
0096 };
0097 
0098 #endif