mirror of
https://github.com/richardharrington/robotwar.git
synced 2024-06-08 17:29:33 +00:00
102a307af8
(so far, we can't play the same sound at the same time anyway, so this change has no visible effect yet)
40 lines
1.7 KiB
Clojure
40 lines
1.7 KiB
Clojure
(ns robotwar.world
|
|
(:use [clojure.string :only [join]]
|
|
[robotwar.constants]
|
|
[clojure.pprint :as pprint])
|
|
(:require [clj-time.core :as time]
|
|
[clj-time.periodic :as periodic]
|
|
[robotwar.robot :as robot]
|
|
[robotwar.shell :as shell]))
|
|
|
|
(defn init-world
|
|
"initialize all the variables for a robot world."
|
|
[programs]
|
|
{:shells {:next-id 0
|
|
:shell-map {}}
|
|
:robots (vec (map-indexed (fn [idx program]
|
|
(robot/init-robot
|
|
idx
|
|
program
|
|
{:pos-x (rand ROBOT-RANGE-X)
|
|
:pos-y (rand ROBOT-RANGE-Y)
|
|
:aim 0.0
|
|
:damage 100.0}))
|
|
programs))})
|
|
|
|
(defn tick-combined-world
|
|
[starting-world]
|
|
(let [{shells :shells :as ticked-robots-world} (reduce (fn [{robots :robots :as world} robot-idx]
|
|
(robot/tick-robot (robots robot-idx) world))
|
|
starting-world
|
|
(range (count (:robots starting-world))))
|
|
ticked-shells (map shell/tick-shell (:shell-map shells))
|
|
live-shells (remove :exploded ticked-shells)
|
|
exploded-shells (filter :exploded ticked-shells)]
|
|
; TODO: make this a real let-binding, that determines
|
|
; which robots were damaged.
|
|
(let [damaged-world ticked-robots-world]
|
|
(assoc-in damaged-world [:shells :shell-map] live-shells))))
|
|
|
|
(def build-combined-worlds (partial iterate tick-combined-world))
|