Fully pivot to pirates, some UI
This commit is contained in:
		| @@ -5,7 +5,7 @@ | ||||
|             :url "https://www.eclipse.org/legal/epl-2.0/"} | ||||
|   :dependencies [[org.clojure/clojure "1.11.1"] | ||||
|                  [seesaw "1.5.0"]] | ||||
|   :main ^:skip-aot space-sim.core | ||||
|   :main ^:skip-aot age-of-sail.core | ||||
|   :target-path "target/%s" | ||||
|   :profiles {:uberjar {:aot :all | ||||
|                        :jvm-opts ["-Dclojure.compiler.direct-linking=true"]}}) | ||||
|   | ||||
| @@ -1,6 +1,7 @@ | ||||
| ;; you should be in space-sim.core> | ||||
| ;; you should be in age-of-sail.core> | ||||
|  | ||||
| (def my-ship (ref {:position [0. 0.] | ||||
|                    :name "Virgina Woolfe" | ||||
|                    :heading (normalize [1.0 1.0]) | ||||
|                    :slots [{:type :downwind-sail :length 2 :furl 1.0}] | ||||
|                    :velocity [1. 0.]})) | ||||
| @@ -9,8 +10,7 @@ | ||||
|  | ||||
| (start-program) | ||||
| @my-ship | ||||
| (dosync (alter my-ship assoc :heading (normalize [0. 1.]))) | ||||
| (stop-program) | ||||
|  | ||||
|  | ||||
| (show-ui) | ||||
| @tracked-ship | ||||
|   | ||||
| @@ -1,6 +1,7 @@ | ||||
| (ns space-sim.core | ||||
|   (:require [space-sim.vec2 :refer :all] | ||||
| (ns age-of-sail.core | ||||
|   (:require [age-of-sail.vec2 :refer :all] | ||||
|             [seesaw.core :refer :all] | ||||
|             [seesaw.bind :as b] | ||||
|             [clojure.math :as math])) | ||||
| 
 | ||||
| (def tickrate 100) | ||||
| @@ -8,6 +9,10 @@ | ||||
| (defonce ships (atom [])) | ||||
| (defonce program (atom nil)) | ||||
| 
 | ||||
| (defn find-ship | ||||
|   [ships name] | ||||
|   (some #(when (= name (:name @%)) %) ships)) | ||||
| 
 | ||||
| (defn downwind-force | ||||
|   "Calculates the force for a single square downwind sail | ||||
|   Force = furl × length² × dot(wind, heading)" | ||||
| @@ -18,13 +23,11 @@ | ||||
|   [ship wind] | ||||
|   (loop [slots (:slots ship) | ||||
|          force (zero)] | ||||
|     (if (empty? slots) | ||||
|       force | ||||
|       (let [slot (first slots) | ||||
|             tail (rest slots)] | ||||
|         (if (= :downwind-sail (:type slot)) | ||||
|           (recur tail (add force (downwind-force slot wind (:heading ship)))) | ||||
|           (recur tail force)))))) | ||||
|     (if-let [slot (first slots)] | ||||
|       (if (= :downwind-sail (:type slot)) | ||||
|         (recur (rest slots) (add force (downwind-force slot wind (:heading ship)))) | ||||
|         (recur (rest slots) force)) | ||||
|       force))) | ||||
| 
 | ||||
| (defn physics-step | ||||
|   [ship wind] | ||||
| @@ -50,21 +53,29 @@ | ||||
|   [] | ||||
|   (stop-program) | ||||
|   (let [thread-continue (atom true)] | ||||
|     (.start (Thread. (fn [] | ||||
|                        (while @thread-continue | ||||
|                          (tick @ships) | ||||
|                          (Thread/sleep (quot 1000 tickrate)))))) | ||||
|     (.start | ||||
|      (Thread. | ||||
|       (fn [] | ||||
|         (while @thread-continue | ||||
|           (tick @ships) | ||||
|           (Thread/sleep (quot 1000 tickrate)))))) | ||||
|     (reset! program thread-continue))) | ||||
| 
 | ||||
| ;; UI | ||||
| (def tracked-ship (atom nil)) | ||||
| 
 | ||||
| (defn ship-chooser | ||||
|   [] | ||||
|   (let [namebox (text)] | ||||
|     (flow-panel :items ["Ship Name" namebox]) | ||||
|     (listen namebox :key-typed #()))) | ||||
|   (let [name (text :columns 20)] | ||||
|     (b/bind (.getDocument name) (b/transform #(find-ship @ships %)) tracked-ship) | ||||
|     (flow-panel :items ["Ship Name" name]))) | ||||
| 
 | ||||
| (defn ship-info | ||||
|   []) | ||||
| 
 | ||||
| (defn show-ui | ||||
|   [] | ||||
|   (-> (frame :title "Space Sim") pack! show!)) | ||||
|   (-> (frame :title "Space Sim" :content (ship-chooser)) pack! show!)) | ||||
| 
 | ||||
| (defn -main | ||||
|   [args] | ||||
| @@ -1,4 +1,4 @@ | ||||
| (ns space-sim.vec2 | ||||
| (ns age-of-sail.vec2 | ||||
|   (:require [clojure.math :as math])) | ||||
| 
 | ||||
| (defn zero | ||||
		Reference in New Issue
	
	Block a user