{-# LANGUAGE OverloadedStrings #-} module Types.Player where import Affection as A import Linear import qualified Data.Vector as V import Data.String (fromString) -- internal imports import Util import Classes.Graphics.Drawable import Classes.Graphics.Bindable import Classes.Prop import Classes.Actor import Classes.Physics import Types.Graphics.VertexBuffer import Types.Texture import Types.Subsystems catMoveVelocity :: Double catMoveVelocity = 10 data Pituicat = Pituicat { pcPos :: V2 Double , pcVel :: V2 Double , pcMoveVel :: V2 Double , pcAcc :: V2 Double , pcHealth :: Int , pcTexture :: Texture , pcGrounded :: Bool , pcMoveState :: Maybe Action } deriving (Eq, Show) instance Drawable Pituicat where toVertices (Pituicat (V2 x y) _ _ _ _ _ _ _) = ( V.fromList [0, 1, 2, 2, 3, 0] , V.fromList [ newVertex (V3 (realToFrac x - 25) (realToFrac y - 25) 0) (V4 1 1 1 1) (V2 0 (1 - 50 / 1024)) 1 , newVertex (V3 (realToFrac x + 25) (realToFrac y - 25) 0) (V4 1 1 1 1) (V2 (50 / 1024) (1 - 50 / 1024)) 1 , newVertex (V3 (realToFrac x + 25) (realToFrac y + 25) 0) (V4 1 1 1 1) (V2 (50 / 1024) 1) 1 , newVertex (V3 (realToFrac x - 25) (realToFrac y + 25) 0) (V4 1 1 1 1) (V2 0 1) 1 ] ) instance Prop Pituicat where residentLayer _ = 0 bindPropTexture = bind . pcTexture instance Actor Pituicat where perform dt p = let physCat = (move dt . accelerate dt . gravitate constG) (p {pcAcc = 0}) (V2 vx vy) = pcVel physCat finalCat = physCat { pcGrounded = (vy <= 0 && abs vy < 30 ) , pcMoveVel = case pcMoveState physCat of Just MoveRight -> V2 catMoveVelocity 0 Just MoveLeft -> V2 (-catMoveVelocity) 0 _ -> V2 0 0 } in (A.log Debug ( ("being at " <> fromString (show $ pcPos finalCat)) <> ("; moving with " <> fromString (show $ pcVel finalCat)) ) ) finalCat instance Mass Pituicat where mass _ = 1 acceleration = pcAcc accelerationUpdater cat = (\accel -> cat { pcAcc = accel } ) velocity cat = pcVel cat + pcMoveVel cat velocityUpdater cat = (\vel -> cat { pcVel = vel } ) position = pcPos positionUpdater cat = (\pos -> cat { pcPos = pos } ) instance Collidible Pituicat where boundary _ = ( V2 (-25) (-25) , V2 25 25 ) collide cat other = A.log Debug ("*boing* meow! other: " <> fromString (show other)) (let ncat = (elasticCollision 0.3 cat other) (V2 _ dy) = pcVel ncat in ncat )