Code: Select all
;Simulate a rusty plane in transit
;By DK_PETER
InitEngine3D()
InitSprite()
InitKeyboard()
UseJPEGImageDecoder()
UsePNGImageDecoder()
Structure _par
id.i
ma.i
tx.i
EndStructure
Structure _mesh
id.i
ms.i
ma.i
tx.i
EndStructure
Structure _plane
body._mesh
wing._mesh[2]
tail._mesh
engine._mesh[2]
nose._mesh
EndStructure
Global Dim Clouds._mesh(5), Dim Engines._par(2)
Global CloudNode.i, PlaneNode.i, Ground._mesh, pl._plane, rust.i
OpenWindow(0, 0, 0, 1024, 768, "plane", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
OpenWindowedScreen(WindowID(0), 0, 0, 1024, 768, #False, 0, 0)
Add3DArchive("texture", #PB_3DArchive_FileSystem)
rust = LoadImage(#PB_Any, "texture\rust.jpg")
CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0, 0, 40, 76)
CameraDirection(0, 0, -0.4, -1)
CreateLight(0, $A5FFF7, 500, 2000, 400, #PB_Light_Directional)
CreateCamera(1, 75, 75, 25, 25)
CameraDirection(1, -1, 0, 0)
MoveCamera(1, 200, 26, 7, 0)
For x = 0 To 4
With clouds(x)
\tx = LoadTexture(#PB_Any, "c.jpg")
\ma = CreateMaterial(#PB_Any, TextureID(\tx))
MaterialBlendingMode(\ma, #PB_Material_Color)
AddMaterialLayer(\ma, TextureID(\tx), #PB_Material_Color)
AddMaterialLayer(\ma, TextureID(\tx), #PB_Material_Add)
ScrollMaterial(\ma, -0.2, 0, #PB_Material_Animated, 0)
ScrollMaterial(\ma, -0.4, 0, #PB_Material_Animated, 1)
ScrollMaterial(\ma, -0.2, 0, #PB_Material_Animated, 2)
\ms = CreatePlane(#PB_Any, 100, 100, 1, 1, 10, 10)
\id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma), 0, -200 + (x * 200) , 0)
ScaleEntity(\id, 100, 100, 100)
EndWith
Next x
With Ground
\tx = LoadTexture(#PB_Any, "a.jpg")
\ma = CreateMaterial(#PB_Any, TextureID(\tx))
ScaleMaterial(\ma, 0.5, 0.5, 0)
ScrollMaterial(\ma, -1.015, 0, #PB_Material_Animated)
\ms = CreatePlane(#PB_Any, 100, 100, 1, 1, 30, 30)
\id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma), 0, -800, 0)
ScaleEntity(\id, 300, 1, 300)
EndWith
With Engines(0)
\tx = CreateTexture(#PB_Any, 10, 10)
StartDrawing(TextureOutput(\tx))
DrawingMode(#PB_2DDrawing_Gradient)
BackColor($00F1E3) : FrontColor($0030FD)
CircularGradient(5, 5, 3)
Circle(5, 5, 3)
StopDrawing()
\ma = CreateMaterial(#PB_Any, TextureID(\tx))
MaterialBlendingMode(\ma, #PB_Material_Add)
\id = CreateParticleEmitter(#PB_Any, 0.5, 0.5, 0.5, #PB_Particle_Box, 3, 1.5 , -10)
ParticleMaterial(\id, MaterialID(\ma))
ParticleEmissionRate(\id, 100)
ParticleTimeToLive(\id, 0.1, 0.1)
ParticleVelocity(\id, 0.2, 0.4)
ParticleEmitterDirection(\id, 1, 0 , 0)
ParticleSize(\id, 4 , 1 )
EndWith
With Engines(1)
\tx = CreateTexture(#PB_Any, 10, 10)
StartDrawing(TextureOutput(\tx))
DrawingMode(#PB_2DDrawing_Gradient)
BackColor($00F1E3) : FrontColor($0030FD)
CircularGradient(5, 5, 3)
Circle(5, 5, 3)
StopDrawing()
\ma = CreateMaterial(#PB_Any, TextureID(\tx))
MaterialBlendingMode(\ma, #PB_Material_Add)
\id = CreateParticleEmitter(#PB_Any, 0.5, 0.5, 0.5, #PB_Particle_Box, 3, 1.5 , 10)
ParticleMaterial(\id, MaterialID(\ma))
ParticleEmissionRate(\id, 100)
ParticleTimeToLive(\id, 0.1, 0.1)
ParticleVelocity(\id, 0.2, 0.4)
ParticleEmitterDirection(\id, 1, 0 , 0)
ParticleSize(\id, 4 , 1 )
EndWith
With pl\body
\tx = LoadTexture(#PB_Any, "rust.jpg")
\ma = CreateMaterial(#PB_Any, TextureID(\tx))
\ms = CreateSphere(#PB_Any, 50)
\id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma), 0, 3, 0)
ScaleEntity(\id, 0.4, 0.05, 0.07)
EndWith
With pl\nose
\tx = CreateTexture(#PB_Any, 40, 40)
StartDrawing(TextureOutput(\tx))
Box(0, 0, 40, 10, $E68B00)
DrawImage(ImageID(rust), 0, 10)
StopDrawing()
\ma = CreateMaterial(#PB_Any, TextureID(\tx))
\ms = CreateSphere(#PB_Any, 50, 10, 10)
\id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma), -15, 3, 0)
ScaleEntity(\id, 0.1, 0.04, 0.04)
EndWith
With pl\wing[0]
\tx = LoadTexture(#PB_Any, "rust.jpg")
\ma = CreateMaterial(#PB_Any, TextureID(\tx))
\ms = CreateCube(#PB_Any, 50)
\id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma), -1, 2.3, -10)
ScaleEntity(\id, 0.5, 0.01, 0.07)
RotateEntity(\id, 0, 55, 0)
EndWith
With pl\wing[1]
\tx = LoadTexture(#PB_Any, "rust.jpg")
\ma = CreateMaterial(#PB_Any, TextureID(\tx))
\ms = CreateCube(#PB_Any, 50)
\id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma), -1, 2.3, 10)
ScaleEntity(\id, 0.5, 0.01, 0.07)
RotateEntity(\id, 0, -55, 0)
EndWith
With pl\engine[0]
\tx = LoadTexture(#PB_Any, "rust.jpg")
\ma = CreateMaterial(#PB_Any, TextureID(\tx))
\ms = CreateSphere(#PB_Any, 30, 10, 10)
\id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma), -0.7, 1.5, 10)
ScaleEntity(\id, 0.09, 0.02, 0.03)
EndWith
With pl\engine[1]
\tx = LoadTexture(#PB_Any, "rust.jpg")
\ma = CreateMaterial(#PB_Any, TextureID(\tx))
\ms = CreateSphere(#PB_Any, 30, 10, 10)
\id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma), -0.7, 1.5, -10)
ScaleEntity(\id, 0.09, 0.02, 0.03)
EndWith
With pl\tail
\tx = LoadTexture(#PB_Any, "rust.jpg")
\ma = CreateMaterial(#PB_Any, TextureID(\tx))
\ms = CreateCylinder(#PB_Any, 3, 5, 2, 1, 6)
\id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma), 16, 7, 0)
ScaleEntity(\id, 1, 1.7, 0.2)
EndWith
;Assemble the plane
PlaneNode = CreateNode(#PB_Any, 0, 0, 0)
AttachNodeObject(PlaneNode, EntityID(pl\body\id))
AttachNodeObject(PlaneNode, EntityID(pl\nose\id))
AttachNodeObject(PlaneNode, EntityID(pl\wing[0]\id))
AttachNodeObject(PlaneNode, EntityID(pl\wing[1]\id))
AttachNodeObject(PlaneNode, EntityID(pl\engine[0]\id))
AttachNodeObject(PlaneNode, EntityID(pl\engine[1]\id))
AttachNodeObject(PlaneNode, EntityID(pl\tail\id))
AttachNodeObject(PlaneNode, ParticleEmitterID(Engines(0)\id))
AttachNodeObject(PlaneNode, ParticleEmitterID(Engines(1)\id))
MoveNode(PlaneNode, 0, 2,0)
Repeat
Repeat
ev = WindowEvent()
If ev = #PB_Event_CloseWindow : Quit = 1 : EndIf
Until ev = 0
RenderWorld()
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Down) And NodeRoll(PlaneNode) > -20
RotateNode(PlaneNode,0, 0, -0.4, #PB_Relative)
EndIf
If KeyboardPushed(#PB_Key_Up) And NodeRoll(PlaneNode) < 20
RotateNode(PlaneNode,0, 0, 0.4, #PB_Relative)
EndIf
If KeyboardPushed(#PB_Key_Left) And NodePitch(PlaneNode) > -56
RotateNode(PlaneNode,-0.4, 0, 0, #PB_Relative)
EndIf
If KeyboardPushed(#PB_Key_Right) And NodePitch(PlaneNode) < 56
RotateNode(PlaneNode,0.4, 0, 0, #PB_Relative)
EndIf
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1



