got shells (mostly) working

This commit is contained in:
Richard Harrington 2013-08-21 21:47:52 -04:00
parent 0d5f3838ac
commit 0ee2637024
2 changed files with 10 additions and 6 deletions

View File

@ -11,8 +11,8 @@
:pos-y pos-y
:v-x (* unit-x SHELL-SPEED)
:v-y (* unit-y SHELL-SPEED)
:dest-x (* unit-x distance)
:dest-y (* unit-y distance)
:dest-x (+ pos-x (* unit-x distance))
:dest-y (+ pos-y (* unit-y distance))
:exploded false}))
(defn tick-shell
@ -24,9 +24,10 @@
remaining-x (- dest-x pos-x)
remaining-y (- dest-y pos-y)]
; only need to check one dimension
(if (< (Math/abs remaining-x) (Math/abs delta-x))
(if (and (< (Math/abs remaining-x) (Math/abs delta-x))
(< (Math/abs remaining-y) (Math/abs delta-y)))
(merge shell {:pos-x dest-x
:pos-y dest-y
:exploded true})
(merge shell {:pos-x (+ pos-x delta-x)
:pox-y (+ pos-y delta-y)})))))
:pos-y (+ pos-y delta-y)})))))

View File

@ -1,9 +1,11 @@
(ns robotwar.world
(:use [clojure.string :only [join]]
[robotwar.constants])
[robotwar.constants]
[clojure.pprint :as pprint])
(:require [clj-time.core :as time]
[clj-time.periodic :as periodic]
[robotwar.robot :as robot]))
[robotwar.robot :as robot]
[robotwar.shell :as shell]))
(defn init-world
"initialize all the variables for a robot world."
@ -28,6 +30,7 @@
ticked-shells (map shell/tick-shell shells)
live-shells (remove :exploded ticked-shells)
exploded-shells (filter :exploded ticked-shells)]
(println (count ticked-shells))
; TODO: make this a real let-binding, that determines
; which robots were damaged.
(let [damaged-world ticked-robots-world]