Skip to content

Commit ab56626

Browse files
committed
Fixed generation of planets and players.
1 parent 9bdb2d5 commit ab56626

3 files changed

Lines changed: 11 additions & 23 deletions

File tree

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: 8 additions & 20 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

0 commit comments

Comments
 (0)