mirror of
https://github.com/richardharrington/robotwar.git
synced 2024-05-28 23:41:31 +00:00
added shell module, with some trig functions
This commit is contained in:
parent
a632b53817
commit
206f44ed9e
25
src/robotwar/shell.clj
Normal file
25
src/robotwar/shell.clj
Normal file
|
@ -0,0 +1,25 @@
|
|||
(ns robotwar.shell
|
||||
(:use [robotwar.constants]))
|
||||
|
||||
|
||||
(defn deg->rad
|
||||
[angle]
|
||||
(* angle (/ Math/PI 180)))
|
||||
|
||||
(defn decompose-angle
|
||||
[angle]
|
||||
{:x (Math/cos angle)
|
||||
:y (Math/sin angle)})
|
||||
|
||||
(defn new-shell
|
||||
[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} (decompose-angle (deg->rad aim))]
|
||||
{:pos-x pos-x
|
||||
:pos-y pos-y
|
||||
:v-x (* unit-x SHELL-SPEED)
|
||||
:v-y (* unit-y SHELL-SPEED)
|
||||
:dest-x (* unit-x distance)
|
||||
:dest-y (* unit-y distance)}))
|
||||
|
Loading…
Reference in New Issue
Block a user