|
311 | 311 | ;; Special Moves |
312 | 312 | ;; ============================================================================ |
313 | 313 |
|
| 314 | +(defn hyperspace [state new-x new-y died?] |
| 315 | + (-> state |
| 316 | + ;; Teleport ship |
| 317 | + (assoc-in [:ship :x] new-x) |
| 318 | + (assoc-in [:ship :y] new-y) |
| 319 | + (assoc-in [:ship :vx] 0) |
| 320 | + (assoc-in [:ship :vy] 0) |
| 321 | + (assoc :hyperspace-cooldown hyperspace-cooldown) |
| 322 | + ;; Conditionally handle death |
| 323 | + (#(if died? |
| 324 | + (-> % |
| 325 | + (update-in [:lives] dec) |
| 326 | + (update :particles |
| 327 | + (fn [particles] |
| 328 | + (vec (concat particles |
| 329 | + (create-particles |
| 330 | + :x new-x |
| 331 | + :y new-y |
| 332 | + :count 12 |
| 333 | + :color "#FFFFFF")))))) |
| 334 | + %)))) |
| 335 | + |
314 | 336 | (defn hyperspace! |
315 | 337 | "Hyperspace jump with risk" |
316 | | - [] |
317 | | - (when (<= (:hyperspace-cooldown @game-state) 0) |
318 | | - (play-hyperspace-sound) ; Play hyperspace sound |
| 338 | + [game-state] |
| 339 | + (when (<= (:hyperspace-cooldown game-state) 0) |
| 340 | + (play-hyperspace-sound) ; Play hyperspace sound |
319 | 341 | (let [new-x (rand-int canvas-width) |
320 | 342 | new-y (rand-int canvas-height) |
321 | 343 | died? (< (rand) 0.1)] |
322 | | - (swap! game-state |
323 | | - (fn [state] |
324 | | - (-> state |
325 | | - ;; Teleport ship |
326 | | - (assoc-in [:ship :x] new-x) |
327 | | - (assoc-in [:ship :y] new-y) |
328 | | - (assoc-in [:ship :vx] 0) |
329 | | - (assoc-in [:ship :vy] 0) |
330 | | - (assoc :hyperspace-cooldown hyperspace-cooldown) |
331 | | - ;; Conditionally handle death |
332 | | - (#(if died? |
333 | | - (-> % |
334 | | - (update-in [:lives] dec) |
335 | | - (update :particles |
336 | | - (fn [particles] |
337 | | - (vec (concat particles |
338 | | - (create-particles |
339 | | - :x new-x |
340 | | - :y new-y |
341 | | - :count 12 |
342 | | - :color "#FFFFFF")))))) |
343 | | - %)))))))) |
| 344 | + (hyperspace game-state new-x new-y died?)))) |
344 | 345 |
|
345 | 346 | ;; ============================================================================ |
346 | 347 | ;; Collision Detection |
|
787 | 788 | (when (= (:game-status @game-state) :playing) |
788 | 789 | (case key |
789 | 790 | " " (do (fire-bullet!) (.preventDefault e)) |
790 | | - "x" (hyperspace!) |
791 | | - "X" (hyperspace!) |
| 791 | + "x" (swap! game-state hyperspace!) |
| 792 | + "X" (swap! game-state hyperspace!) |
792 | 793 | nil))))) |
793 | 794 |
|
794 | 795 | (.addEventListener js/window "keyup" |
|
1042 | 1043 | :color "255, 152, 0" |
1043 | 1044 | :on-press #(do |
1044 | 1045 | (swap! game-state assoc-in [:touch-controls :hyperspace-button] true) |
1045 | | - (hyperspace!)) |
| 1046 | + (swap! game-state hyperspace!)) |
1046 | 1047 | :on-release #(swap! game-state assoc-in [:touch-controls :hyperspace-button] false)]]])) |
1047 | 1048 |
|
1048 | 1049 | ;; ============================================================================ |
|
0 commit comments