trying to fix shells

This commit is contained in:
Richard Harrington 2013-09-04 09:56:12 -04:00
parent fe9294bff1
commit 37625c312b
3 changed files with 15 additions and 7 deletions

View File

@ -123,7 +123,8 @@
GAME-SECONDS-PER-SHOT)]
(assoc
world-with-new-shot-timer
:shells (merge shells (shell/init-shell pos-x pos-y aim next-shell-id data))
:shells (merge shells {next-shell-id
(shell/init-shell pos-x pos-y aim data)})
:next-shell-id (inc next-shell-id))))))})
(defn get-target-register

View File

@ -3,12 +3,11 @@
(:require [robotwar.physics :as physics]))
(defn init-shell
[pos-x pos-y aim id distance]
[pos-x pos-y aim distance]
; TODO: make the starting point dependent upon the robot radius,
; which should be in constants.
(let [{unit-x :x unit-y :y} (physics/decompose-angle aim)]
{:id id
:pos-x pos-x
{:pos-x pos-x
:pos-y pos-y
:v-x (* unit-x SHELL-SPEED)
:v-y (* unit-y SHELL-SPEED)

View File

@ -29,9 +29,17 @@
(robot/tick-robot (robots robot-idx) world))
starting-world
(range (count (:robots starting-world))))
ticked-shells (map shell/tick-shell shells)
live-shells (remove :exploded ticked-shells)
exploded-shells (filter :exploded ticked-shells)]
ticked-shells (zipmap (keys shells)
(map shell/tick-shell (vals shells)))
; TODO: Is this the most idiomatic way to map a hash-map, testing
; each value in the hash-map on a predicate and then returning another hash-map?
; looks clunky.
live-shells (into {} (remove #(:exploded (val %))
ticked-shells))
exploded-shells (into {} (filter #(:exploded (val %))
ticked-shells))]
; TODO: make this a real let-binding, that determines
; which robots were damaged.
(let [damaged-world ticked-robots-world]