generalize

This commit is contained in:
nek0 2016-12-28 12:19:45 +01:00
parent 5cf28ed234
commit 46319e7f24

View file

@ -202,14 +202,15 @@ update sec = do
ud2 <- getAffection ud2 <- getAffection
let nx = fst (sPos $ ship ud2) + (fst (sVel $ ship ud2)) * sec let nx = fst (sPos $ ship ud2) + (fst (sVel $ ship ud2)) * sec
ny = snd (sPos $ ship ud2) + (snd (sVel $ ship ud2)) * sec ny = snd (sPos $ ship ud2) + (snd (sVel $ ship ud2)) * sec
nnx = -- nnx =
if nx > 800 -- if nx > 800
then nx - 850 -- then nx - 850
else if nx < -50 then nx + 850 else nx -- else if nx < -50 then nx + 850 else nx
nny = -- nny =
if ny > 600 -- if ny > 600
then ny - 650 -- then ny - 650
else if ny < -50 then ny + 650 else ny -- else if ny < -50 then ny + 650 else ny
(nnx, nny) = wrapAround (nx, ny) 50
liftIO $ gegl_node_set (nodeGraph ud2 M.! KeyTranslate) $ Operation "gegl:translate" liftIO $ gegl_node_set (nodeGraph ud2 M.! KeyTranslate) $ Operation "gegl:translate"
[ Property "x" $ PropertyDouble $ nnx [ Property "x" $ PropertyDouble $ nnx
, Property "y" $ PropertyDouble $ nny , Property "y" $ PropertyDouble $ nny
@ -225,6 +226,17 @@ update sec = do
, shots = ups , shots = ups
} }
wrapAround (nx, ny) width = (nnx, nny)
where
nnx =
if nx > 800
then nx - (800 + width)
else if nx < -width then nx + 800 + width else nx
nny =
if ny > 600
then ny - (600 + width)
else if ny < -width then ny + 600 + width else ny
draw :: Affection UserData () draw :: Affection UserData ()
draw = do draw = do
traceM "drawing" traceM "drawing"