From a1af74be7458fa4792ae9e6af3d2ef5caf3db5c3 Mon Sep 17 00:00:00 2001 From: nek0 Date: Wed, 20 Jan 2021 05:12:16 +0100 Subject: [PATCH 1/2] make camera follow the cat --- src/Scenes/Test.hs | 14 ++++++++++++++ src/Scenes/Test/Load.hs | 35 ++++++++++++++++++----------------- src/Scenes/Test/Types.hs | 9 +++++++++ 3 files changed, 41 insertions(+), 17 deletions(-) diff --git a/src/Scenes/Test.hs b/src/Scenes/Test.hs index 102a3bb..5c2c2da 100644 --- a/src/Scenes/Test.hs +++ b/src/Scenes/Test.hs @@ -5,6 +5,8 @@ module Scenes.Test import Affection as A +import Linear + import qualified Data.Vector.Storable as VS import qualified Data.Vector as V @@ -33,6 +35,7 @@ instance Scene Test where <*> newTVarIO Nothing <*> newTVarIO V.empty <*> newTVarIO V.empty + <*> newTVarIO (PVM identity identity identity) <*> newTVarIO [] loadScene = load @@ -52,6 +55,17 @@ instance Scene Test where nonPlayerCast <- readTVarIO (testCast level) pituicat <- atomically $ readTVar (testPlayer level) let cast = Cast (fromJust pituicat) `V.cons` nonPlayerCast + playerPos@(V2 px py) = realToFrac <$> (pcPos $ fromJust pituicat) + + atomically $ modifyTVar (testMatrices level) $ \pvm -> + pvm + { pvmV = mkTransformationMat + identity + (V3 (400 - px) (300 - py) 0) + } + + (PVM p v m) <- atomically $ readTVar (testMatrices level) + setUniform sh "u_mvp" (p !*! v !*! m) let (indices, vertices) = populate layers stageSet cast diff --git a/src/Scenes/Test/Load.hs b/src/Scenes/Test/Load.hs index 3d6d01d..66e0918 100644 --- a/src/Scenes/Test/Load.hs +++ b/src/Scenes/Test/Load.hs @@ -34,12 +34,6 @@ load level progress = do putTMVar progress (0.5, "Loaded test level map!") void $ atomically $ swapTVar (testLoaded level) True - let projection = ortho 0 800 0 600 (-1) 1 :: M44 GL.GLfloat - view = mkTransformationMat - (identity :: M33 GL.GLfloat) - (V3 0 ((-64) * 32 + 600) 0) - model = mkTransformationMat (identity :: M33 GL.GLfloat) (V3 0 0 0) - vertexArray <- newVertexArray bind vertexArray @@ -70,6 +64,23 @@ load level progress = do , ShaderSource GL.FragmentShader "./res/shaders/frag.shader" ] + let projection = ortho 0 800 0 600 (-1) 1 :: M44 GL.GLfloat + view = mkTransformationMat + (identity :: M33 GL.GLfloat) + (V3 (400 - sx) (300 - sy) 0) + model = mkTransformationMat (identity :: M33 GL.GLfloat) (V3 0 0 0) + startpos@(V2 sx sy) = V2 100 1948 + pituicat = Pituicat + (realToFrac <$> startpos) + (V2 0 0) + (V2 0 0) + (V2 0 0) + (V2 0 0) + 100 + tex + False + Nothing + bind shader setUniform shader "u_mvp" (projection !*! view !*! model) setUniformList @@ -82,17 +93,6 @@ load level progress = do ] ) - let pituicat = Pituicat - (V2 100 1948) - (V2 0 1) - (V2 0 0) - (V2 0 0) - (V2 0 0) - 100 - tex - False - Nothing - unbind vertexArray unbind vertexBuffer unbind indexBuffer @@ -104,6 +104,7 @@ load level progress = do (GLAssets vertexArray vertexBuffer indexBuffer shader [tex]) writeTVar (testPlayer level) (Just pituicat) writeTVar (testLoaded level) True + writeTVar (testMatrices level) (PVM projection view model) void $ atomically $ do void $ takeTMVar progress diff --git a/src/Scenes/Test/Types.hs b/src/Scenes/Test/Types.hs index 64281cd..daeda6a 100644 --- a/src/Scenes/Test/Types.hs +++ b/src/Scenes/Test/Types.hs @@ -2,6 +2,8 @@ module Scenes.Test.Types where import Affection +import Linear + import Control.Concurrent.STM import qualified Data.Vector as V @@ -17,6 +19,7 @@ data Test = Test , testPlayer :: TVar (Maybe Pituicat) , testStageSet :: TVar (V.Vector StageSet) , testCast :: TVar (V.Vector Cast) + , testMatrices :: TVar PVM , testClean :: TVar [UUID] } @@ -27,3 +30,9 @@ data GLAssets = GLAssets , glSP :: Shader , glTx :: [Texture] } + +data PVM = PVM + { pvmP :: M44 Float + , pvmV :: M44 Float + , pvmM :: M44 Float + } From f9ff9d1db20151f0b4de975d0d99f2817f244d96 Mon Sep 17 00:00:00 2001 From: nek0 Date: Wed, 20 Jan 2021 05:20:56 +0100 Subject: [PATCH 2/2] zero allmovement in collision direction --- src/Types/Player.hs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Types/Player.hs b/src/Types/Player.hs index 31a2521..21ec06d 100644 --- a/src/Types/Player.hs +++ b/src/Types/Player.hs @@ -162,5 +162,13 @@ instance Collidible Pituicat where if dirx /= 0 then V2 0 1 else V2 1 1 + , pcTMoveVel = pcTMoveVel ncat * + if dirx /= 0 + then V2 0 1 + else V2 1 1 + , pcVel = pcVel ncat * + if dirx /= 0 + then V2 0 1 + else V2 1 1 } )