finishing up. game works
This commit is contained in:
parent
700821f059
commit
ac2a71cdc4
1 changed files with 56 additions and 22 deletions
78
src/Main.hs
78
src/Main.hs
|
@ -177,10 +177,12 @@ update sec = do
|
||||||
when (SDL.keyboardEventKeyMotion dat == SDL.Pressed) $ do
|
when (SDL.keyboardEventKeyMotion dat == SDL.Pressed) $ do
|
||||||
ud <- getAffection
|
ud <- getAffection
|
||||||
-- ad <- get
|
-- ad <- get
|
||||||
|
let posX = (fst $ sPos $ ship ud) + 23 - 30 * sin (toR $ sRot $ ship ud)
|
||||||
|
posY = (snd $ sPos $ ship ud) + 23 - 30 * cos (toR $ sRot $ ship ud)
|
||||||
tempRoot <- liftIO $ gegl_node_new
|
tempRoot <- liftIO $ gegl_node_new
|
||||||
tempRect <- liftIO $ gegl_node_new_child tempRoot $ Operation "gegl:rectangle"
|
tempRect <- liftIO $ gegl_node_new_child tempRoot $ Operation "gegl:rectangle"
|
||||||
[ Property "x" $ (PropertyDouble $ (fst $ sPos $ ship ud) + 23)
|
[ Property "x" $ PropertyDouble $ posX
|
||||||
, Property "y" $ (PropertyDouble $ (snd $ sPos $ ship ud) + 23)
|
, Property "y" $ PropertyDouble $ posY
|
||||||
, Property "width" $ PropertyDouble 4
|
, Property "width" $ PropertyDouble 4
|
||||||
, Property "height" $ PropertyDouble 4
|
, Property "height" $ PropertyDouble 4
|
||||||
, Property "color" $ PropertyColor $ (GEGL.RGBA 1 1 1 1)
|
, Property "color" $ PropertyColor $ (GEGL.RGBA 1 1 1 1)
|
||||||
|
@ -191,10 +193,7 @@ update sec = do
|
||||||
Particle
|
Particle
|
||||||
{ particleTimeToLive = 5
|
{ particleTimeToLive = 5
|
||||||
, particleCreation = elapsedTime ad
|
, particleCreation = elapsedTime ad
|
||||||
, particlePosition =
|
, particlePosition = (posX, posY)
|
||||||
( (fst $ sPos $ ship ud) + 23
|
|
||||||
, (snd $ sPos $ ship ud) + 23
|
|
||||||
)
|
|
||||||
, particleRotation = Rad 0
|
, particleRotation = Rad 0
|
||||||
, particleVelocity =
|
, particleVelocity =
|
||||||
-- ( (floor $ -200 * (sin $ toR $ (sRot $ ship ud) + (fst $ sVel $ ship ud)))
|
-- ( (floor $ -200 * (sin $ toR $ (sRot $ ship ud) + (fst $ sVel $ ship ud)))
|
||||||
|
@ -225,7 +224,7 @@ update sec = do
|
||||||
) evs
|
) evs
|
||||||
ud2 <- getAffection
|
ud2 <- getAffection
|
||||||
nhs <- mapM (updateHaskelloid sec) (haskelloids ud2)
|
nhs <- mapM (updateHaskelloid sec) (haskelloids ud2)
|
||||||
liftIO $ traceIO $ show $ length nhs
|
-- liftIO $ traceIO $ show $ length nhs
|
||||||
putAffection ud2
|
putAffection ud2
|
||||||
{ haskelloids = nhs
|
{ haskelloids = nhs
|
||||||
}
|
}
|
||||||
|
@ -263,7 +262,7 @@ wrapAround (nx, ny) width = (nnx, nny)
|
||||||
|
|
||||||
draw :: Affection UserData ()
|
draw :: Affection UserData ()
|
||||||
draw = do
|
draw = do
|
||||||
traceM "drawing"
|
-- traceM "drawing"
|
||||||
ud <- getAffection
|
ud <- getAffection
|
||||||
liftIO $ gegl_node_process $ nodeGraph ud M.! KeySink
|
liftIO $ gegl_node_process $ nodeGraph ud M.! KeySink
|
||||||
-- mintr <- liftIO $ gegl_rectangle_intersect
|
-- mintr <- liftIO $ gegl_rectangle_intersect
|
||||||
|
@ -311,8 +310,21 @@ shotsUpd sec part@Particle{..} = do
|
||||||
Nothing -> return Nothing
|
Nothing -> return Nothing
|
||||||
) (haskelloids ud)
|
) (haskelloids ud)
|
||||||
killings <- mapM haskelloidShotDown inters
|
killings <- mapM haskelloidShotDown inters
|
||||||
ud2 <- getAffection
|
lost <- liftIO $ gegl_rectangle_intersect
|
||||||
liftIO $ traceIO $ show $ length $ haskelloids ud2
|
(GeglRectangle (floor nnx) (floor nny) 4 4)
|
||||||
|
(GeglRectangle
|
||||||
|
(floor $ fst $ sPos $ ship ud)
|
||||||
|
(floor $ snd $ sPos $ ship ud)
|
||||||
|
50
|
||||||
|
50
|
||||||
|
)
|
||||||
|
maybe (return ()) (\_ -> do
|
||||||
|
ad <- get
|
||||||
|
liftIO $ traceIO "YOU LOST!"
|
||||||
|
put ad
|
||||||
|
{ quitEvent = True
|
||||||
|
}
|
||||||
|
) lost
|
||||||
return part
|
return part
|
||||||
{ particlePosition = (nnx, nny)
|
{ particlePosition = (nnx, nny)
|
||||||
, particleTimeToLive = if (not $ null killings) then 0 else particleTimeToLive
|
, particleTimeToLive = if (not $ null killings) then 0 else particleTimeToLive
|
||||||
|
@ -320,31 +332,37 @@ shotsUpd sec part@Particle{..} = do
|
||||||
|
|
||||||
haskelloidShotDown :: Haskelloid -> Affection UserData ()
|
haskelloidShotDown :: Haskelloid -> Affection UserData ()
|
||||||
haskelloidShotDown h = do
|
haskelloidShotDown h = do
|
||||||
liftIO $ traceIO "Haskelloid shot down"
|
-- liftIO $ traceIO "Haskelloid shot down"
|
||||||
ud <- getAffection
|
ud <- getAffection
|
||||||
let redHaskelloids = delete h (haskelloids ud)
|
let redHaskelloids = delete h (haskelloids ud)
|
||||||
newHaskelloids <- catMaybes <$> foldM
|
newHaskelloids <- catMaybes <$> foldM
|
||||||
(\acc _ ->
|
(\acc _ ->
|
||||||
if hDiv h < 6
|
if hDiv h < 4
|
||||||
then
|
then
|
||||||
liftIO $ insertHaskelloid acc (Just $ hDiv h) $ hPos h
|
liftIO $ insertHaskelloid acc (Just $ hDiv h) $ hPos h
|
||||||
else
|
else
|
||||||
return $ Nothing : acc
|
return $ Nothing : acc
|
||||||
)
|
)
|
||||||
(map Just redHaskelloids) ([0..1] :: [Int])
|
(map Just redHaskelloids) ([0..1] :: [Int])
|
||||||
liftIO $ traceIO $ show $ length newHaskelloids
|
-- liftIO $ traceIO $ show $ length newHaskelloids
|
||||||
liftIO $ gegl_node_link_many $ map hFlange newHaskelloids
|
liftIO $ gegl_node_link_many $ map hFlange newHaskelloids
|
||||||
|
if not $ null newHaskelloids
|
||||||
|
then
|
||||||
|
liftIO $ gegl_node_link
|
||||||
|
(last $ map hFlange newHaskelloids)
|
||||||
|
(nodeGraph ud M.! KeyHNop)
|
||||||
|
else do
|
||||||
|
ad <- get
|
||||||
|
liftIO $ traceIO "YOU WON!"
|
||||||
|
put ad
|
||||||
|
{ quitEvent = True
|
||||||
|
}
|
||||||
putAffection ud
|
putAffection ud
|
||||||
{ haskelloids = newHaskelloids
|
{ haskelloids = newHaskelloids
|
||||||
}
|
}
|
||||||
|
|
||||||
shotsDraw :: GeglBuffer -> GeglNode -> Particle -> Affection UserData ()
|
shotsDraw :: GeglBuffer -> GeglNode -> Particle -> Affection UserData ()
|
||||||
shotsDraw _ _ _ = do
|
shotsDraw _ _ _ = return ()
|
||||||
-- present
|
|
||||||
-- (GeglRectangle (floor $ fst particlePosition - 2) (floor $ snd particlePosition - 2) 4 4)
|
|
||||||
-- buf
|
|
||||||
-- False
|
|
||||||
return ()
|
|
||||||
|
|
||||||
updateHaskelloid :: Double -> Haskelloid -> Affection UserData Haskelloid
|
updateHaskelloid :: Double -> Haskelloid -> Affection UserData Haskelloid
|
||||||
updateHaskelloid sec h@Haskelloid{..} = do
|
updateHaskelloid sec h@Haskelloid{..} = do
|
||||||
|
@ -359,6 +377,22 @@ updateHaskelloid sec h@Haskelloid{..} = do
|
||||||
liftIO $ gegl_node_set (hNodeGraph M.! "rot") $ Operation "gegl:rotate"
|
liftIO $ gegl_node_set (hNodeGraph M.! "rot") $ Operation "gegl:rotate"
|
||||||
[ Property "degrees" $ PropertyDouble newRot
|
[ Property "degrees" $ PropertyDouble newRot
|
||||||
]
|
]
|
||||||
|
ud <- getAffection
|
||||||
|
lost <- liftIO $ gegl_rectangle_intersect
|
||||||
|
(GeglRectangle (floor nnx) (floor nny) (100 `div` hDiv) (100 `div` hDiv))
|
||||||
|
(GeglRectangle
|
||||||
|
(floor $ fst $ sPos $ ship ud)
|
||||||
|
(floor $ snd $ sPos $ ship ud)
|
||||||
|
50
|
||||||
|
50
|
||||||
|
)
|
||||||
|
maybe (return ()) (\_ -> do
|
||||||
|
ad <- get
|
||||||
|
liftIO $ traceIO "YOU LOST!"
|
||||||
|
put ad
|
||||||
|
{ quitEvent = True
|
||||||
|
}
|
||||||
|
) lost
|
||||||
return h
|
return h
|
||||||
{ hPos = (nnx, nny)
|
{ hPos = (nnx, nny)
|
||||||
, hRot = newRot
|
, hRot = newRot
|
||||||
|
@ -366,14 +400,14 @@ updateHaskelloid sec h@Haskelloid{..} = do
|
||||||
|
|
||||||
insertHaskelloid :: [Maybe Haskelloid] -> Maybe Int -> (Double, Double) -> IO [Maybe Haskelloid]
|
insertHaskelloid :: [Maybe Haskelloid] -> Maybe Int -> (Double, Double) -> IO [Maybe Haskelloid]
|
||||||
insertHaskelloid hs split (px, py) = do
|
insertHaskelloid hs split (px, py) = do
|
||||||
liftIO $ traceIO "inserting haskelloid"
|
-- liftIO $ traceIO "inserting haskelloid"
|
||||||
vx <- liftIO $ randomRIO (-10, 10)
|
vx <- liftIO $ randomRIO (-10, 10)
|
||||||
vy <- liftIO $ randomRIO (-10, 10)
|
vy <- liftIO $ randomRIO (-10, 10)
|
||||||
rdiv <- case split of
|
rdiv <- case split of
|
||||||
Nothing -> liftIO $ randomRIO (1, 2)
|
Nothing -> liftIO $ randomRIO (1, 2)
|
||||||
Just x -> return $ x + 1
|
Just x -> return $ x + 1
|
||||||
rot <- liftIO $ randomRIO (-2 * pi, 2 * pi)
|
rot <- liftIO $ randomRIO (0, 360)
|
||||||
pitch <- liftIO $ randomRIO (-2 * pi, 2 * pi)
|
pitch <- liftIO $ randomRIO (-45, 45)
|
||||||
tempRoot <- liftIO $ gegl_node_new
|
tempRoot <- liftIO $ gegl_node_new
|
||||||
tempOver <- liftIO $ gegl_node_new_child tempRoot $ defaultOverOperation
|
tempOver <- liftIO $ gegl_node_new_child tempRoot $ defaultOverOperation
|
||||||
tempSvg <- gegl_node_new_child tempRoot $ Operation "gegl:svg-load"
|
tempSvg <- gegl_node_new_child tempRoot $ Operation "gegl:svg-load"
|
||||||
|
|
Loading…
Reference in a new issue