more beautiful winning and losing
This commit is contained in:
parent
ac2a71cdc4
commit
8257b69c97
1 changed files with 131 additions and 111 deletions
40
src/Main.hs
40
src/Main.hs
|
@ -62,6 +62,16 @@ load _ = do
|
||||||
sink <- gegl_node_new_child root $ Operation "gegl:copy-buffer"
|
sink <- gegl_node_new_child root $ Operation "gegl:copy-buffer"
|
||||||
[ Property "buffer" $ PropertyBuffer buffer
|
[ Property "buffer" $ PropertyBuffer buffer
|
||||||
]
|
]
|
||||||
|
won <- gegl_node_new_child root $ textOperation
|
||||||
|
[ Property "string" $ PropertyString "YOU WON!"
|
||||||
|
, Property "size" $ PropertyDouble 100
|
||||||
|
, Property "color" $ PropertyColor $ GEGL.RGBA 1 1 1 1
|
||||||
|
]
|
||||||
|
lost <- gegl_node_new_child root $ textOperation
|
||||||
|
[ Property "string" $ PropertyString "YOU LOST!"
|
||||||
|
, Property "size" $ PropertyDouble 100
|
||||||
|
, Property "color" $ PropertyColor $ GEGL.RGBA 1 1 1 1
|
||||||
|
]
|
||||||
gegl_node_link_many [ship, rotate, translate]
|
gegl_node_link_many [ship, rotate, translate]
|
||||||
gegl_node_link_many [pover, hover, sover, crop, sink]
|
gegl_node_link_many [pover, hover, sover, crop, sink]
|
||||||
_ <- gegl_node_connect_to translate "output" sover "aux"
|
_ <- gegl_node_connect_to translate "output" sover "aux"
|
||||||
|
@ -78,6 +88,8 @@ load _ = do
|
||||||
, (KeyCrop, crop)
|
, (KeyCrop, crop)
|
||||||
, (KeyShipOver, sover)
|
, (KeyShipOver, sover)
|
||||||
, (KeySink, sink)
|
, (KeySink, sink)
|
||||||
|
, (KeyWon, won)
|
||||||
|
, (KeyLost, lost)
|
||||||
]
|
]
|
||||||
hs <- catMaybes <$> foldM (\acc _ -> do
|
hs <- catMaybes <$> foldM (\acc _ -> do
|
||||||
px <- liftIO $ randomRIO (0, 800)
|
px <- liftIO $ randomRIO (0, 800)
|
||||||
|
@ -97,6 +109,7 @@ load _ = do
|
||||||
, buffer = buffer
|
, buffer = buffer
|
||||||
, shots = ParticleSystem (ParticleStorage Nothing []) pnop buffer
|
, shots = ParticleSystem (ParticleStorage Nothing []) pnop buffer
|
||||||
, haskelloids = hs
|
, haskelloids = hs
|
||||||
|
, wonlost = False
|
||||||
}
|
}
|
||||||
|
|
||||||
data UserData = UserData
|
data UserData = UserData
|
||||||
|
@ -106,6 +119,7 @@ data UserData = UserData
|
||||||
, haskelloids :: [Haskelloid]
|
, haskelloids :: [Haskelloid]
|
||||||
, shots :: ParticleSystem
|
, shots :: ParticleSystem
|
||||||
-- , debris :: ParticleSystem
|
-- , debris :: ParticleSystem
|
||||||
|
, wonlost :: Bool
|
||||||
}
|
}
|
||||||
|
|
||||||
data Ship = Ship
|
data Ship = Ship
|
||||||
|
@ -135,12 +149,17 @@ data NodeKey
|
||||||
| KeyCrop
|
| KeyCrop
|
||||||
| KeyShipOver
|
| KeyShipOver
|
||||||
| KeySink
|
| KeySink
|
||||||
|
| KeyWon
|
||||||
|
| KeyLost
|
||||||
deriving (Ord, Eq)
|
deriving (Ord, Eq)
|
||||||
|
|
||||||
update :: Double -> Affection UserData ()
|
update :: Double -> Affection UserData ()
|
||||||
update sec = do
|
update sec = do
|
||||||
-- traceM $ (show $ 1 / sec) ++ " FPS"
|
-- traceM $ (show $ 1 / sec) ++ " FPS"
|
||||||
ad <- get
|
ad <- get
|
||||||
|
wd <- getAffection
|
||||||
|
if (not $ wonlost wd)
|
||||||
|
then do
|
||||||
evs <- SDL.pollEvents
|
evs <- SDL.pollEvents
|
||||||
mapM_ (\e ->
|
mapM_ (\e ->
|
||||||
case SDL.eventPayload e of
|
case SDL.eventPayload e of
|
||||||
|
@ -247,6 +266,7 @@ update sec = do
|
||||||
}
|
}
|
||||||
, shots = ups
|
, shots = ups
|
||||||
}
|
}
|
||||||
|
else return ()
|
||||||
|
|
||||||
wrapAround :: (Ord t, Num t) => (t, t) -> t -> (t, t)
|
wrapAround :: (Ord t, Num t) => (t, t) -> t -> (t, t)
|
||||||
wrapAround (nx, ny) width = (nnx, nny)
|
wrapAround (nx, ny) width = (nnx, nny)
|
||||||
|
@ -278,7 +298,7 @@ draw = do
|
||||||
present
|
present
|
||||||
(GeglRectangle 0 0 800 600)
|
(GeglRectangle 0 0 800 600)
|
||||||
(buffer ud)
|
(buffer ud)
|
||||||
False
|
(not $ wonlost ud)
|
||||||
|
|
||||||
clean :: UserData -> IO ()
|
clean :: UserData -> IO ()
|
||||||
clean _ = return ()
|
clean _ = return ()
|
||||||
|
@ -319,10 +339,10 @@ shotsUpd sec part@Particle{..} = do
|
||||||
50
|
50
|
||||||
)
|
)
|
||||||
maybe (return ()) (\_ -> do
|
maybe (return ()) (\_ -> do
|
||||||
ad <- get
|
|
||||||
liftIO $ traceIO "YOU LOST!"
|
liftIO $ traceIO "YOU LOST!"
|
||||||
put ad
|
liftIO $ gegl_node_link (nodeGraph ud M.! KeyLost) (nodeGraph ud M.! KeySink)
|
||||||
{ quitEvent = True
|
putAffection ud
|
||||||
|
{ wonlost = True
|
||||||
}
|
}
|
||||||
) lost
|
) lost
|
||||||
return part
|
return part
|
||||||
|
@ -352,10 +372,10 @@ haskelloidShotDown h = do
|
||||||
(last $ map hFlange newHaskelloids)
|
(last $ map hFlange newHaskelloids)
|
||||||
(nodeGraph ud M.! KeyHNop)
|
(nodeGraph ud M.! KeyHNop)
|
||||||
else do
|
else do
|
||||||
ad <- get
|
|
||||||
liftIO $ traceIO "YOU WON!"
|
liftIO $ traceIO "YOU WON!"
|
||||||
put ad
|
liftIO $ gegl_node_link (nodeGraph ud M.! KeyWon) (nodeGraph ud M.! KeySink)
|
||||||
{ quitEvent = True
|
putAffection ud
|
||||||
|
{ wonlost = True
|
||||||
}
|
}
|
||||||
putAffection ud
|
putAffection ud
|
||||||
{ haskelloids = newHaskelloids
|
{ haskelloids = newHaskelloids
|
||||||
|
@ -387,10 +407,10 @@ updateHaskelloid sec h@Haskelloid{..} = do
|
||||||
50
|
50
|
||||||
)
|
)
|
||||||
maybe (return ()) (\_ -> do
|
maybe (return ()) (\_ -> do
|
||||||
ad <- get
|
|
||||||
liftIO $ traceIO "YOU LOST!"
|
liftIO $ traceIO "YOU LOST!"
|
||||||
put ad
|
liftIO $ gegl_node_link (nodeGraph ud M.! KeyLost) (nodeGraph ud M.! KeySink)
|
||||||
{ quitEvent = True
|
putAffection ud
|
||||||
|
{ wonlost = True
|
||||||
}
|
}
|
||||||
) lost
|
) lost
|
||||||
return h
|
return h
|
||||||
|
|
Loading…
Reference in a new issue