-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path10-Terrain.sb
More file actions
100 lines (79 loc) · 2.73 KB
/
10-Terrain.sb
File metadata and controls
100 lines (79 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
;Babylon.sbi - Create Terrain
EnableExplicit
IncludeFile "babylon/babylon.sbi"
Global Camera, Light, Sky, Ground, GroundTex, GroundMat, Water, Box, Mesh, Texture, Material
Global Box0, Box1, Box2
Global ShadowGenerator
Declare LoadGame()
Declare RenderGame()
UseModule BJS
InitEngine(@LoadGame())
Procedure LoadGame()
If CreateScene()
InitKey()
;Camera & Light
Camera = CreateCamera("camera", 0, 65, 100, #BJS_Universal)
CameraBodySize(Camera, 1, 15, 1)
CameraLookAt(Camera, 0, 30, 0)
;Redefine the camera keys
CameraMapKey(Camera, #PB_Key_Left, #PB_Key_A)
CameraMapKey(Camera, #PB_Key_Right, #PB_Key_Z)
Light = CreateLight("Light", 0, 200, -100, 0.8, #BJS_Point)
;SkyBox
Sky = SkyBox("Clouds", "data/textures/sky/cloud", 2000)
;Terrain
Ground = CreateTerrain("island", "data/textures/heightMap.png", 1000, 1000, 210, 0, 70)
GroundTex = LoadTexture("Data/textures/Ground.jpg")
GroundMat = CreateMaterial("sand")
SetMaterialTexture(GroundMat, #BJS_Diffuse, GroundTex)
ScaleMaterial(GroundMat, 16, 16)
SetMeshMaterial(Ground, GroundMat)
SetMaterialColor(GroundMat, #BJS_Specular, RGB(80, 80, 80))
MoveMesh(Ground, 0, -12, 0)
;Box
Box0 = CreateBox("box", 10, 10, 10)
Texture = LoadTexture("data/textures/crate.png")
Material = CreateMaterial("box")
SetMaterialTexture(Material, #BJS_Diffuse, Texture)
SetMaterialColor(Material, #BJS_Emissive, RGB(80, 80, 80))
SetMeshMaterial(Box0, Material)
MoveMesh(Box0, -4, 22, -70)
Box1 = CloneMesh(Box0)
MoveMesh(Box1, 7, 22, -70)
Box2 = CloneMesh(Box0)
MoveMesh(Box2, 0, 32, -70)
RotateMesh(Box2, 0, 45, 0)
;Water
Water = CreateWater("water", "data/textures/waterbump.png", 2000, 2000, 128)
WaterRenderList(Water, Ground)
WaterRenderList(Water, Sky)
;Shadow
ShadowGenerator = InitShadow(Light)
ShadowEmitter(ShadowGenerator, Box0)
ShadowEmitter(ShadowGenerator, Box1)
ShadowEmitter(ShadowGenerator, Box2)
RenderShadows(Ground)
RenderLoop(@RenderGame())
EndIf
EndProcedure
Procedure RenderGame()
If KeyPushed(#PB_Key_Left)
RotateCamera(Camera, 0, -0.05, 0, #PB_Relative)
EndIf
If KeyPushed(#PB_Key_Right)
RotateCamera(Camera, 0, 0.05, 0, #PB_Relative)
EndIf
RenderWorld()
EndProcedure
; IDE Options = SpiderBasic 2.20 (Windows - x86)
; CursorPosition = 69
; FirstLine = 25
; Folding = -
; WebAppName = Terrain
; HtmlFilename = terrain.html
; JavaScriptFilename = terrain.js
; JavaScriptPath = sb
; iOSAppOrientation = 0
; AndroidAppOrientation = 0
; EnableXP
; CompileSourceDirectory