Skip to content

Commit 45cca63

Browse files
committed
Merge remote-tracking branch 'upstream/big-changes' into big-changes
2 parents c6f1778 + 88482e2 commit 45cca63

1 file changed

Lines changed: 23 additions & 7 deletions

File tree

src/hyperspace/world.clj

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(ns hyperspace.world
22
(:use [clojure.pprint :only (pprint)]
33
[clojure.java.io :only (reader writer)]
4-
[hyperspace.misc]))
4+
[hyperspace geometry misc]))
55

66
(def missile-radius 5)
77
(def player-radius 15)
@@ -11,6 +11,14 @@
1111
(def amount-of-players 2)
1212
(def amount-of-missiles 0)
1313

14+
15+
(defn generate-without-intersection
16+
"Generates new object (player, planet etc). fgen should be 0-arity function"
17+
[{:keys [planets] :as world} fgen]
18+
(first
19+
(remove #(circle-X-any-circle? % planets)
20+
(repeatedly fgen))))
21+
1422
;;; Planets related stuff
1523

1624
(defn make-planet
@@ -21,16 +29,20 @@
2129
:mass (* (Math/sqrt radius)
2230
(Math/pow 10 7))})
2331

24-
(defn add-random-planet
32+
(defn generate-random-planet
2533
[{planets :planets
2634
[x, y] :position
2735
[width, height] :size
2836
:as world}]
2937
(let [radius (-> (min width height) (/ 5) rand)
3038
x (rand-range (+ x radius) (- (+ x width) radius))
3139
y (rand-range (+ y radius) (- (+ y height) radius))]
32-
(assoc world
33-
:planets (conj planets (make-planet [x, y] radius)))))
40+
(make-planet [x y] radius)))
41+
42+
(defn add-random-planet
43+
[world]
44+
(let [p (generate-without-intersection world (partial generate-random-planet world))]
45+
(update-in world [:planets] conj p)))
3446

3547
(defn generate-planets
3648
[world]
@@ -79,15 +91,19 @@
7991
:heading heading
8092
:radius player-radius})
8193

82-
(defn add-random-player
94+
(defn generate-random-player
8395
[{[x, y] :position
8496
[width, height] :size
8597
players :players
8698
:as world}]
8799
(let [x (rand-range (+ x player-radius) (- (+ x width) player-radius))
88100
y (rand-range (+ y player-radius) (- (+ y height) player-radius))]
89-
(assoc world
90-
:players (conj players (make-player [x, y] [0, 3.0])))))
101+
(make-player [x y] [0 3.0])))
102+
103+
(defn add-random-player
104+
[world]
105+
(let [player (generate-without-intersection world (partial generate-random-player world))]
106+
(update-in world [:players] conj player)))
91107

92108
(defn generate-players
93109
[world]

0 commit comments

Comments
 (0)