-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path16-ApplyImpulse.sb
More file actions
89 lines (72 loc) · 2.45 KB
/
16-ApplyImpulse.sb
File metadata and controls
89 lines (72 loc) · 2.45 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
;Babylon.sbi - Apply Mesh Impulse
EnableExplicit
IncludeFile "babylon/babylon.sbi"
UseModule BJS
Enumeration
#Font
#mf
#mfRender
EndEnumeration
Global Scene, Camera, Ground, GroundTex, GroundMat, Dim Boxs(9), BoxTex, BoxMat
Declare LoadGame()
Declare RenderGame()
Declare Resize()
LoadFont(#Font, "Arial", 22)
OpenWindow(#mf, 0, 0, 0, 0, "", #PB_Window_Background)
CanvasGadget(#mfRender, 0, 0, WindowWidth(#mf), WindowHeight(#mf), #PB_Canvas_Transparent)
BindEvent(#PB_Event_SizeWindow, @Resize())
InitEngine(@LoadGame(), #mfRender)
InitKey()
Procedure LoadGame()
Protected n, Help
Scene = CreateScene()
If Scene
ClearScene(RGB(178, 34, 34))
Camera = CreateCamera("camera", 0, 10, 30, #BJS_ArcRotate)
CreateLight("light", 0, 20, 0, 0.8)
;Create static ground (Mass = 0)
Ground = CreateGround("ground", 100, 100)
CreateMeshBody(Ground, #BJS_BoxBody, 0, 0.5, 0.5)
GroundTex = LoadTexture("Data/textures/Beton1.png")
GroundMat = CreateMaterial("ground")
SetMaterialTexture(GroundMat, #BJS_Diffuse, GroundTex)
ScaleMaterial(GroundMat, 5, 5)
SetMeshMaterial(Ground, GroundMat)
;Create 10 Box (Physic)
BoxTex = LoadTexture("data/textures/crate.png")
BoxMat = CreateMaterial("crate")
SetMaterialTexture(BoxMat, #BJS_Diffuse, BoxTex)
For n = 0 To 9
Boxs(n) = CreateBox("box", 3, 3, 3)
MoveMesh(Boxs(n), (n * 4) - 18, 1.4, -30)
SetMeshMaterial(Boxs(n), BoxMat)
CreateMeshBody(Boxs(n), #BJS_BoxBody, 1, 1, 1)
Next
Help = TextGadget(-1, 20, WindowHeight(#mf) - 50, 400, 22, "Press the space key to send a pulse.")
SetGadgetColor(Help, #PB_Gadget_FrontColor, RGB(255, 255, 255))
SetGadgetFont(Help, FontID(#Font))
RenderLoop(@RenderGame())
EndIf
EndProcedure
Procedure RenderGame()
Protected n
If KeyReleased(#PB_Key_Space)
For n = 0 To 9
ApplyMeshImpulse(Boxs(n), 0, Random(20, 10), Random(5, 2))
Next
EndIf
RenderWorld()
EndProcedure
Procedure Resize()
ResizeGadget(#mfRender, #PB_Ignore, #PB_Ignore, WindowWidth(#mf), WindowHeight(#mf))
EndProcedure
; IDE Options = SpiderBasic 2.20 (Windows - x86)
; Folding = -
; WebAppName = Apply Impulse
; HtmlFilename = applyimpulse.html
; JavaScriptFilename = applyimpulse.js
; JavaScriptPath = sb
; iOSAppOrientation = 0
; AndroidAppOrientation = 0
; EnableXP
; CompileSourceDirectory