I would have made it with pure code..I just couldn't get it quite right...
So these two images must be saved in the texture folder.
save as: lightning.jpg
http://postimg.org/image/r9j2r7mcl/
And
save as: flare.jpg
http://postimg.org/image/6b1xjlogf/
Have fun...
Code:
Code: Select all
;-------------------------------------------
; Yet another mish mash
; BY DK_PETER
; Room with lights on...
;-------------------------------------------
UseJPEGImageDecoder()
UsePNGImageDecoder()
If InitEngine3D() = 0
MessageRequester("Unable to start 3D engine", "Examine log for clues")
End
EndIf
If InitSprite() = 0
MessageRequester("Unable to open a screen??", "Something is wrong...")
End
EndIf
InitKeyboard()
Structure Vector3
x.f
y.f
z.f
EndStructure
Structure _object
id.i
ma.i
ma2.i
ms.i
tx.i[4]
EndStructure
Structure _Room
floor._object
walls._object[3]
ceil._object
beamsRight._object[10]
beamsLeft._object[10]
vBeamsLeft._object[5]
vBeamsRight._object[5]
ball._object
tube._object[3]
smallball._object
EndStructure
Structure _pars
id.i
ma.i
tx.i
EndStructure
Declare Normalize(*V.Vector3)
Declare.i CreateTube(meshID.i, outerRadius.f, innerRadius.f, height.f, numSegBase.i=16, numSegHeight.i=1)
Declare.i MakeRoom()
Global twink._pars, r._Room, el.i, lg.i, sp.f = 0.01, ScaleStart.f = 1.0, NewMat.i = #False
OpenWindow(0, 0, 0, 1024, 768, "Star trek horizon example - (DK_PETER) - Escape = Quit", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
OpenWindowedScreen(WindowID(0), 0, 0, 1024, 768)
Add3DArchive("texture", #PB_3DArchive_FileSystem)
WorldShadows(#PB_Shadow_TextureAdditive)
CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0, 0, 0.4, 6)
lg1 = CreateLight(#PB_Any, $F6FFFF, 0.5, 1, -2,#PB_Light_Spot)
LightDirection(lg1, -0.2, 0.1, 1)
MakeRoom()
Repeat
Repeat
ev = WindowEvent()
Until ev = 0
RotateEntity(r\ball\id, 0, -1.5, 0,#PB_Relative)
If sp < 5 : sp + 0.01 : EndIf
If sp >= 5 And ScaleStart < 60
ScaleStart + 1
ScaleEntity(r\smallball\id, ScaleStart, ScaleStart, ScaleStart, #PB_Absolute)
If ScaleStart >= 50 And NewMat = #False
SetEntityMaterial(r\ball\id, MaterialID(r\ball\ma2))
NewMat = #True
HideParticleEmitter(twink\id, #False)
EndIf
EndIf
RotateEntity(r\tube[0]\id, sp, 0, 0, #PB_Relative)
RotateEntity(r\tube[1]\id, 0, sp, sp, #PB_Relative)
RotateEntity(r\tube[2]\id, 0, 0, sp, #PB_Relative)
RenderWorld()
ExamineKeyboard()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
Procedure.i MakeRoom()
Protected x.i, y.i, c.i, ra.f
;Floor
With r\floor
\tx[0] = CreateTexture(#PB_Any, 1024, 1024)
StartDrawing(TextureOutput(\tx[0]))
DrawingMode(#PB_2DDrawing_AlphaBlend)
Box(0, 0, 1024, 1024, $FF7D7B7C)
DrawingMode(#PB_2DDrawing_Outlined)
For y = 0 To 1024 Step 48
For x = 0 To 1024 Step 48
color = Random(50,0)
Box(x, y, 48, 48, RGBA(color,color,color,255))
Next x
Next y
DrawingMode(#PB_2DDrawing_AlphaBlend|#PB_2DDrawing_Gradient)
FrontColor($33000000)
BackColor($FF000000)
CircularGradient(512, 768, 80)
Circle(512, 768, 80)
StopDrawing()
\ma = CreateMaterial(#PB_Any, TextureID(\tx[0]))
MaterialFilteringMode(\ma, #PB_Material_Anisotropic, 8)
SetMaterialAttribute(\ma, #PB_Material_DepthWrite, #True)
\ms = CreatePlane(#PB_Any, 5, 15, 1, 1, 1, 1)
\id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma), 0, 0, 0)
EndWith
;Ceil
With r\ceil
\tx[0] = CreateTexture(#PB_Any, 1024, 1024)
StartDrawing(TextureOutput(\tx[0]))
DrawingMode(#PB_2DDrawing_AlphaBlend)
Box(0, 0, 1024, 1024, $FF7D7B7C)
DrawingMode(#PB_2DDrawing_Outlined)
For y = 0 To 1024 Step 24
For x = 0 To 1024 Step 24
color = Random(50,0)
Box(x, y, 48, 48, RGBA(color,color,color,255))
Next x
Next y
DrawingMode(#PB_2DDrawing_AlphaBlend)
Circle(512, 768, 120, $FF000000)
StopDrawing()
\ma = CreateMaterial(#PB_Any, TextureID(\tx[0]))
MaterialFilteringMode(\ma, #PB_Material_Anisotropic, 8)
MaterialCullingMode(\ma, #PB_Material_NoCulling)
SetMaterialAttribute(\ma, #PB_Material_DepthWrite, #True)
\ms = CreatePlane(#PB_Any, 5, 15, 1, 1, 1, 1)
\id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma), 0, 2.2, 0)
EndWith
With r\walls[0]
\tx[0] = CreateTexture(#PB_Any, 1024, 1024)
StartDrawing(TextureOutput(\tx[0]))
Box(0, 0, 1024, 1024, $FF151414)
For y = 0 To 1024 Step 64
If Mod(y,256) = 0
Box(0, y-2, 1024, 5, $898989)
Else
Box(0, y-3, 1024, 5, $757575)
EndIf
Next y
StopDrawing()
\ma = CreateMaterial(#PB_Any, TextureID(\tx[0]))
MaterialFilteringMode(\ma, #PB_Material_Anisotropic, 8)
AddMaterialLayer(\ma, TextureID(\tx[0]))
SetMaterialAttribute(\ma, #PB_Material_DepthWrite, #True)
\ms = CreatePlane(#PB_Any, 5, 15, 1, 1, 1, 1)
\id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma), -2.5, 0, 0)
RotateEntity(\id, 0, 0, -90)
r\walls[1]\id = CopyEntity(\id, #PB_Any)
RotateEntity(r\walls[1]\id, 0, 0, 90)
MoveEntity(r\walls[1]\id, 2.5, 0, 0)
r\walls[2]\id = CopyEntity(\id, #PB_Any)
RotateEntity(r\walls[2]\id, 90, 0, 90)
MoveEntity(r\walls[2]\id, 0, 0, -6)
EndWith
;Base_beams
With r\beamsLeft[0] ;tilted
\tx[0] = CreateTexture(#PB_Any, 1024, 1024)
StartDrawing(TextureOutput(\tx[0]))
DrawingMode(#PB_2DDrawing_AlphaBlend)
Box(0, 0, 1024, 1024, $FF151414)
Box(0, 450, 1024, 50, $88F9B21B)
Box(0, 550, 1024, 50, $88F9B21B)
Box(0, 650, 1024, 50, $88F9B21B)
Box(0, 465, 1024, 25, $FFF9D01B)
Box(0, 565, 1024, 25, $FFF9D01B)
Box(0, 665, 1024, 25, $FFF9D01B)
Box(0, 470, 1024, 10, $FFF9F31B)
Box(0, 570, 1024, 10, $FFF9F31B)
Box(0, 670, 1024, 10, $FFF9F31B)
StopDrawing()
\tx[1] = CreateTexture(#PB_Any, 1024, 1024)
StartDrawing(TextureOutput(\tx[1]))
DrawingMode(#PB_2DDrawing_AlphaBlend)
Box(0, 470, 180, 20, $FFFFE758)
Box(0, 570, 180, 20, $FFFFE758)
Box(0, 670, 180, 20, $FFFFE758)
StopDrawing()
\ma = CreateMaterial(#PB_Any, TextureID(\tx[0]))
AddMaterialLayer(\ma, TextureID(\tx[0]))
AddMaterialLayer(\ma, TextureID(\tx[1]), #PB_Material_Add)
MaterialFilteringMode(\ma, #PB_Material_Anisotropic, 8)
ScrollMaterial(\ma, 2, 0, #PB_Material_Animated,2)
\ms = CreateCube(#PB_Any, 0.2)
\id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma))
ScaleEntity(\id, 1, 7, 1)
RotateEntity(\id, 0, 0, 40,#PB_Absolute)
MoveEntity(\id, -2.2, 0.4, -5)
EndWith
With r\vbeamsLeft[0] ;vertical
\tx[0] = CreateTexture(#PB_Any, 1024, 1024)
StartDrawing(TextureOutput(\tx[0]))
DrawingMode(#PB_2DDrawing_AlphaBlend)
Box(0, 0, 1024, 1024, $FF151414)
Box(448, 0, 128, 1024, $88F9B21B)
For y = 0 To 1024 Step 48
Box(480, y+9, 64, 30, $BBEDFF58)
Box(500, y+18, 24, 10, $FFFFFFFF)
Next y
StopDrawing()
\tx[1] = CreateTexture(#PB_Any, 1024, 1024)
StartDrawing(TextureOutput(\tx[1]))
DrawingMode(#PB_2DDrawing_AlphaBlend)
For y = 0 To 1024 Step 150
Box(496, y, 30, 30, $BBEDFF58)
Next y
StopDrawing()
\ma = CreateMaterial(#PB_Any, TextureID(\tx[0]))
AddMaterialLayer(\ma, TextureID(\tx[0]))
AddMaterialLayer(\ma, TextureID(\tx[1]), #PB_Material_Add)
ScrollMaterial(\ma, 0, -0.3, #PB_Material_Animated,2)
MaterialFilteringMode(\ma, #PB_Material_Anisotropic, 8)
\ms = CreateCube(#PB_Any, 0.2)
\id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma))
ScaleEntity(\id, 1, 12, 1)
MoveEntity(\id, -2.2, 1.2, -6)
EndWith
c = 1
For x = -4 To 2 Step 2
r\vbeamsLeft[c]\id = CopyEntity(r\vbeamsLeft[0]\id, #PB_Any)
r\vbeamsRight[c]\id = CopyEntity(r\vbeamsLeft[0]\id, #PB_Any)
MoveEntity(r\vbeamsLeft[c]\id, -2.2, 1.2, x)
MoveEntity(r\vbeamsRight[c]\id, 2.2, 1.2, x)
r\beamsLeft[c]\id = CopyEntity(r\beamsLeft[0]\id, #PB_Any)
r\beamsRight[c]\id = CopyEntity(r\beamsLeft[0]\id, #PB_Any)
MoveEntity(r\beamsLeft[c]\id, -2.2, 0.4, x+1)
MoveEntity(r\beamsRight[c]\id, 2.2, 0.4, x+1)
RotateEntity(r\beamsLeft[c]\id, 0, 0, 40,#PB_Absolute)
RotateEntity(r\beamsRight[c]\id, 0, 0, -40,#PB_Absolute)
c+1
Next x
For x = -4 To 2 Step 2 ;ceiling
r\beamsLeft[c]\id = CopyEntity(r\beamsLeft[0]\id, #PB_Any)
r\beamsRight[c]\id = CopyEntity(r\beamsLeft[0]\id, #PB_Any)
MoveEntity(r\beamsLeft[c]\id, -2.2, 1.8, x+1)
MoveEntity(r\beamsRight[c]\id, 2.2, 1.8, x+1)
RotateEntity(r\beamsLeft[c]\id, 0, 0, -40,#PB_Absolute)
RotateEntity(r\beamsRight[c]\id, 0, 0, 40,#PB_Absolute)
c+1
Next x
With r\ball
\tx[0] = CreateTexture(#PB_Any, 1024, 1024)
StartDrawing(TextureOutput(\tx[0]))
DrawingMode(#PB_2DDrawing_AlphaBlend)
Box(0, 0, 1024, 1024, $FF000000)
For x = 0 To 1024 Step 30
For y = 0 To 1024 Step 30
Box(x, y, 15, 15, $FFFFBD5B)
Next y
Next x
StopDrawing()
\ma = CreateMaterial(#PB_Any, TextureID(\tx[0]))
RotateMaterial(\ma, 45,#PB_Material_Fixed)
MaterialFilteringMode(\ma, #PB_Material_Anisotropic, 8)
SetMaterialAttribute(\ma, #PB_Material_DepthWrite, #True)
\ms = CreateSphere(#PB_Any, 0.5, 32, 32)
\id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(r\ball\ma), 0, 1, -4)
\tx[1] = LoadTexture(#PB_Any, "lightning.jpg")
\ma2 = CreateMaterial(#PB_Any, TextureID(\tx[1]))
MaterialBlendingMode(r\ball\ma2, #PB_Material_Add)
AddMaterialLayer(r\ball\ma2, TextureID(r\ball\tx[1]),#PB_Material_Modulate)
ScaleMaterial(r\ball\ma2, 1.5, 1.5, 0)
ScaleMaterial(r\ball\ma2, 2.1, 2.1, 0)
ScrollMaterial(r\ball\ma2, 0.03, 0.1, #PB_Material_Animated,0)
ScrollMaterial(r\ball\ma2, -0.2, -0.01, #PB_Material_Animated,1)
EndWith
With r\smallball
\tx[0] = CreateTexture(#PB_Any, 1024, 1024)
StartDrawing(TextureOutput(\tx[0]))
Box(0, 0, 1024, 1024, $FFFFFF)
StopDrawing()
\ma = CreateMaterial(#PB_Any, TextureID(\tx[0]))
AddMaterialLayer(\ma, TextureID(\tx[0]), #PB_Material_Add)
RotateMaterial(\ma, 45,#PB_Material_Fixed)
MaterialFilteringMode(\ma, #PB_Material_Anisotropic, 8)
SetMaterialAttribute(\ma, #PB_Material_DepthWrite, #True)
\ms = CreateSphere(#PB_Any, 0.2, 32, 32)
\id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(r\smallball\ma), 0, 1, -4)
EndWith
ra = 0.7
For x = 0 To 2
With r\tube[x]
\tx[0] = CreateTexture(#PB_Any, 1024, 1024)
StartDrawing(TextureOutput(\tx[0]))
DrawingMode(#PB_2DDrawing_AlphaBlend)
Box(0, 0, 1024, 1024, $FF438EBB)
Box(0, 500, 524, 24, $FF2A93D2)
StopDrawing()
\ma = CreateMaterial(#PB_Any, TextureID(\tx[0]))
\ms = CreateTube(#PB_Any, ra, ra-0.1, 0.1, 36, 2)
\id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma), 0, 1, -4)
RotateEntity(\id, 90, 0, 90)
ra + 0.13
EndWith
Next x
With twink
\tx = LoadTexture(#PB_Any, "flare.jpg")
\ma = CreateMaterial(#PB_Any, TextureID(\tx))
MaterialBlendingMode(\ma, #PB_Material_Add)
\id = CreateParticleEmitter(#PB_Any,1, 1, 1, #PB_Particle_Box, 0, -1, -3.8)
ParticleMaterial(\id, MaterialID(\ma))
ParticleEmissionRate(\id, 500)
ParticleEmitterDirection(\id, 0, 1, 0)
ParticleSize(\id, 0.5, 1.2)
ParticleTimeToLive(\id, 0.4, 0.7)
ParticleVelocity(\id, 0.001, 0.002)
ParticleSpeedFactor(\id, 0.2)
HideParticleEmitter(\id, #True)
EndWith
EndProcedure
Procedure.i CreateTube(meshID.i, outerRadius.f, innerRadius.f, height.f, numSegBase.i=16, numSegHeight.i=1)
Protected Normal.Vector3, returnMesh.i
If meshID = -1
returnMesh = CreateMesh(#PB_Any)
Else
returnMesh = meshID
CreateMesh(returnMesh)
EndIf
If numSegBase < 1
numSegBase = 1
EndIf
If numSegHeight < 1
numSegHeight = 1
EndIf
deltaAngle.f = #PI*2 / numSegBase
deltaHeight.f = height / numSegHeight
height2.f = height / 2.0
offset = 0
For i = 0 To numSegHeight
For j = 0 To numSegBase
x0.f = outerRadius * Cos(j*deltaAngle)
z0.f = outerRadius * Sin(j*deltaAngle)
Normal\x = x0
Normal\y = 0
Normal\z = z0
Normalize(@Normal)
MeshVertexPosition(x0, i*deltaHeight-height2, z0)
MeshVertexNormal(Normal\x, Normal\y, Normal\z)
MeshVertexTextureCoordinate(j / numSegBase, i / numSegHeight)
If i <> numSegHeight
MeshIndex(offset + numSegBase + 1)
MeshIndex(offset)
MeshIndex(offset + numSegBase)
MeshIndex(offset + numSegBase + 1)
MeshIndex(offset + 1)
MeshIndex(offset)
EndIf
offset + 1
Next
Next
For i = 0 To numSegHeight
For j = 0 To numSegBase
x0.f = innerRadius * Cos(j*deltaAngle)
z0.f = innerRadius * Sin(j*deltaAngle)
Normal\x = x0
Normal\y = 0
Normal\z = z0
Normalize(@Normal)
MeshVertexPosition(x0, i*deltaHeight-height2, z0)
MeshVertexNormal(Normal\x, Normal\y, Normal\z)
MeshVertexTextureCoordinate(j / numSegBase, i / numSegHeight)
If i <> numSegHeight
MeshIndex(offset + numSegBase + 1)
MeshIndex(offset + numSegBase)
MeshIndex(offset)
MeshIndex(offset + numSegBase + 1)
MeshIndex(offset)
MeshIndex(offset + 1)
EndIf
offset + 1
Next
Next
;low cap
For j = 0 To numSegBase
x0.f = innerRadius * Cos(j*deltaAngle)
z0.f = innerRadius * Sin(j*deltaAngle)
MeshVertexPosition(x0, -height2, z0)
MeshVertexNormal(0, -1, 0)
MeshVertexTextureCoordinate(j / numSegBase, 1)
x0 = outerRadius * Cos(j*deltaAngle)
z0 = outerRadius * Sin(j*deltaAngle)
MeshVertexPosition(x0, -height2, z0)
MeshVertexNormal(0, -1, 0)
MeshVertexTextureCoordinate(j / numSegBase, 0)
If j <> numSegBase
MeshIndex(offset)
MeshIndex(offset + 1)
MeshIndex(offset + 3)
MeshIndex(offset + 2)
MeshIndex(offset)
MeshIndex(offset + 3)
EndIf
offset + 2
Next
;high cap
For j = 0 To numSegBase
x0.f = innerRadius * Cos(j*deltaAngle)
z0.f = innerRadius * Sin(j*deltaAngle)
MeshVertexPosition(x0, height2, z0)
MeshVertexNormal(0, 1, 0)
MeshVertexTextureCoordinate(j / numSegBase, 0)
x0 = outerRadius * Cos(j*deltaAngle)
z0 = outerRadius * Sin(j*deltaAngle)
MeshVertexPosition(x0, height2, z0)
MeshVertexNormal(0, 1, 0)
MeshVertexTextureCoordinate(j / numSegBase, 1)
If j <> numSegBase
MeshIndex(offset + 1)
MeshIndex(offset)
MeshIndex(offset + 3)
MeshIndex(offset)
MeshIndex(offset + 2)
MeshIndex(offset + 3)
EndIf
offset + 2
Next
FinishMesh(#True)
ProcedureReturn returnMesh
EndProcedure
Procedure Normalize(*V.Vector3)
Define.f magSq, oneOverMag
magSq = *V\x * *V\x + *V\y * *V\y + *V\z * *V\z
If magsq > 0
oneOverMag = 1.0 / Sqr(magSq)
*V\x * oneOverMag
*V\y * oneOverMag
*V\z * oneOverMag
EndIf
EndProcedure


