mirror of
https://github.com/richardharrington/robotwar.git
synced 2024-05-28 23:41:31 +00:00
fixing shells -- probably will discard
This commit is contained in:
parent
fe9294bff1
commit
cb1c7126c4
|
@ -238,7 +238,6 @@
|
||||||
drawRobot(robot, ROBOT_COLORS[idx]);
|
drawRobot(robot, ROBOT_COLORS[idx]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (currentWorld["next-shell-id"] !== previousWorld["next-shell-id"]) {
|
if (currentWorld["next-shell-id"] !== previousWorld["next-shell-id"]) {
|
||||||
soundPlayers.shellRelease.play();
|
soundPlayers.shellRelease.play();
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,10 +16,8 @@
|
||||||
:damage
|
:damage
|
||||||
:shot-timer]))
|
:shot-timer]))
|
||||||
(select-shell-keys [shell]
|
(select-shell-keys [shell]
|
||||||
(select-keys shell [:id
|
(select-keys shell [:pos-x
|
||||||
:pos-x
|
:pos-y]))
|
||||||
:pos-y
|
|
||||||
:exploded]))
|
|
||||||
(three-sigs-map [m]
|
(three-sigs-map [m]
|
||||||
(zipmap (keys m)
|
(zipmap (keys m)
|
||||||
(map #(if (float? %)
|
(map #(if (float? %)
|
||||||
|
|
|
@ -123,7 +123,9 @@
|
||||||
GAME-SECONDS-PER-SHOT)]
|
GAME-SECONDS-PER-SHOT)]
|
||||||
(assoc
|
(assoc
|
||||||
world-with-new-shot-timer
|
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))))))})
|
:next-shell-id (inc next-shell-id))))))})
|
||||||
|
|
||||||
(defn get-target-register
|
(defn get-target-register
|
||||||
|
|
|
@ -3,32 +3,23 @@
|
||||||
(:require [robotwar.physics :as physics]))
|
(:require [robotwar.physics :as physics]))
|
||||||
|
|
||||||
(defn init-shell
|
(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)]
|
(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
|
:pos-y pos-y
|
||||||
:v-x (* unit-x SHELL-SPEED)
|
:v-x (* unit-x SHELL-SPEED)
|
||||||
:v-y (* unit-y SHELL-SPEED)
|
:v-y (* unit-y SHELL-SPEED)
|
||||||
:dest-x (+ pos-x (* unit-x distance))
|
:dest-x (+ pos-x (* unit-x distance))
|
||||||
:dest-y (+ pos-y (* unit-y distance))
|
:dest-y (+ pos-y (* unit-y distance))}))
|
||||||
:exploded false}))
|
|
||||||
|
|
||||||
(defn tick-shell
|
(defn tick-shell
|
||||||
[{:keys [pos-x pos-y v-x v-y dest-x dest-y exploded] :as shell}]
|
[{:keys [pos-x pos-y v-x v-y dest-x dest-y] :as shell}]
|
||||||
(if exploded
|
(let [delta-x (* v-x *GAME-SECONDS-PER-TICK*)
|
||||||
nil
|
delta-y (* v-y *GAME-SECONDS-PER-TICK*)
|
||||||
(let [delta-x (* v-x *GAME-SECONDS-PER-TICK*)
|
remaining-x (- dest-x pos-x)
|
||||||
delta-y (* v-y *GAME-SECONDS-PER-TICK*)
|
remaining-y (- dest-y pos-y)]
|
||||||
remaining-x (- dest-x pos-x)
|
(if (and (<= (Math/abs remaining-x) (Math/abs delta-x))
|
||||||
remaining-y (- dest-y pos-y)]
|
(<= (Math/abs remaining-y) (Math/abs delta-y)))
|
||||||
; only need to check one dimension
|
nil
|
||||||
(if (and (<= (Math/abs remaining-x) (Math/abs delta-x))
|
(merge shell {:pos-x (+ pos-x delta-x)
|
||||||
(<= (Math/abs remaining-y) (Math/abs delta-y)))
|
:pos-y (+ pos-y delta-y)}))))
|
||||||
(merge shell {:pos-x dest-x
|
|
||||||
:pos-y dest-y
|
|
||||||
:exploded true})
|
|
||||||
(merge shell {:pos-x (+ pos-x delta-x)
|
|
||||||
:pos-y (+ pos-y delta-y)})))))
|
|
||||||
|
|
|
@ -25,16 +25,18 @@
|
||||||
(defn tick-combined-world
|
(defn tick-combined-world
|
||||||
[starting-world]
|
[starting-world]
|
||||||
(let [{:keys [shells next-shell-id] :as ticked-robots-world}
|
(let [{:keys [shells next-shell-id] :as ticked-robots-world}
|
||||||
(reduce (fn [{robots :robots :as world} robot-idx]
|
(reduce (fn [{robots :robots :as world} robot-idx]
|
||||||
(robot/tick-robot (robots robot-idx) world))
|
(robot/tick-robot (robots robot-idx) world))
|
||||||
starting-world
|
starting-world
|
||||||
(range (count (:robots starting-world))))
|
(range (count (:robots starting-world))))
|
||||||
ticked-shells (map shell/tick-shell shells)
|
ticked-shells (into {} (map (fn [shell-map-entry]
|
||||||
live-shells (remove :exploded ticked-shells)
|
[(key shell-map-entry)
|
||||||
exploded-shells (filter :exploded ticked-shells)]
|
(shell/tick-shell (val shell-map-entry))])
|
||||||
|
shells))]
|
||||||
; TODO: make this a real let-binding, that determines
|
; TODO: make this a real let-binding, that determines
|
||||||
; which robots were damaged.
|
; which robots were damaged.
|
||||||
(let [damaged-world ticked-robots-world]
|
(let [damaged-world ticked-robots-world]
|
||||||
(assoc damaged-world :shells live-shells))))
|
(pprint ticked-shells)
|
||||||
|
(assoc damaged-world :shells ticked-shells))))
|
||||||
|
|
||||||
(def build-combined-worlds (partial iterate tick-combined-world))
|
(def build-combined-worlds (partial iterate tick-combined-world))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user