Haha, it's not as easy as one might think. Basicly, you should render all sprites at the end, sorted from back to front and with full z buffer enabled (S3D_Z_BUFFER). And since sprites should always face the camera, you have to mess about a little with that. I've added a mummy, or atleast the rendering of it, at position 33, 33 (x and z).
The rendering of the heightmap that is done earlier doesn't need to read from the z buffer (therefor I use only S3D_Z_BUFFER_WRITE), since the sorting itself works perfectly for that kind of data.
Edit If you're making a horror game, I totally love those Played through Paratopic last weekend (maybe not horror but very ... creepy), completed the original Amnesia games, Layers of Fear, Resident Evil Revelations, Outlast and a bunch of others. But for some reason I just CAN'T play Slenderman, as soon as he appears I go full "NOPE!" and shut down my Nintendo Switch I started playing Alien Isolation som years ago, very scary but too difficult so I gave up ... maybe I should give it another go? I'm rambling, sorry.
The rendering of the heightmap that is done earlier doesn't need to read from the z buffer (therefor I use only S3D_Z_BUFFER_WRITE), since the sorting itself works perfectly for that kind of data.
Code:
'==================================================
' THE MAZE II
' Part 1. Sand Desert
' Part 2. to be
' Part 3. to be
'
' Control :
' SPACE = move forward
' Mouse = see around
'
' Reference :
' - s3d.n7 library, ex6_heightmap.n7 by Marcus
'
' Sand texture https://images.app.goo.gl/QwsHZq7hZVdyNXB76
' Mummy1 https://images.app.goo.gl/uiosCKdMHraZPfoC7
' Title https://images.app.goo.gl/AGLmRC8g9vQDg21Q6
'==================================================
'----------------
' INITIALIZATION
'----------------
include "data_maze2/heightmap_library.n7"
include "s3d.n7"; S3D_SetView(primary, rad(90), 0.1, 5)
set window "Maze 2 - Part 1.Sand Desert",400,200,false,3
set mouse off
set redraw off
'color definition
gray = [128,128,128]
black = [0,0,0]
white = [255,255,255]
red = [255,0,0]
green = [0,255,0]
darkgreen = [0,128,0,120]
' Heightmap and Ground
heightmapImg = loadimage("data_maze2/heightmap.png");hm = CreateHeightmap(heightmapImg, 8)
groundImg = loadimage("data_maze2/ground.png")
' Camera
camX = 32 ; camY = 0 ; camZ = 32 'position
camYaw = 0 ; camPitch = 0 'rotation
camBobAngle = 0 ; camBobEffect = 0 'when the user moves
' Mummy
mummy = []
mummy[1] = []
mummy[1].img = loadimage("data_maze2/mummy1.png")
' misc initial value
dt = 0.003
map = [] 'little map
map.x = width(primary)-100
map.z = height(primary)-80
map.w = width(heightmapImg)
map.h = height(heightmapImg)
map.r = map.w/2 'radius
map.cx = map.x+map.w/2 'center
map.cz = map.z+map.h/2 'center
map.a = 0 'angle
pos = [] 'player's position
pos.x = 0
pos.y = 0
pos.z = 0
'-----------
' GAME LOOP
'-----------
while not keydown(KEY_ESCAPE, true)
'----------
' control
'----------
' Rotation
mdx = mouserelx(); mdy = mouserely()
camYaw = (camYaw + mdx*45*dt)%360 ; camPitch = min(max(camPitch - mdy*45*dt, -60), 60)
set mouse width(primary)/2, height(primary)/2
' Movement
dx = 0; dz = 0
if keydown(KEY_SPACE)
dx = dx + sin(rad(camYaw))
dz = dz + cos(rad(camYaw))
endif
if dx or dz
camBobAngle = camBobAngle + 500*dt 'when the user moves
k = dt/sqr(dx*dx + dz*dz)
camX = camX + k*dx 'position X
camZ = camZ + k*dz 'position Z
camBobEffect = min(camBobEffect + 4*dt, 1) 'when the user moves
endif
camY = hm.GetY(camX, camZ) - 0.5 'position Y
pos.x = str(camX,0,1)
pos.y = str(camY,0,1)
pos.z = str(camZ,0,1)
map.a = 90-camYaw
'------------
' rendering
'------------
' Fill screen with the fog color.
set color gray; cls
' Rendering Process
S3D_Clear()
S3D_SetSorting(S3D_BACK_TO_FRONT)
S3D_SetDepthBuffer(S3D_Z_BUFFER_WRITE)
S3D_RotateX(rad(-camPitch))
S3D_RotateY(rad(-camYaw))
S3D_Translate(-camX, -camY + 0.04*camBobEffect*sin(rad(camBobAngle)), -camZ)
S3D_Texture(groundImg)
S3D_Mesh(hm.mesh, 0)
S3D_Render()
' draw mummy (and all other sprites)
mummyx = 33
mummyz = 33
mummyy = hm.GetY(mummyx, mummyz)
' Draw sprites back to front.
S3D_SetSorting(S3D_BACK_TO_FRONT)
S3D_SetDepthBuffer(S3D_Z_BUFFER) ' If there was no fog, we could use S3D_Z_READ instead
' For every sprite do a push and pop.
S3D_Push()
' Move to position.
S3D_Translate(mummyx, mummyy - 1, mummyz)
' Rotate y with camYaw to make the sprite always face the player.
S3D_RotateY(rad(camYaw))
' Set texture.
S3D_Texture(mummy[1].img)
' Creating a mesh for this would speed things up, really.
S3D_Begin(S3D_QUADS)
S3D_Vertex(-0.5, 0, 0, 0, 0)
S3D_Vertex(0.5, 0, 0, 1, 0)
S3D_Vertex(0.5, 1, 0, 1, 1)
S3D_Vertex(-0.5, 1, 0, 0, 1)
S3D_End()
S3D_Pop()
' Render sprites.
S3D_Render()
S3D_RenderFog(gray[0],gray[1],gray[2],false)
' Just simple draw image
'set color white
'draw image mummy[1].img, 20,20
'------------
' navigation
'------------
set color black
set caret 0,0; wln "Angle "+camYaw 'camYaw = 0 south, 90 east, 180 north, 270 west
wln "Position "+pos.x+","+pos.y+","+pos.z
set color darkgreen ; draw ellipse map.cx,map.cz,map.r,map.r,true
set color green
draw ellipse map.cx,map.cz,map.r,map.r
draw line map.cx,map.cz,map.cx+map.r*cos(rad(map.a)),map.cz+map.r*sin(rad(map.a))
set color red ; draw ellipse (map.x+int(pos.x)),(map.z+int(pos.z)),2,2,true
set color white ; draw ellipse (map.x+int(pos.x)),(map.z+int(pos.z)),2,2
set caret map.cx-18, map.z-13; wln "North"
set caret map.cx-18, map.z+map.h; wln "South"
set caret map.x-35, map.cz-5; wln "West"
set caret map.x+map.w+5, map.cz-5; wln "East"
redraw
wait 1
wend
Edit If you're making a horror game, I totally love those Played through Paratopic last weekend (maybe not horror but very ... creepy), completed the original Amnesia games, Layers of Fear, Resident Evil Revelations, Outlast and a bunch of others. But for some reason I just CAN'T play Slenderman, as soon as he appears I go full "NOPE!" and shut down my Nintendo Switch I started playing Alien Isolation som years ago, very scary but too difficult so I gave up ... maybe I should give it another go? I'm rambling, sorry.