changed width and height to robot-range-x and robot-range-y and made
them constants because technically, the robot ranges are the maximum ranges for the centers of the robots' bodies, so the actual extent of the arena when displayed must be slightly larger
This commit is contained in:
parent
e3b879fba8
commit
9b46900f9b
|
@ -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)
|
||||
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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))
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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))})
|
||||
|
|
Loading…
Reference in New Issue