Skip to content

Commit 2acc111

Browse files
committed
simulation: fix player position calculation
1 parent 4e22cc4 commit 2acc111

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

src/hyperspace/library/simulation.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,5 @@
6161
(cond
6262
(> counter max-cycle) [world nil]
6363
planet [world (:position planet)]
64-
player [(kill-player world player) (:position planet)]
64+
player [(kill-player world player) (:position player)]
6565
:else (recur bullet (+ counter 1)))))))

test/hyperspace/test/library/sumulation.clj

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77
[hyperspace.library.world :as world]))
88

99
(def player-fixture (world/make-player [10 10]))
10+
(def player2-fixture (world/make-player [15 15]))
1011
(def nonexistent-player-fixture (world/make-player [20 20]))
1112
(def world-fixture (-> (world/create 800 600)
1213
(assoc :players [player-fixture])))
14+
(def two-player-world-fixture (assoc world-fixture
15+
:players [player-fixture player2-fixture]))
1316

1417
(facts "about kill-player function"
1518
(kill-player world-fixture player-fixture) => (assoc world-fixture :players [(assoc player-fixture :status :dead)])
@@ -44,6 +47,10 @@
4447
))
4548

4649
(facts "about fire function"
47-
;; TODO: test shot to player
50+
(let [heading (geometry/heading (:position player-fixture) (:position player2-fixture))
51+
result-player2 (assoc player2-fixture :status :dead)
52+
result-world (assoc two-player-world-fixture :players [player-fixture result-player2])]
53+
(fire two-player-world-fixture player-fixture heading 10)
54+
=> [result-world (:position player2-fixture)])
4855
;; TODO: test shot to planet
4956
(fire world-fixture player-fixture 0 10) => [world-fixture nil])

0 commit comments

Comments
 (0)