Ver código fonte

Fixed sound effects

Daniel 5 anos atrás
pai
commit
4413668145
7 arquivos alterados com 9 adições e 10 exclusões
  1. 3
    4
      Classes.h
  2. 1
    0
      README.md
  3. 5
    5
      functions.cpp
  4. BIN
      functions.o
  5. BIN
      pong
  6. 0
    1
      pong.cpp
  7. BIN
      pong.o

+ 3
- 4
Classes.h Ver arquivo

@@ -40,9 +40,8 @@ class Ball : public sf::CircleShape {
40 40
         float getRadius() const;
41 41
         float getAngle() const;
42 42
         void setAngle(float a);
43
-        void render(sf::RenderWindow) const;
44
-        void checkLeftPaddle(Paddle leftPaddle, sf::Sound ballSound);
45
-        void checkRightPaddle(Paddle rightPaddle, sf::Sound ballSound);
46
-        void checkCollisions(sf::Sound ballsound);
43
+        void checkLeftPaddle(const Paddle &leftPaddle, sf::Sound &ballSound);
44
+        void checkRightPaddle(const Paddle &rightPaddle, sf::Sound &ballSound);
45
+        void checkCollisions(sf::Sound &ballsound);
47 46
 
48 47
 };

+ 1
- 0
README.md Ver arquivo

@@ -0,0 +1 @@
1
+If you are reading this, I'm sorry

+ 5
- 5
functions.cpp Ver arquivo

@@ -53,7 +53,7 @@ void Ball::setAngle(float a) {
53 53
     angle = a;
54 54
 }
55 55
 
56
-void Ball::checkLeftPaddle(Paddle leftPaddle, sf::Sound ballSound) {
56
+void Ball::checkLeftPaddle(const Paddle &leftPaddle, sf::Sound &ballSound) {
57 57
     
58 58
     if (getPosition().x - radius < leftPaddle.getX() + leftPaddle.getSize().x / 2 &&
59 59
         getPosition().x - radius > leftPaddle.getX() &&
@@ -71,7 +71,7 @@ void Ball::checkLeftPaddle(Paddle leftPaddle, sf::Sound ballSound) {
71 71
     }
72 72
 }
73 73
 
74
-void Ball::checkRightPaddle(Paddle rightPaddle, sf::Sound ballSound) {
74
+void Ball::checkRightPaddle(const Paddle &rightPaddle, sf::Sound &ballSound) {
75 75
     
76 76
     if (getPosition().x + radius > rightPaddle.getX() - rightPaddle.getSize().x / 2 &&
77 77
         getPosition().x + radius < rightPaddle.getX() &&
@@ -79,16 +79,16 @@ void Ball::checkRightPaddle(Paddle rightPaddle, sf::Sound ballSound) {
79 79
         getPosition().y - radius <= rightPaddle.getY() + rightPaddle.getSize().y / 2)
80 80
     {
81 81
         if (getPosition().y > rightPaddle.getY())
82
-            angle = radius - angle + (rand() % 20) * radius / 180;
82
+            angle = M_PI - angle + (rand() % 20) * M_PI / 180;
83 83
         else
84
-            angle = radius - angle - (rand() % 20) * M_PI / 180;
84
+            angle = M_PI - angle - (rand() % 20) * M_PI / 180;
85 85
 
86 86
         ballSound.play();
87 87
         setPosition(rightPaddle.getX() - radius - rightPaddle.getSize().x / 2 - 0.1, getPosition().y);
88 88
     }
89 89
 }
90 90
 
91
-void Ball::checkCollisions(sf::Sound ballSound) {
91
+void Ball::checkCollisions(sf::Sound &ballSound) {
92 92
     if (getY() - radius < 0.f)
93 93
             {
94 94
                 ballSound.play();

BIN
functions.o Ver arquivo


BIN
pong Ver arquivo


+ 0
- 1
pong.cpp Ver arquivo

@@ -198,7 +198,6 @@ int main()
198 198
                 pauseMessage.setString("You Won!\n" + inputString);
199 199
             }
200 200
 
201
-            
202 201
             ball.checkCollisions(ballSound);
203 202
 
204 203
             // Check the collisions between the ball and the paddles

BIN
pong.o Ver arquivo