add player and tinker around
This commit is contained in:
parent
a859814fda
commit
2f03adc8f4
|
@ -30,6 +30,7 @@ executable pituicat
|
||||||
, Types.Graphics.IndexBuffer
|
, Types.Graphics.IndexBuffer
|
||||||
, Types.Graphics.Shader
|
, Types.Graphics.Shader
|
||||||
, Types.Util
|
, Types.Util
|
||||||
|
, Types.Player
|
||||||
, Classes
|
, Classes
|
||||||
, Classes.Scene
|
, Classes.Scene
|
||||||
, Classes.Actor
|
, Classes.Actor
|
||||||
|
|
|
@ -6,12 +6,12 @@ in vec4 v_color;
|
||||||
in vec2 v_texCoord;
|
in vec2 v_texCoord;
|
||||||
in float v_texIndex;
|
in float v_texIndex;
|
||||||
|
|
||||||
uniform sampler2D u_texture;
|
uniform sampler2D[2] u_textures;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
//vec4 texColor = texture(u_texture, v_texCoord);
|
//vec4 texColor = texture(u_texture, v_texCoord);
|
||||||
//int index = int(v_texIndex);
|
int index = int(v_texIndex);
|
||||||
color = texture(u_texture, v_texCoord);
|
color = texture(u_textures[index], v_texCoord);
|
||||||
//color = vec4(0.0, 1.0, 0.0, 1.0);
|
//color = vec4(0.0, 1.0, 0.0, 1.0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,10 @@ module Classes.Prop where
|
||||||
|
|
||||||
import Classes.Graphics.Drawable
|
import Classes.Graphics.Drawable
|
||||||
|
|
||||||
|
import Types.Texture
|
||||||
|
|
||||||
class (Drawable a) => Prop a where
|
class (Drawable a) => Prop a where
|
||||||
|
|
||||||
residentLayer :: a -> Word
|
residentLayer :: a -> Word
|
||||||
|
|
||||||
|
bindPropTexture :: a -> IO ()
|
||||||
|
|
|
@ -38,7 +38,7 @@ data GLAssets = GLAssets
|
||||||
, glVB :: VertexBuffer
|
, glVB :: VertexBuffer
|
||||||
, glIB :: IndexBuffer
|
, glIB :: IndexBuffer
|
||||||
, glSP :: Shader
|
, glSP :: Shader
|
||||||
, glTx :: Texture
|
, glTx :: [Texture]
|
||||||
}
|
}
|
||||||
|
|
||||||
instance Scene Test where
|
instance Scene Test where
|
||||||
|
@ -91,7 +91,6 @@ instance Scene Test where
|
||||||
addBuffer (undefined :: Vertex) vertexBuffer
|
addBuffer (undefined :: Vertex) vertexBuffer
|
||||||
|
|
||||||
(_, tex) <- newTexture "res/pituicat/pituicat.png" 1
|
(_, tex) <- newTexture "res/pituicat/pituicat.png" 1
|
||||||
|
|
||||||
bind tex
|
bind tex
|
||||||
|
|
||||||
shader <- newShader
|
shader <- newShader
|
||||||
|
@ -101,7 +100,22 @@ instance Scene Test where
|
||||||
|
|
||||||
bind shader
|
bind shader
|
||||||
setUniform shader "u_mvp" (projection !*! view !*! model)
|
setUniform shader "u_mvp" (projection !*! view !*! model)
|
||||||
setUniform shader "u_texture" (0 :: GL.GLint)
|
setUniformList
|
||||||
|
shader
|
||||||
|
"u_textures"
|
||||||
|
(map
|
||||||
|
((\(GL.TextureObject o) -> o) . textureId)
|
||||||
|
[ (tileMapTexture $ mapTileMap loadedMap)
|
||||||
|
, tex
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
let pituicat = Pituicat
|
||||||
|
(V2 0 (-1748))
|
||||||
|
(V2 0 0)
|
||||||
|
(V2 0 0)
|
||||||
|
100
|
||||||
|
tex
|
||||||
|
|
||||||
unbind vertexArray
|
unbind vertexArray
|
||||||
unbind vertexBuffer
|
unbind vertexBuffer
|
||||||
|
@ -111,7 +125,8 @@ instance Scene Test where
|
||||||
|
|
||||||
atomically $ do
|
atomically $ do
|
||||||
putTMVar (testGraphics level)
|
putTMVar (testGraphics level)
|
||||||
(GLAssets vertexArray vertexBuffer indexBuffer shader tex)
|
(GLAssets vertexArray vertexBuffer indexBuffer shader [tex])
|
||||||
|
modifyTVar (testStageSet level) (\set -> StageSet pituicat `V.cons` set)
|
||||||
writeTVar (testLoaded level) True
|
writeTVar (testLoaded level) True
|
||||||
|
|
||||||
void $ atomically $ do
|
void $ atomically $ do
|
||||||
|
@ -119,7 +134,7 @@ instance Scene Test where
|
||||||
putTMVar progress (1, "Loaded graphics!")
|
putTMVar progress (1, "Loaded graphics!")
|
||||||
|
|
||||||
|
|
||||||
isSceneLoaded = liftIO . atomically . readTVar . testLoaded
|
isSceneLoaded = liftIO . readTVarIO . testLoaded
|
||||||
|
|
||||||
update level dt = liftIO $ do
|
update level dt = liftIO $ do
|
||||||
logIO Debug ("FPS: " <> fromString (show $ 1 / dt))
|
logIO Debug ("FPS: " <> fromString (show $ 1 / dt))
|
||||||
|
@ -132,22 +147,39 @@ instance Scene Test where
|
||||||
(LevelMap layers _ _ tileMap _) <-
|
(LevelMap layers _ _ tileMap _) <-
|
||||||
atomically (readTMVar $ testMap level)
|
atomically (readTMVar $ testMap level)
|
||||||
|
|
||||||
stageSet <- atomically (readTVar $ testStageSet level)
|
logIO Debug "loaded level"
|
||||||
cast <- atomically (readTVar $ testCast level)
|
|
||||||
|
stageSet <- readTVarIO (testStageSet level)
|
||||||
|
cast <- readTVarIO (testCast level)
|
||||||
|
|
||||||
|
logIO Debug "Read stage set and cast"
|
||||||
|
|
||||||
let (indices, vertices) = populate layers stageSet cast
|
let (indices, vertices) = populate layers stageSet cast
|
||||||
|
|
||||||
|
logIO Debug "Populated"
|
||||||
|
|
||||||
bind va
|
bind va
|
||||||
bind vb
|
bind vb
|
||||||
|
|
||||||
write vb 0 (VS.convert vertices)
|
|
||||||
|
|
||||||
bind ib
|
bind ib
|
||||||
|
|
||||||
|
logIO Debug "Bound buffers"
|
||||||
|
|
||||||
|
write vb 0 vertices
|
||||||
|
|
||||||
|
logIO Debug ("Written " <> fromString (show $ VS.length vertices) <> " vertices")
|
||||||
|
|
||||||
write ib 0 (VS.map fromIntegral indices)
|
write ib 0 (VS.map fromIntegral indices)
|
||||||
|
|
||||||
|
logIO Debug ("Written " <> fromString (show $ VS.length vertices) <> " indices")
|
||||||
|
|
||||||
|
logIO Debug "Wrote buffers"
|
||||||
|
|
||||||
bind (tileMapTexture tileMap)
|
bind (tileMapTexture tileMap)
|
||||||
|
mapM_ (\(StageSet p) -> bindPropTexture p) stageSet
|
||||||
R.draw va ib sh
|
R.draw va ib sh
|
||||||
|
|
||||||
|
logIO Debug "Drawn"
|
||||||
|
|
||||||
testLevelDesc :: LevelDescriptor
|
testLevelDesc :: LevelDescriptor
|
||||||
testLevelDesc = LevelDescriptor
|
testLevelDesc = LevelDescriptor
|
||||||
[ (0, "res/maps/00_test/00_test.bmp")
|
[ (0, "res/maps/00_test/00_test.bmp")
|
||||||
|
@ -198,7 +230,7 @@ populate layers props actors =
|
||||||
, avs V.++ nvs)
|
, avs V.++ nvs)
|
||||||
)
|
)
|
||||||
(V.empty, V.empty)
|
(V.empty, V.empty)
|
||||||
(propsHere)
|
propsHere
|
||||||
(cisRaw, cvs) = V.foldl
|
(cisRaw, cvs) = V.foldl
|
||||||
(\(ais, avs) (Cast c) ->
|
(\(ais, avs) (Cast c) ->
|
||||||
let (nis, nvs) = toVertices c
|
let (nis, nvs) = toVertices c
|
||||||
|
@ -207,7 +239,7 @@ populate layers props actors =
|
||||||
, avs V.++ nvs)
|
, avs V.++ nvs)
|
||||||
)
|
)
|
||||||
(V.empty, V.empty)
|
(V.empty, V.empty)
|
||||||
(actorsHere)
|
actorsHere
|
||||||
(lisRaw, lvs) = toVertices l
|
(lisRaw, lvs) = toVertices l
|
||||||
lis = V.map
|
lis = V.map
|
||||||
(+ if null is then 0 else V.maximum is)
|
(+ if null is then 0 else V.maximum is)
|
||||||
|
|
|
@ -9,4 +9,5 @@ import Types.Texture as T
|
||||||
import Types.Cast as T
|
import Types.Cast as T
|
||||||
import Types.StageSet as T
|
import Types.StageSet as T
|
||||||
import Types.Graphics as T
|
import Types.Graphics as T
|
||||||
|
import Types.Player as T
|
||||||
import Types.Util as T
|
import Types.Util as T
|
||||||
|
|
|
@ -42,7 +42,7 @@ newTexture fp slot = do
|
||||||
eimg <- readImage fp
|
eimg <- readImage fp
|
||||||
|
|
||||||
case eimg of
|
case eimg of
|
||||||
Left err ->
|
Left err -> do
|
||||||
let mesg = ("reading file " <> fp <> " failed: " <> show err)
|
let mesg = ("reading file " <> fp <> " failed: " <> show err)
|
||||||
logIO Error (fromString mesg)
|
logIO Error (fromString mesg)
|
||||||
return $ Left mesg
|
return $ Left mesg
|
||||||
|
|
|
@ -54,22 +54,22 @@ instance Drawable Tile where
|
||||||
(V3 (fromIntegral x * 32) (fromIntegral y * 32) 0)
|
(V3 (fromIntegral x * 32) (fromIntegral y * 32) 0)
|
||||||
(V4 0 0 0 1)
|
(V4 0 0 0 1)
|
||||||
(V2 u1 v1)
|
(V2 u1 v1)
|
||||||
(fromIntegral 0)
|
0
|
||||||
, newVertex
|
, newVertex
|
||||||
(V3 (fromIntegral (x + 1) * 32) (fromIntegral y * 32) 0)
|
(V3 (fromIntegral (x + 1) * 32) (fromIntegral y * 32) 0)
|
||||||
(V4 0 0 0 1)
|
(V4 0 0 0 1)
|
||||||
(V2 u2 v1)
|
(V2 u2 v1)
|
||||||
(fromIntegral 0)
|
0
|
||||||
, newVertex
|
, newVertex
|
||||||
(V3 (fromIntegral (x + 1) * 32) (fromIntegral (y + 1) * 32) 0)
|
(V3 (fromIntegral (x + 1) * 32) (fromIntegral (y + 1) * 32) 0)
|
||||||
(V4 0 0 0 1)
|
(V4 0 0 0 1)
|
||||||
(V2 u2 v2)
|
(V2 u2 v2)
|
||||||
(fromIntegral 0)
|
0
|
||||||
, newVertex
|
, newVertex
|
||||||
(V3 (fromIntegral x * 32) (fromIntegral (y + 1) * 32) 0)
|
(V3 (fromIntegral x * 32) (fromIntegral (y + 1) * 32) 0)
|
||||||
(V4 0 0 0 1)
|
(V4 0 0 0 1)
|
||||||
(V2 u1 v2)
|
(V2 u1 v2)
|
||||||
(fromIntegral 0)
|
0
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
module Types.Player where
|
||||||
|
|
||||||
|
import qualified Graphics.Rendering.OpenGL as GL
|
||||||
|
|
||||||
|
import Linear
|
||||||
|
|
||||||
|
import qualified Data.Vector as V
|
||||||
|
|
||||||
|
-- internal imports
|
||||||
|
|
||||||
|
import Classes.Graphics.Drawable
|
||||||
|
import Classes.Graphics.Bindable
|
||||||
|
import Classes.Prop
|
||||||
|
|
||||||
|
import Types.Graphics.VertexBuffer
|
||||||
|
import Types.Texture
|
||||||
|
|
||||||
|
data Pituicat = Pituicat
|
||||||
|
{ pcPos :: V2 Double
|
||||||
|
, pcVel :: V2 Double
|
||||||
|
, pcAcc :: V2 Double
|
||||||
|
, pcHealth :: Int
|
||||||
|
, pcTexture :: Texture
|
||||||
|
}
|
||||||
|
|
||||||
|
instance Drawable Pituicat where
|
||||||
|
|
||||||
|
toVertices (Pituicat pos@(V2 x y) _ _ _ tex) =
|
||||||
|
( V.fromList [0, 1, 2, 2, 3, 0]
|
||||||
|
, V.fromList
|
||||||
|
[ newVertex
|
||||||
|
(V3 (realToFrac x - 25) (realToFrac y - 25) 0)
|
||||||
|
(V4 0 0 0 1)
|
||||||
|
(V2 0 (1 - 50 / 1024))
|
||||||
|
1
|
||||||
|
, newVertex
|
||||||
|
(V3 (realToFrac x + 25) (realToFrac y - 25) 0)
|
||||||
|
(V4 0 0 0 1)
|
||||||
|
(V2 (50 / 1024) (1 - 50 / 1024))
|
||||||
|
1
|
||||||
|
, newVertex
|
||||||
|
(V3 (realToFrac x + 25) (realToFrac y + 25) 0)
|
||||||
|
(V4 0 0 0 1)
|
||||||
|
(V2 (50 / 1024) 1)
|
||||||
|
1
|
||||||
|
, newVertex
|
||||||
|
(V3 (realToFrac x - 25) (realToFrac y + 25) 0)
|
||||||
|
(V4 0 0 0 1)
|
||||||
|
(V2 (50 / 1024) 1)
|
||||||
|
1
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
instance Prop Pituicat where
|
||||||
|
|
||||||
|
residentLayer _ = 0
|
||||||
|
|
||||||
|
bindPropTexture = bind . pcTexture
|
Loading…
Reference in New Issue