The good thing about this system is that it allows you to make very large maps that are generated automatically. The actual measurements of the map are those of the image we use as a relief map.
If anyone can help to add collisions to the map I would be very grateful.
Code: Select all
; # minimy old school landscape - 2024
UsePNGImageDecoder()
UseJPEGImageDecoder()
Global fontLit= LoadFont(#PB_Any,"Arial",9)
Global fontMed= LoadFont(#PB_Any,"Arial",32)
Global.l niebla_color= $aaaaaa
Global.d niebla_intensidad= 0.75
Global.l niebla_cerca= 50
Global.l niebla_lejos= 5000
Procedure dummyIni()
Protected cubo_mesh= CreateCube(#PB_Any,1)
Protected cubo_mate= CreateMaterial(#PB_Any, #Null,$0000ff)
Global cubo_enti= CreateEntity(#PB_Any, MeshID(cubo_mesh), MaterialID(cubo_mate));,4,1,4)
HideEntity(cubo_enti,1)
EndProcedure
Procedure dummy(x.f,y.f,z.f,color.l= $0000ff, sx.f=1,sy.f=1,sz.f=1)
Protected m= CreateMaterial(#PB_Any,#Null,color)
Protected a= CopyEntity(cubo_enti,#PB_Any)
MoveEntity( a,x,y,z,#PB_Absolute)
ScaleEntity(a,sx,sy,sz,#PB_Absolute)
SetEntityMaterial(a,MaterialID(m))
ProcedureReturn a
EndProcedure
Procedure spr2DText(spr, txt.s, ink.l=$ff00ff00)
Protected n,y=2,tl= CountString(txt,#CR$)
Protected tx.s
StartDrawing(SpriteOutput(spr))
DrawingMode(#PB_2DDrawing_AlphaChannel)
Box(0,0,OutputWidth(),OutputHeight(),$00000000)
DrawingMode(#PB_2DDrawing_AlphaBlend | #PB_2DDrawing_Transparent)
Box(0,0,OutputWidth(),OutputHeight(),$aa000000)
DrawingFont(FontID(fontLit))
For n=1 To tl+1
tx= StringField(txt,n,#CR$)
DrawText(5,y,tx,ink)
y+16
Next n
DrawingMode(#PB_2DDrawing_AlphaBlend | #PB_2DDrawing_Outlined)
Box(0,0,OutputWidth(),OutputHeight(),ink)
StopDrawing()
EndProcedure
;{ landScape
Structure land_struc
file.s
img.i
;mapa físico
mate.i
mesh.i
enti.i
tileX.i
tileZ.i
tilesX.i
tilesZ.i
planX.i
planZ.i
;mapa virtual
sizeX.i
sizeZ.i
playX.i
playZ.i
oldPlayX.i
oldPlayZ.i
EndStructure
Global land.land_struc
Global Dim landData.MeshVertex(0)
Global Dim landMapa.d(1,1)
Procedure landImg(size=512)
Protected size2= size*2, x,y,b,r1,r2
Protected.s t="minimy"
Protected i=CreateImage(#PB_Any,size2,size2,24,0)
StartDrawing(ImageOutput(i))
DrawingMode(#PB_2DDrawing_AlphaBlend | #PB_2DDrawing_Gradient)
BackColor($ffffffff)
FrontColor($00000000)
For p=0 To 200
x= Random(OutputWidth())
y= Random(OutputHeight())
n= OutputWidth()/8
r1= Random(n,n*0.5)
r2= Random(n,n*0.5)
EllipticalGradient(x,y, r1, r2)
Ellipse(x, y, r1,r2)
Next p
DrawingMode(#PB_2DDrawing_Default | #PB_2DDrawing_Transparent)
DrawingFont(FontID(fontMed))
DrawText((OutputWidth()-TextWidth(t))/2,(OutputHeight()-TextHeight(t))/2,t,$ffffff)
StopDrawing()
ResizeImage(i,size,size)
; showImage(i)
ProcedureReturn i
EndProcedure
Procedure landIni(planX=50,planZ=50, tilesX=50,tilesZ=50, file.s="test.png", altura=50, mate=0)
Protected.l c, x,z
;mapa virtual
land\file= file
If LCase(GetExtensionPart(file))="png"
land\img= LoadImage(#PB_Any,file)
Else
land\img= Val(file)
EndIf
land\sizeX= ImageWidth(land\img)
land\sizeZ= ImageHeight(land\img)
FreeArray(landMapa())
Dim landMapa(land\sizeX, land\sizeZ)
StartDrawing(ImageOutput(land\img))
For z=0 To land\sizeZ-1
For x=0 To land\sizeX-1
c=Point(x,z)
landMapa(x,z)= (altura * Red(c)) / 255
Next
Next
StopDrawing()
;mapa físico
land\planX= planX
land\planZ= planZ
land\tilesX= tilesX
land\tilesZ= tilesZ
land\tileX= planX / tilesX
land\tileZ= planZ / tilesZ
land\mate= mate
land\mesh= CreatePlane(#PB_Any,land\planX, land\planZ, land\tilesX, land\tilesZ, 1,1)
land\enti= CreateEntity(#PB_Any,MeshID(land\mesh),MaterialID(land\mate), 0, 0, 0)
GetMeshData(land\mesh,0, landData(), #PB_Mesh_Vertex | #PB_Mesh_Normal , 0, MeshVertexCount(land\mesh)-1)
EndProcedure
Procedure landSet(player)
x2= land\playX - (land\tilesX / 2)
x1= land\playX + (land\tilesX / 2)
z1= land\playZ - (land\tilesZ / 2)
z2= land\playZ + (land\tilesZ / 2)
If z1>-1 And z2<land\sizeZ And x2>-1 And x1<land\sizeX-1
c=0
For z = z1 To z2
For x = x1 To x2 Step -1
y3=z : If y3<0: y3= (land\sizeZ-1)+z: EndIf
x3=x : If x3<0: x3= (land\sizeX-1)+x: EndIf
height.f= landMapa(x3,y3)
landData(c)\y = height
c+1
Next
Next
MoveEntity(land\enti, land\playX * land\tileX, 0, land\playZ * land\tileZ, #PB_Absolute)
SetMeshData(land\mesh,0, landData(), #PB_Mesh_Vertex | #PB_Mesh_Normal, 0, MeshVertexCount(land\mesh)-1)
NormalizeMesh(land\mesh)
UpdateMeshBoundingBox(land\mesh)
EndIf
EndProcedure
;}
InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()
Add3DArchive(".", #PB_3DArchive_FileSystem)
Parse3DScripts()
ExamineDesktops()
DesktopW = DesktopWidth(0)
DesktopH = DesktopHeight(0)
winMain= OpenWindow(#PB_Any, 0, 0, DesktopW, DesktopH, "landScap (old school)",#PB_Window_Maximize|#PB_Window_BorderLess)
DesktopW = WindowWidth(winMain)
DesktopH = WindowHeight(winMain)
OpenWindowedScreen(WindowID(winMain), 0, 0, DesktopW, DesktopH, 0, 0, 0, #PB_Screen_NoSynchronization)
AntialiasingMode(#PB_AntialiasingMode_None)
WorldShadows(#PB_Shadow_Additive)
camara= 0
cam1= 1
CreateCamera(camara, 0, 0, 100, 100)
MoveCamera(camara, 500, 320, 400, #PB_Absolute)
CameraLookAt(camara,0,0,0)
CameraBackColor(camara, niebla_color)
CreateCamera(cam1, 1, 1, 30, 30)
MoveCamera(cam1, 1100, 720, 1100, #PB_Absolute)
CameraBackColor(cam1, $999999)
CreateLight(0, RGB(255, 255, 255), 1000, 500, 0)
suelo_tx3D= CreateTexture(#PB_Any,128,128)
StartDrawing(TextureOutput(suelo_tx3D))
Box(0,0,OutputWidth(),OutputHeight(),$0)
Box(2,2,OutputWidth()-4,OutputHeight()-4,$ff00ff00)
StopDrawing()
tiles= 51
suelo_mate= CreateMaterial(#PB_Any,TextureID(suelo_tx3D))
m1= CopyMaterial(suelo_mate,#PB_Any)
ScaleMaterial(suelo_mate,1/tiles,1/tiles)
MaterialCullingMode(suelo_mate, #PB_Material_NoCulling)
i= landImg()
landIni(500,500,50,50,Str(i),55,suelo_mate)
; landIni(1500,1500,50,50,"test.png",50,suelo_mate)
dummyIni()
player= dummy( (land\sizeX* land\tileX)/2, 60, (land\sizeZ* land\tileZ)/2 ,$0000ff, 5,5,5)
landSet(player)
sprInfo= CreateSprite(#PB_Any,100,200,#PB_Sprite_AlphaBlending)
SetFrameRate(50)
camaraSpeed= 1
Repeat
Repeat
Until WindowEvent()=0
ExamineKeyboard()
ExamineMouse()
;{ player
If KeyboardPushed(#PB_Key_LeftShift)
spdPlayer= 10
Else
spdPlayer= 1
EndIf
If KeyboardPushed(#PB_Key_Up)
MoveEntity(player,0,0,spdPlayer,#PB_Local)
ElseIf KeyboardPushed(#PB_Key_Down)
MoveEntity(player,0,0,-spdPlayer,#PB_Local)
EndIf
If KeyboardPushed(#PB_Key_Left)
RotateEntity(player,0,1,0,#PB_Relative)
ElseIf KeyboardPushed(#PB_Key_Right)
RotateEntity(player,0,-1,0,#PB_Relative)
EndIf
MoveCamera(cam1,EntityX(player),EntityY(player),EntityZ(player),#PB_Absolute)
CameraDirection(cam1, EntityDirectionX(player)*-1,EntityDirectionY(player),EntityDirectionZ(player)*-1)
;}
land\playX= Round(EntityX(player) / land\tileX, #PB_Round_Down)
land\playZ= Round(EntityZ(player) / land\tileZ, #PB_Round_Down)
If land\oldPlayX<>land\playX Or land\oldPlayZ<>land\playZ
landSet(player)
land\oldPlayX= land\playX
land\oldPlayZ= land\playZ
EndIf
CameraFollow(camara,EntityID(land\enti), 30, 300,500,0.1,0.1)
CameraLookAt(camara, EntityX(player),0,EntityZ(player))
RenderWorld()
txt.s= "minimy 2024"+ #CR$+
"landscape" +#CR$+
"old school" +#CR$+#CR$+
"FPS: "+Str(Engine3DStatus(#PB_Engine3D_CurrentFPS)) +#CR$+
Str(ScreenWidth())+" x "+Str(ScreenHeight()) +#CR$+
; "X: "+StrF(CameraX(camara),2)+#CR$+"Y: "+StrF(CameraY(camara),2)+#CR$+"Z: "+StrF(CameraZ(camara),2); +#CR$+
"X: "+StrF(land\playX) +#CR$+
"Z: "+StrF(land\playZ) +#CR$+
"▲►▼◄ Move " +#CR$+
"LShift HiSpeed "; +#CR$+
spr2DText(sprInfo,txt, $ff00ffff)
DisplayTransparentSprite(sprInfo,ScreenWidth()-110,10)
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1