Commits

Julio Nobrega committed 6163c00

Restart ball when scoring

Comments (0)

Files changed (1)

 (def *running* 1)
 (def game-state (atom *paused*))
 
+; On scoring, ball will be thrown from an arc between -0.2 and 0.2
+(defn rand-ball-arc
+  []
+  (/ (- (rand) 0.8) 5)
+)
+
 ;;;;;;;;;;;;;;;;; Colision checking ;;;;;;;;;;;;;;;;;
 (defn colision-top?
   [game]
 (defn collided-right
   [game]
   (let [ball (game :ball)]
-    (merge game {:ball (merge ball {:x (- (game :window-width) (game :ball-size))
-                                    :sx (* -1 (ball :sx))})
-                 :player-left-score (inc (game :player-left-score))})))
+    (merge game {:ball (merge ball {:x (* (/ (game :window-width) 4) 3)
+                                    :y (+ (game :bleacher-height) (rand-int (game :window-height)))
+                                    :sx (* -1 (ball :sx))
+                                    :sy (rand-ball-arc)
+                                    })
+                 :player-left-score (inc (game :player-left-score))
+                 })))
 
 (defn collided-racquet-right
   [game]
                                     :sy (* (Math/sin hit) (game :speed))})
                  :speed (+ (game :speed) (game :increment))})))
 
+(defn collided-left
+  [game]
+  (let [ball (game :ball)]
+    (merge game {:ball (merge ball {:x (/ (game :window-width) 4)
+                                    :y (+ (game :bleacher-height) (rand-int (game :window-height)))
+                                    :sx (* -1 (ball :sx))
+                                    :sy (rand-ball-arc)
+                                    })
+                 :player-right-score (inc (game :player-right-score))
+                 })))
+
 (defn collided-racquet-left
   [game]
   (let [ball (game :ball)
                                     :sy (* (Math/sin hit) (game :speed))})
                  :speed (+ (game :speed) (game :increment))})))
 
-(defn collided-left
-  [game]
-  (let [ball (game :ball)]
-    (merge game {:ball (merge ball {:x 0
-                                    :sx (* -1 (ball :sx))})
-                 :player-right-score (inc (game :player-right-score))})))
-
 ;;;;;;;;;;;;;;;;; Object updates ;;;;;;;;;;;;;;;;;
 (defn update-ball
   [game step]