|
277 | 277 |
|
278 | 278 | (defn fire-bullet! |
279 | 279 | "Fires a bullet from the ship" |
280 | | - [] |
| 280 | + [{:keys [ship] :as game-state}] |
281 | 281 | (play-laser-sound) ; Play laser sound |
282 | | - (let [{:keys [x y angle]} (:ship @game-state) |
| 282 | + (let [{:keys [x y angle]} ship |
283 | 283 | bullet-vx (* bullet-speed (Math/cos (- angle (/ Math/PI 2)))) |
284 | 284 | bullet-vy (* bullet-speed (Math/sin (- angle (/ Math/PI 2))))] |
285 | | - (swap! game-state update :bullets conj |
286 | | - {:x x |
287 | | - :y y |
288 | | - :vx bullet-vx |
289 | | - :vy bullet-vy |
290 | | - :life bullet-lifetime}))) |
| 285 | + (update game-state :bullets conj |
| 286 | + {:x x |
| 287 | + :y y |
| 288 | + :vx bullet-vx |
| 289 | + :vy bullet-vy |
| 290 | + :life bullet-lifetime}))) |
291 | 291 |
|
292 | 292 | (defn ufo-fire! |
293 | 293 | "UFO fires bullet at ship" |
294 | | - [& {:keys [ufo]}] |
295 | | - (let [{:keys [ship]} @game-state |
296 | | - dx (- (:x ship) (:x ufo)) |
| 294 | + [{:keys [ship] :as game-state} & {:keys [ufo]}] |
| 295 | + (let [dx (- (:x ship) (:x ufo)) |
297 | 296 | dy (- (:y ship) (:y ufo)) |
298 | 297 | angle (Math/atan2 dy dx) |
299 | 298 | bullet-vx (* 5 (Math/cos angle)) |
300 | 299 | bullet-vy (* 5 (Math/sin angle))] |
301 | | - (swap! game-state update :bullets conj |
302 | | - {:x (:x ufo) |
303 | | - :y (:y ufo) |
304 | | - :vx bullet-vx |
305 | | - :vy bullet-vy |
306 | | - :life bullet-lifetime |
307 | | - :from-ufo true}))) |
| 300 | + (update game-state :bullets conj |
| 301 | + {:x (:x ufo) |
| 302 | + :y (:y ufo) |
| 303 | + :vx bullet-vx |
| 304 | + :vy bullet-vy |
| 305 | + :life bullet-lifetime |
| 306 | + :from-ufo true}))) |
308 | 307 |
|
309 | 308 | ;; ============================================================================ |
310 | 309 | ;; Special Moves |
|
427 | 426 | (do |
428 | 427 | (when (and (= (mod (:frame-count @game-state) 60) 0) |
429 | 428 | (< (rand) 0.3)) |
430 | | - (ufo-fire! :ufo u)) |
| 429 | + (swap! game-state ufo-fire! :ufo u)) |
431 | 430 | (-> u |
432 | 431 | (update :x + (:vx u)) |
433 | 432 | (update :y + (:vy u)))))))) |
|
786 | 785 | (swap! keys-pressed conj key) |
787 | 786 | (when (= (:game-status @game-state) :playing) |
788 | 787 | (case key |
789 | | - " " (do (fire-bullet!) (.preventDefault e)) |
| 788 | + " " (do (swap! game-state fire-bullet!) (.preventDefault e)) |
790 | 789 | "x" (swap! game-state hyperspace!) |
791 | 790 | "X" (swap! game-state hyperspace!) |
792 | 791 | nil))))) |
|
1033 | 1032 | :color "76, 175, 80" |
1034 | 1033 | :on-press #(do |
1035 | 1034 | (swap! game-state assoc-in [:touch-controls :fire-button] true) |
1036 | | - (fire-bullet!)) |
| 1035 | + (swap! game-state fire-bullet!)) |
1037 | 1036 | :on-release #(swap! game-state assoc-in [:touch-controls :fire-button] false)] |
1038 | 1037 | [touch-action-button |
1039 | 1038 | :label "HYPER" |
|
0 commit comments