File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 250250 " Hyperspace jump with risk"
251251 []
252252 (when (<= (:hyperspace-cooldown @game-state) 0 )
253- (swap! game-state assoc-in [:ship :x ] (rand-int canvas-width))
254- (swap! game-state assoc-in [:ship :y ] (rand-int canvas-height))
255- (swap! game-state assoc-in [:ship :vx ] 0 )
256- (swap! game-state assoc-in [:ship :vy ] 0 )
257- (swap! game-state assoc :hyperspace-cooldown hyperspace-cooldown)
258- ; ; 10% chance of explosion (risky!)
259- (when (< (rand ) 0.1 )
260- (swap! game-state update-in [:lives ] dec)
261- (swap! game-state update :particles
262- #(vec (concat % (create-particles :x (:x (:ship @game-state))
263- :y (:y (:ship @game-state))
264- :count 12
265- :color " #FFFFFF" )))))))
253+ (let [new-x (rand-int canvas-width)
254+ new-y (rand-int canvas-height)
255+ died? (< (rand ) 0.1 )]
256+ (swap! game-state
257+ (fn [state]
258+ (-> state
259+ ; ; Teleport ship
260+ (assoc-in [:ship :x ] new-x)
261+ (assoc-in [:ship :y ] new-y)
262+ (assoc-in [:ship :vx ] 0 )
263+ (assoc-in [:ship :vy ] 0 )
264+ (assoc :hyperspace-cooldown hyperspace-cooldown)
265+ ; ; Conditionally handle death
266+ (#(if died?
267+ (-> %
268+ (update-in [:lives ] dec)
269+ (update :particles
270+ (fn [particles]
271+ (vec (concat particles
272+ (create-particles
273+ :x new-x
274+ :y new-y
275+ :count 12
276+ :color " #FFFFFF" ))))))
277+ %))))))))
266278
267279; ; ============================================================================
268280; ; Collision Detection
You can’t perform that action at this time.
0 commit comments