diff --git a/src/robotwar/constants.clj b/src/robotwar/constants.clj index 0b4458a..eed7a20 100644 --- a/src/robotwar/constants.clj +++ b/src/robotwar/constants.clj @@ -4,4 +4,7 @@ (def MAX-ACCEL 4.0) (def ^:dynamic *GAME-SECONDS-PER-TICK* 0.03) +; ROBOT-RANGE-X and -Y are in meters +(def ROBOT-RANGE-X 256.0) +(def ROBOT-RANGE-Y 256.0) diff --git a/src/robotwar/core.clj b/src/robotwar/core.clj index a5b5214..dba5cb0 100644 --- a/src/robotwar/core.clj +++ b/src/robotwar/core.clj @@ -14,7 +14,7 @@ (def progs (repeat 3 (:moving-to-spot test-programs/programs))) (def world - (world/init-world 256.0 256.0 progs)) + (world/init-world progs)) (defn combined-worlds [] (world/build-combined-worlds world)) (defn worlds-for-terminal-display [fast-forward] diff --git a/src/robotwar/handler.clj b/src/robotwar/handler.clj index 6c327a9..a3cae52 100644 --- a/src/robotwar/handler.clj +++ b/src/robotwar/handler.clj @@ -25,7 +25,7 @@ (def progs (repeat 3 (:moving-to-spot test-programs/programs))) (def world - (world/init-world 256.0 256.0 progs)) + (world/init-world progs)) (defn combined-worlds [] (world/build-combined-worlds world)) diff --git a/src/robotwar/terminal.clj b/src/robotwar/terminal.clj index 3591faa..b73433c 100644 --- a/src/robotwar/terminal.clj +++ b/src/robotwar/terminal.clj @@ -23,13 +23,13 @@ (defn arena-text-grid "outputs the arena, with borders" - [{:keys [width height robots]} print-width print-height] + [{robots :robots} print-robot-range-x print-robot-range-y] (let [horiz-border-char "-" vert-border-char "+" - header-footer (apply str (repeat (+ (* print-width 3) 2) horiz-border-char)) - scale-x #(* % (/ print-width width)) - scale-y #(* % (/ print-height height)) - field (for [y (range print-height), x (range print-width)] + header-footer (apply str (repeat (+ (* print-robot-range-x 3) 2) horiz-border-char)) + scale-x #(* % (/ print-robot-range-x ROBOT-RANGE-X)) + scale-y #(* % (/ print-robot-range-y ROBOT-RANGE-Y)) + field (for [y (range print-robot-range-y), x (range print-robot-range-x)] (or (some (fn [{:keys [idx pos-x pos-y]}] (when (near-point [(scale-x pos-x) (scale-y pos-y)] [x y]) (str "(" idx ")"))) @@ -38,7 +38,7 @@ (str header-footer "\n" (join "\n" (map #(join (apply str %) (repeat 2 vert-border-char)) - (partition print-width field))) + (partition print-robot-range-x field))) "\n" header-footer))) @@ -56,12 +56,12 @@ (defn animate "animates a sequence of worlds in the terminal" - [initial-worlds print-width print-height fps] + [initial-worlds print-robot-range-x print-robot-range-y fps] (let [frame-period (time/millis (* (/ 1 fps) 1000)) starting-instant (time/now)] (loop [[world :as worlds] initial-worlds frame-start starting-instant] - (println (arena-text-grid world print-width print-height)) + (println (arena-text-grid world print-robot-range-x print-robot-range-y)) (display-robots-info world (time/interval starting-instant frame-start) fps) (let [desired-next-frame-calc-start (time/plus frame-start frame-period) this-instant (time/now) diff --git a/src/robotwar/world.clj b/src/robotwar/world.clj index e05a7e7..9fbd2d0 100644 --- a/src/robotwar/world.clj +++ b/src/robotwar/world.clj @@ -1,21 +1,20 @@ (ns robotwar.world - (:use [clojure.string :only [join]]) + (:use [clojure.string :only [join]] + [robotwar.constants]) (:require [clj-time.core :as time] [clj-time.periodic :as periodic] [robotwar.robot :as robot])) (defn init-world "initialize all the variables for a robot world." - [width height programs] - {:width width - :height height - :shells [] + [programs] + {:shells [] :robots (vec (map-indexed (fn [idx program] (robot/init-robot idx program - {:pos-x (rand width) - :pos-y (rand height) + {:pos-x (rand ROBOT-RANGE-X) + :pos-y (rand ROBOT-RANGE-Y) :aim 0.0 :damage 100.0})) programs))})