Skip to content

Commit d89c257

Browse files
committed
Merge branch 'rexim/big-changes' into big-changes.
2 parents 80d4b00 + b1c00f8 commit d89c257

7 files changed

Lines changed: 44 additions & 37 deletions

File tree

src/hyperspace/game.clj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@
4141
(let [{position :position
4242
[_, power :as heading] :heading} player
4343
missile-position (-> (polar->cartesian heading)
44-
normilize-vector
44+
normalize-vector
4545
(multiply-by-scalar (+ player-radius
4646
missile-radius))
4747
(vector-sum position))
4848
missile-velocity (-> (polar->cartesian heading)
49-
normilize-vector
49+
normalize-vector
5050
(multiply-by-scalar (* power 100)))]
5151
(add-missile world
5252
missile-position
@@ -91,7 +91,7 @@
9191
planet-radius :radius} planet
9292

9393
fragments-position (-> (vector-subtract particle-position planet-position)
94-
normilize-vector
94+
normalize-vector
9595
(multiply-by-scalar (+ particle-radius planet-radius 5))
9696
(vector-sum planet-position))]
9797
(repeatedly 5

src/hyperspace/geometry.clj

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22

33
(def
44
^{:arglists '([vtr & vtrs])
5-
:doc "Returns the sum of vectors. The result vector has a minimum
6-
possible dimension."}
5+
:doc "Returns the sum of vectors."}
76
vector-sum (partial mapv +))
87

98
(def
109
^{:arglists '([vtr & vtrs])
11-
:doc "If no vtrs are supplied, returns the negation of vtr, else
12-
subtracts the vtrs from vtr and returns the result. The result
13-
vector has a minimum possible dimension."}
10+
:doc "If vtrs are supplied, returns the negation of vtr, else
11+
subtracts the vtrs from vtr and returns the result."}
1412
vector-subtract
1513
(partial mapv -))
1614

@@ -36,8 +34,8 @@
3634
[vtr]
3735
(Math/sqrt (reduce #(+ %1 (* %2 %2)) 0.0 vtr)))
3836

39-
(defn normilize-vector
40-
"Normilizes vector, that is returns a vector with the same
37+
(defn normalize-vector
38+
"Normalizes vector, that is returns a vector with the same
4139
direction, but with the length equal 1."
4240
[vtr]
4341
(let [length (vector-length vtr)]

src/hyperspace/gravity.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@
1313
(* d d))
1414
acceleration (/ force mass1)]
1515
(-> (vector-subtract position2 position1)
16-
normilize-vector
16+
normalize-vector
1717
(multiply-by-scalar acceleration))))

src/hyperspace/main.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44

55
(defn -main
66
[& args]
7-
(start-ui (generate-world 800 600)))
7+
(start-ui (generate-world 1024 768)))

src/hyperspace/ui.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@
126126
;; Init OpenGL
127127
(GL11/glMatrixMode GL11/GL_PROJECTION)
128128
(GL11/glLoadIdentity)
129-
(GL11/glOrtho x (+ x window-width)
130-
y (+ y window-height)
129+
(GL11/glOrtho x (+ x width)
130+
y (+ y height)
131131
1 -1)
132132
(GL11/glMatrixMode GL11/GL_MODELVIEW))
133133

src/hyperspace/world.clj

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@
2323

2424
(defn add-random-planet
2525
[{planets :planets
26+
[x, y] :position
2627
[width, height] :size
2728
:as world}]
28-
(let [radius (-> (min width height) (/ 4) rand)
29-
x (rand-range radius (- width radius))
30-
y (rand-range radius (- height radius))]
29+
(let [radius (-> (min width height) (/ 5) rand)
30+
x (rand-range (+ x radius) (- (+ x width) radius))
31+
y (rand-range (+ y radius) (- (+ y height) radius))]
3132
(assoc world
3233
:planets (conj planets (make-planet [x, y] radius)))))
3334

@@ -59,20 +60,6 @@
5960
:missiles (conj missiles new-missile)
6061
:traces (conj traces []))))
6162

62-
(defn add-random-missile
63-
[{[width, height] :size
64-
:as world}]
65-
(let [x (rand-range missile-radius (- width missile-radius))
66-
y (rand-range missile-radius (- height missile-radius))
67-
vx (rand-range -300 300)
68-
vy (rand-range -300 300)]
69-
(add-missile world [x, y] [vx, vy])))
70-
71-
(defn generate-missiles
72-
[world]
73-
(-> (iterate add-random-missile world)
74-
(nth amount-of-missiles)))
75-
7663
;;; Fragments related stuff
7764

7865
(defn make-fragment
@@ -93,11 +80,12 @@
9380
:radius player-radius})
9481

9582
(defn add-random-player
96-
[{[width, height] :size
83+
[{[x, y] :position
84+
[width, height] :size
9785
players :players
9886
:as world}]
99-
(let [x (rand-range player-radius (- width player-radius))
100-
y (rand-range player-radius (- height player-radius))]
87+
(let [x (rand-range (+ x player-radius) (- (+ x width) player-radius))
88+
y (rand-range (+ y player-radius) (- (+ y height) player-radius))]
10189
(assoc world
10290
:players (conj players (make-player [x, y] [0, 3.0])))))
10391

@@ -119,5 +107,4 @@
119107
:traces []
120108
:exit false}
121109
generate-players
122-
generate-planets
123-
generate-missiles))
110+
generate-planets))

test/hyperspace/test/geometry.clj

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
(multiply-by-scalar [0.2, 0.5] 3) => (just [(almost= 0.6),
2121
(almost= 1.5)]))
2222

23+
;; (facts "about polar->cartesian function"
24+
;; )
25+
26+
;; (facts "about cartesia->polar function"
27+
;; )
28+
2329
(facts "about vector-length function"
2430
(vector-length [10, 10]) => (almost= 14.142135623730951)
2531
(vector-length [1.23, 10.32]) => (almost= 10.393040940937354))
@@ -37,4 +43,20 @@
3743

3844
(facts "about distance function"
3945
(distance [0, 0] [10, 10]) => (almost= (vector-length [10, 10]))
40-
(distance [34, 12] [-24, 42]) => (almost= 65.29931086925804))
46+
(distance [34, 12] [-24, 42]) => (almost= 65.29931086925804))
47+
48+
;; (facts "about circle-X-circle? function"
49+
;; (circle-X-circle? {:position [0, 0], :radius 10}
50+
;; {:position [100, 100], :radius 10})
51+
;; => false
52+
53+
;; (circle-X-circle? {:position [34, 32], :radius 20}
54+
;; {:position []})
55+
;; => true
56+
;; )
57+
58+
;; (facts "about circle-X-any-circle? function"
59+
;; )
60+
61+
;; (facts "about circle-X-rectangle? fucntion"
62+
;; )

0 commit comments

Comments
 (0)