prepare hackable computers
This commit is contained in:
parent
35337651a0
commit
b14d9a6d76
4 changed files with 97 additions and 15 deletions
12
src/Load.hs
12
src/Load.hs
|
@ -62,7 +62,7 @@ loadFork
|
||||||
-> MVar (Float, T.Text)
|
-> MVar (Float, T.Text)
|
||||||
-> IO ()
|
-> IO ()
|
||||||
loadFork ws win glc nvg future progress = do
|
loadFork ws win glc nvg future progress = do
|
||||||
let stateSteps = 35
|
let stateSteps = 36
|
||||||
increment = 1 / stateSteps
|
increment = 1 / stateSteps
|
||||||
SDL.glMakeCurrent win glc
|
SDL.glMakeCurrent win glc
|
||||||
modifyMVar_ progress (return . (\(p, _) ->
|
modifyMVar_ progress (return . (\(p, _) ->
|
||||||
|
@ -272,6 +272,15 @@ loadFork ws win glc nvg future progress = do
|
||||||
, AnimationConfig (0, 0) (64, 74) (64, 0) 2 2 APLoop
|
, AnimationConfig (0, 0) (64, 74) (64, 0) 2 2 APLoop
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
modifyMVar_ progress (return . (\(p, _) ->
|
||||||
|
( p + increment
|
||||||
|
, "Loading Animation \"computer: hack\""
|
||||||
|
)))
|
||||||
|
computerHack <- loadAnimationSprites "assets/misc/tableCornerComputer.png" nvg
|
||||||
|
[ ( AnimId "computer" "hack" N
|
||||||
|
, AnimationConfig (0, 74) (64, 74) (64, 0) 4 2 APLoop
|
||||||
|
)
|
||||||
|
]
|
||||||
modifyMVar_ progress (return . (\(p, _) ->
|
modifyMVar_ progress (return . (\(p, _) ->
|
||||||
( p + increment
|
( p + increment
|
||||||
, "Loading Animation \"toilet: free\""
|
, "Loading Animation \"toilet: free\""
|
||||||
|
@ -307,6 +316,7 @@ loadFork ws win glc nvg future progress = do
|
||||||
copierStand ++
|
copierStand ++
|
||||||
copierCopy ++
|
copierCopy ++
|
||||||
computerOff ++
|
computerOff ++
|
||||||
|
computerHack ++
|
||||||
toiletFree ++
|
toiletFree ++
|
||||||
toiletOccupied
|
toiletOccupied
|
||||||
)
|
)
|
||||||
|
|
|
@ -157,6 +157,7 @@ loadMapFork ud ad future progress = do
|
||||||
, anim = Just $ AnimState (AnimId "computer" "off" N) 0 0
|
, anim = Just $ AnimState (AnimId "computer" "off" N) 0 0
|
||||||
, objAccess = Just $ (V2 1 (-1), dir)
|
, objAccess = Just $ (V2 1 (-1), dir)
|
||||||
, objType = Just ObjComputer
|
, objType = Just ObjComputer
|
||||||
|
, objState = Just "off"
|
||||||
}
|
}
|
||||||
) (A.log A.Debug ("number of computers: " ++ show (length computers)) computers)
|
) (A.log A.Debug ("number of computers: " ++ show (length computers)) computers)
|
||||||
void $ liftIO $ swapMVar progress (18 / loadSteps, "Registering toilets into WorldState")
|
void $ liftIO $ swapMVar progress (18 / loadSteps, "Registering toilets into WorldState")
|
||||||
|
|
|
@ -8,6 +8,9 @@ import Affection as A
|
||||||
import Control.Monad (when)
|
import Control.Monad (when)
|
||||||
|
|
||||||
import Data.Ecstasy
|
import Data.Ecstasy
|
||||||
|
import Data.Maybe
|
||||||
|
|
||||||
|
import Linear
|
||||||
|
|
||||||
import Types
|
import Types
|
||||||
|
|
||||||
|
@ -33,6 +36,38 @@ instance ObjectAction ObjType ObjState where
|
||||||
Just ttl -> return (ttl < 0)
|
Just ttl -> return (ttl < 0)
|
||||||
when trans (setEntity ent =<< objectTransition t s False ent)
|
when trans (setEntity ent =<< objectTransition t s False ent)
|
||||||
|
|
||||||
|
objectAction dt t@ObjComputer s@"hack" ent = do
|
||||||
|
[vel] <- efor allEnts $ do
|
||||||
|
with player
|
||||||
|
with vel
|
||||||
|
query vel
|
||||||
|
emap (anEnt ent) $ do
|
||||||
|
mtime <- queryMaybe objStateTime
|
||||||
|
case mtime of
|
||||||
|
Nothing -> do
|
||||||
|
liftIO $ logIO Debug ("Computer " ++ show ent ++ ": hacking!")
|
||||||
|
return unchanged
|
||||||
|
{ objStateTime = Set (actionTime t s)
|
||||||
|
}
|
||||||
|
Just ttl -> do
|
||||||
|
return unchanged
|
||||||
|
{ objStateTime = Set (ttl - dt)
|
||||||
|
}
|
||||||
|
[trans] <- efor (anEnt ent) $ do
|
||||||
|
mttl <- queryMaybe objStateTime
|
||||||
|
case mttl of
|
||||||
|
Nothing -> return Nothing
|
||||||
|
Just ttl -> do
|
||||||
|
if (ttl < 0) || vel `dot` vel > 0
|
||||||
|
then do
|
||||||
|
tpa <- query objPlayerActivated
|
||||||
|
return (Just tpa)
|
||||||
|
else return Nothing
|
||||||
|
maybe
|
||||||
|
(return ())
|
||||||
|
(\tpa -> setEntity ent =<< objectTransition t s tpa ent)
|
||||||
|
trans
|
||||||
|
|
||||||
objectAction _ _ _ _ = return ()
|
objectAction _ _ _ _ = return ()
|
||||||
|
|
||||||
objectTransition ObjCopier "idle" playerActivated ent = do
|
objectTransition ObjCopier "idle" playerActivated ent = do
|
||||||
|
@ -50,25 +85,60 @@ instance ObjectAction ObjType ObjState where
|
||||||
|
|
||||||
objectTransition ObjCopier "copying" _ ent = do
|
objectTransition ObjCopier "copying" _ ent = do
|
||||||
[e] <- efor (anEnt ent) $ do
|
[e] <- efor (anEnt ent) $ do
|
||||||
ttl <- query objStateTime
|
ttl <- query objStateTime
|
||||||
if ttl < 0
|
if ttl < 0
|
||||||
then do
|
then do
|
||||||
let nstat = AnimState
|
let nstat = AnimState
|
||||||
(AnimId "copier" "open" N)
|
(AnimId "copier" "open" N)
|
||||||
0
|
0
|
||||||
0
|
0
|
||||||
return unchanged
|
return unchanged
|
||||||
{ anim = Set nstat
|
{ anim = Set nstat
|
||||||
, objState = Set "idle"
|
, objState = Set "idle"
|
||||||
, objStateTime = Unset
|
, objStateTime = Unset
|
||||||
, objPlayerActivated = Unset
|
, objPlayerActivated = Unset
|
||||||
}
|
}
|
||||||
else return unchanged
|
else return unchanged
|
||||||
|
return e
|
||||||
|
|
||||||
|
objectTransition ObjComputer "off" pa ent = do
|
||||||
|
[e] <- efor (anEnt ent) $ do
|
||||||
|
solved <- queryMaybe objSolved
|
||||||
|
if pa && not (fromMaybe False solved)
|
||||||
|
then do
|
||||||
|
let nstat = AnimState
|
||||||
|
(AnimId "computer" "hack" N)
|
||||||
|
0
|
||||||
|
0
|
||||||
|
return unchanged
|
||||||
|
{ anim = Set nstat
|
||||||
|
, objState = Set "hack"
|
||||||
|
, objPlayerActivated = Set True
|
||||||
|
}
|
||||||
|
else return unchanged
|
||||||
|
return e
|
||||||
|
|
||||||
|
objectTransition ObjComputer "hack" _ ent = do
|
||||||
|
[e] <- efor (anEnt ent) $ do
|
||||||
|
let nstat = AnimState
|
||||||
|
(AnimId "computer" "off" N)
|
||||||
|
0
|
||||||
|
0
|
||||||
|
ost <- query objStateTime
|
||||||
|
return unchanged
|
||||||
|
{ anim = Set nstat
|
||||||
|
, objState = Set "off"
|
||||||
|
, objPlayerActivated = Unset
|
||||||
|
, objStateTime = Unset
|
||||||
|
, objSolved = Set (ost < 0)
|
||||||
|
}
|
||||||
return e
|
return e
|
||||||
|
|
||||||
objectTransition _ _ _ _ = return unchanged
|
objectTransition _ _ _ _ = return unchanged
|
||||||
|
|
||||||
instance ActionTime ObjType ObjState where
|
instance ActionTime ObjType ObjState where
|
||||||
actionTime ObjCopier "copying" = 5
|
actionTime ObjCopier "copying" = 5
|
||||||
|
actionTime ObjComputer "off" = 0
|
||||||
|
actionTime ObjComputer "hack" = 20
|
||||||
|
|
||||||
actionTime o s = A.log Error (show o ++ ": " ++ s ++ ": has not time") 0
|
actionTime o s = A.log Error (show o ++ ": " ++ s ++ ": has not time") 0
|
||||||
|
|
|
@ -27,5 +27,6 @@ data Entity f = Entity
|
||||||
, objState :: Component f 'Field ObjState
|
, objState :: Component f 'Field ObjState
|
||||||
, objStateTime :: Component f 'Field Double
|
, objStateTime :: Component f 'Field Double
|
||||||
, objPlayerActivated :: Component f 'Field Bool
|
, objPlayerActivated :: Component f 'Field Bool
|
||||||
|
, objSolved :: Component f 'Field Bool
|
||||||
}
|
}
|
||||||
deriving (Generic)
|
deriving (Generic)
|
||||||
|
|
Loading…
Reference in a new issue