2021-01-02 12:32:20 +00:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
2020-12-23 06:47:20 +00:00
|
|
|
module Types.Player where
|
|
|
|
|
2021-01-02 12:32:20 +00:00
|
|
|
import Affection as A
|
|
|
|
|
2020-12-23 06:47:20 +00:00
|
|
|
import Linear
|
|
|
|
|
|
|
|
import qualified Data.Vector as V
|
|
|
|
|
2021-01-02 12:32:20 +00:00
|
|
|
import Data.String (fromString)
|
|
|
|
|
2020-12-23 06:47:20 +00:00
|
|
|
-- internal imports
|
|
|
|
|
2021-01-11 23:53:00 +00:00
|
|
|
import Util
|
|
|
|
|
2020-12-23 06:47:20 +00:00
|
|
|
import Classes.Graphics.Drawable
|
|
|
|
import Classes.Graphics.Bindable
|
|
|
|
import Classes.Prop
|
2020-12-24 11:01:59 +00:00
|
|
|
import Classes.Actor
|
2021-01-02 12:32:20 +00:00
|
|
|
import Classes.Physics
|
2020-12-23 06:47:20 +00:00
|
|
|
|
|
|
|
import Types.Graphics.VertexBuffer
|
|
|
|
import Types.Texture
|
|
|
|
|
|
|
|
data Pituicat = Pituicat
|
|
|
|
{ pcPos :: V2 Double
|
|
|
|
, pcVel :: V2 Double
|
|
|
|
, pcAcc :: V2 Double
|
|
|
|
, pcHealth :: Int
|
|
|
|
, pcTexture :: Texture
|
2021-01-11 23:51:58 +00:00
|
|
|
, pcGrounded :: Bool
|
2020-12-23 06:47:20 +00:00
|
|
|
}
|
2021-01-02 12:32:20 +00:00
|
|
|
deriving (Eq, Show)
|
2020-12-23 06:47:20 +00:00
|
|
|
|
|
|
|
instance Drawable Pituicat where
|
|
|
|
|
2021-01-11 23:51:58 +00:00
|
|
|
toVertices (Pituicat (V2 x y) _ _ _ _ _) =
|
2020-12-23 06:47:20 +00:00
|
|
|
( V.fromList [0, 1, 2, 2, 3, 0]
|
|
|
|
, V.fromList
|
|
|
|
[ newVertex
|
|
|
|
(V3 (realToFrac x - 25) (realToFrac y - 25) 0)
|
2020-12-23 16:16:30 +00:00
|
|
|
(V4 1 1 1 1)
|
2020-12-23 06:47:20 +00:00
|
|
|
(V2 0 (1 - 50 / 1024))
|
|
|
|
1
|
|
|
|
, newVertex
|
|
|
|
(V3 (realToFrac x + 25) (realToFrac y - 25) 0)
|
2020-12-23 16:16:30 +00:00
|
|
|
(V4 1 1 1 1)
|
2020-12-23 06:47:20 +00:00
|
|
|
(V2 (50 / 1024) (1 - 50 / 1024))
|
|
|
|
1
|
|
|
|
, newVertex
|
|
|
|
(V3 (realToFrac x + 25) (realToFrac y + 25) 0)
|
2020-12-23 16:16:30 +00:00
|
|
|
(V4 1 1 1 1)
|
2020-12-23 06:47:20 +00:00
|
|
|
(V2 (50 / 1024) 1)
|
|
|
|
1
|
|
|
|
, newVertex
|
|
|
|
(V3 (realToFrac x - 25) (realToFrac y + 25) 0)
|
2020-12-23 16:16:30 +00:00
|
|
|
(V4 1 1 1 1)
|
2020-12-23 15:39:45 +00:00
|
|
|
(V2 0 1)
|
2020-12-23 06:47:20 +00:00
|
|
|
1
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
instance Prop Pituicat where
|
|
|
|
|
|
|
|
residentLayer _ = 0
|
|
|
|
|
|
|
|
bindPropTexture = bind . pcTexture
|
2020-12-24 11:01:59 +00:00
|
|
|
|
|
|
|
instance Actor Pituicat where
|
|
|
|
|
2021-01-11 23:51:58 +00:00
|
|
|
perform dt p =
|
2021-01-11 23:53:00 +00:00
|
|
|
let physCat = (accelerate dt . gravitate constG)
|
2021-01-11 23:51:58 +00:00
|
|
|
(p {pcAcc = 0})
|
|
|
|
(V2 _ dy) = pcVel physCat
|
|
|
|
finalCat = physCat
|
2021-01-11 23:53:00 +00:00
|
|
|
{ pcGrounded = pcGrounded physCat || (dy < 0 && abs dy < 2)
|
2021-01-11 23:51:58 +00:00
|
|
|
}
|
|
|
|
in
|
|
|
|
(A.log Debug ("moving with " <> fromString (show $ pcVel finalCat))) finalCat
|
2021-01-02 12:32:20 +00:00
|
|
|
|
|
|
|
instance Mass Pituicat where
|
|
|
|
|
|
|
|
mass _ = 1
|
|
|
|
|
|
|
|
acceleration = pcAcc
|
|
|
|
|
|
|
|
accelerationUpdater cat =
|
|
|
|
(\accel -> cat
|
|
|
|
{ pcAcc = accel
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
velocity = pcVel
|
|
|
|
|
|
|
|
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))
|
2021-01-11 23:51:58 +00:00
|
|
|
(let ncat = (elasticCollision 0.3 cat other)
|
|
|
|
(V2 _ dy) = pcVel ncat
|
|
|
|
in
|
|
|
|
ncat
|
2021-01-11 23:53:00 +00:00
|
|
|
{ pcGrounded = dy > 0 && abs dy < 2
|
2021-01-11 23:51:58 +00:00
|
|
|
}
|
|
|
|
)
|