module MStateGameMain (newMStateGameMain) where import Graphics.Rendering.OpenGL import Graphics.UI.GLUT import States import VectorMaps import Action (nextVelocity2 , nextPosition2) import qualified Data.Map as Map -----新しいMStateの作成 newMStateGameMain :: MState -> KState -> DState -> MState newMStateGameMain mst kst dst = changeMStateGState mst (newGState kst mst (gState mst)) -----GStateの更新 newGState :: KState -> MState-> GState -> GState newGState kst mst gst = let gObjs = gStateObjs gst gObjsF = map (newGObjectMoveF gstg) gObjs ---キーによる変化 gstg = gStage gst gObjsFK = map (newGObjectMoveKey kst) gObjsF newGObjs = map (newGObjectPosType mst) gObjsFK in changeGStateGObject gst newGObjs -----力や速度によるGObjectの更新 newGObjectMoveF :: GStage -> GObject -> GObject newGObjectMoveF gstg gObj = let pos = posGObj gObj vel = velGObj gObj acc = accGObj gObj pB = boundaryStage gstg newPos = nextPosition2 pB pos vel newVel = nextVelocity2 pB pos vel acc in changeGObjectPVA gObj newPos newVel acc -----キーによるGObjectの更新 newGObjectMoveKey :: KState -> GObject -> GObject newGObjectMoveKey kst gObj = changeGObjectByAct (changeGObjectActionKey kst gObj) -----ActionによるGObjectの速度を更新 changeGObjectByAct :: GObject -> GObject changeGObjectByAct gObj = let gAData = gActionDatas gObj aname = gAction gObj newaction = (\(Just x) -> x) (Map.lookup aname gAData) gObjV = velGObj gObj gObjVx = vectorElementX gObjV gObjVy = vectorElementY gObjV in case (actionVelX newaction) of Nothing -> case (actionVelY newaction) of Nothing -> gObj Just y -> changeGObjectVel gObj (Vector2 gObjVx y) Just x -> case (actionVelY newaction) of Nothing -> changeGObjectVel gObj (Vector2 x gObjVy) Just y -> changeGObjectVel gObj (Vector2 x y) -----キーによるGObjectのActionの変更 changeGObjectActionKey :: KState -> GObject -> GObject changeGObjectActionKey kst gObj = let ks = keyS kst gPType = gPosType gObj in if gPType == OnGround then case (cKey ks) of Just (SpecialKey KeyRight) -> changeGObjectGAction gObj AWalkF Just (SpecialKey KeyLeft) -> changeGObjectGAction gObj AWalkB Just (SpecialKey KeyUp) -> if (downKeyCount ks) == 0 then changeGObjectGAction gObj AJump else changeGObjectGAction gObj ANeutral _ -> changeGObjectGAction gObj AStand else changeGObjectGAction gObj ANeutral -----位置によるPosTypeの決定 getGObjectPosType :: GObject -> GLfloat -> PosType getGObjectPosType gObj gh | gObjY > gh = OverGround | otherwise = OnGround where gObjY = (vectorElementY (posGObj gObj)) -----位置によるPosTypeの変更 newGObjectPosType :: MState -> GObject -> GObject newGObjectPosType mst gObj = let gst = gState mst gstag = gStage gst pbound = boundaryStage gstag pboundY = vectorElementY pbound groundH = minPBound pboundY in changeGObjectPosType gObj (getGObjectPosType gObj groundH)