Page 1 of 1

Mooob

Posted: Mon Feb 01, 2016 11:06 am
by DK_PETER
Part of an old project I had lying around - collecting dust.
You need a piece of music.mp3, a flare.png and a font.

Code:

Script: star.material

Code: Select all

material Starsprite
{
   technique
   {
      pass
      {

      	 scene_blend add
       	 depth_write off
         
         point_sprites on
         point_size 20

         texture_unit
         {
            texture flare.png
         }
      }
   }
}
Main code:

Code: Select all

;Part of an old project I made.
;Mimicking going back to the beginning of creation
;-------------------------------------------------
;By DK_PETER
;-------------------------------------------------
;Music created by http://www.bensound.com
;-------------------------------------------------

UseJPEGImageDecoder()
UsePNGImageDecoder()

InitEngine3D()
InitSprite()
InitKeyboard()
InitMovie()

Structure vector3D
  x.f
  y.f
  z.f
EndStructure

Structure _Object
  id.i
  ms.i
  ma.i
  tx.i
  sc.f
  elap.i
EndStructure

Structure _par
  id.i
  ma.i
  tx.i
  show.i
EndStructure


Declare.i Calc(*ReturnVec.Vector3D, CenterX.f, CenterY.f, CenterZ.f, AngleX.f, AngleY.f, RadiusX.i, RadiusY.i, RadiusZ.i )
Declare.f RandomF(min.f, Max.f, SeedVal.i = #PB_Ignore)
Declare.i CreateFakeUniverse()
Declare.i MakeSprite()

Global si._par, ob._Object, ret.i, fn.i, mu.i, tx_Elap.i
Global Dim sp.i(15), Dim ms._Object(3)

OpenWindow(0, 0, 0, 800, 600, "Mooob - Created by DK_PETER", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
OpenWindowedScreen(WindowID(0), 0, 0, 800, 600)
Add3DArchive("texture", #PB_3DArchive_FileSystem)
Add3DArchive("script", #PB_3DArchive_FileSystem)
Parse3DScripts()

;LOAD YOUR OWN FONT HERE - I'M USING THIS ONE
;http://www.dafont.com/theme.php?cat=402     -  NAME: Long shot

fn = LoadFont(#PB_Any, "Long shot", 24)

cam = CreateCamera(#PB_Any, 0, 0, 100, 100)
ret = CreateFakeUniverse()
ret = MakeSprite()
mu = LoadMovie(#PB_Any, "betterdays.mp3")
If IsMovie(mu) > 0 : PlayMovie(mu, 0) : EndIf

tx_Elap = ElapsedMilliseconds()

Repeat
  
  Repeat
    ev = WindowEvent()
  Until ev = 0
  
  RotateEntity(ms(0)\id, 0.01, 0.01, -0.01, #PB_Relative)
  RotateEntity(ms(1)\id, 0.01, -0.01, 0.01, #PB_Relative)
  RotateEntity(ms(2)\id, -0.01, -0.01, 0.01, #PB_Relative)
  
  ExamineKeyboard()
  
  If ElapsedMilliseconds() - ms(0)\elap > 10
    If ms(0)\sc - 0.1 < 1 
      ms(0)\sc = 1 
      If si\show = #False
        HideParticleEmitter(si\id, #False)
        si\show = #True
      EndIf
    Else 
      ms(0)\sc - 0.1 
    EndIf
    ScaleEntity(ms(0)\id, ms(0)\sc, ms(0)\sc, ms(0)\sc, #PB_Absolute)
    ScaleEntity(ms(1)\id, ms(0)\sc, ms(0)\sc, ms(0)\sc, #PB_Absolute)
    ScaleEntity(ms(2)\id, ms(0)\sc, ms(0)\sc, ms(0)\sc, #PB_Absolute)
    ms(0)\elap = ElapsedMilliseconds()
  EndIf
  
  RenderWorld()
  
  Select ElapsedMilliseconds() - tx_Elap
    Case 0 To 6000
      DisplayTransparentSprite(sp(0), 0, 0)
    Case 7000 To 12000
      DisplayTransparentSprite(sp(1), 0, 0)
    Case 13000 To 18000
      DisplayTransparentSprite(sp(2), 0, 0)
    Case 19000 To 25000
      DisplayTransparentSprite(sp(3), 0, 0)
    Case 26000 To 30000
      DisplayTransparentSprite(sp(4), 0, 0)
    Case 31000 To 38000
      DisplayTransparentSprite(sp(5), 0, 0)
    Case 40000 To 47000
      DisplayTransparentSprite(sp(6), 0, 0)
    Case 50000 To 58000
      DisplayTransparentSprite(sp(7), 0, 0)
    Case 59000 To 65000
      DisplayTransparentSprite(sp(8), 0, 0)
    Case 66000 To 72000
      DisplayTransparentSprite(sp(9), 0, 0)
    Case 74000 To 78000
      DisplayTransparentSprite(sp(10), 0, 0)
    Case 80000 To 85000
      DisplayTransparentSprite(sp(11), 0, 0)
    Case 87000 To 92000
      DisplayTransparentSprite(sp(12), 0, 0)
    Case 94000 To 98000
      DisplayTransparentSprite(sp(13), 0, 0)
    Case 100000 To 110000
      DisplayTransparentSprite(sp(14), 0, 0)
    Case 112000 To 120000
      DisplayTransparentSprite(sp(15), 0, 0)
  EndSelect
  
  FlipBuffers()
  
Until KeyboardPushed(#PB_Key_Escape)

End

Procedure.i CreateFakeUniverse()
  Protected v.vector3D, rad.i = 0
  
  si\id = CreateParticleEmitter(#PB_Any, 0, 0, 0, #PB_Particle_Point, 0, 0, -200)
  si\tx = LoadTexture(#PB_Any, "flare.png")
  si\ma = CreateMaterial(#PB_Any, TextureID(si\tx))
  ParticleSize(si\id, 80, 80)
  MaterialBlendingMode(si\ma, #PB_Material_Add)
  ParticleMaterial(si\id, MaterialID(si\ma))
  ParticleEmitterDirection(si\id, 0, 0, 1)
  ParticleEmissionRate(si\id, 10)
  ParticleTimeToLive(si\id, 0.1, 0.4)
  HideParticleEmitter(si\id, #True)
  si\show = #False
  
  ms(0)\ms = CreateMesh(#PB_Any, #PB_Mesh_PointList, #PB_Mesh_Dynamic)
  For x = 0 To 100
    v\x = 0: v\y = 0: v\z = 0
    For y = 0 To 100
      If rad + 1 > 360 : rad = 0 : Else : rad + 1 : EndIf
      Calc(v, RandomF(-10,10), RandomF(-10,10), RandomF(-10,10), rad, rad , RandomF(-10,10),  RandomF(-2,2), RandomF(-10,10))
      MeshVertexPosition(v\x , v\y , v\z)
    Next y
  Next x
  NormalizeMesh(ms(0)\ms)
  FinishMesh(#True)
  ms(0)\tx = CreateTexture(#PB_Any, 48, 48)
  StartDrawing(TextureOutput(ms(0)\tx))
  Box(0, 0, 48, 48, $FFFFFF)
  StopDrawing()
  
  ms(0)\ma = GetScriptMaterial(#PB_Any, "Starsprite")
  ms(0)\id = CreateEntity(#PB_Any, MeshID(ms(0)\ms),MaterialID(ms(0)\ma), 0, 0, -4000)
  ms(1)\id = CopyEntity(ms(0)\id, #PB_Any)
  ms(1)\ma = CopyMaterial(ms(0)\ma, #PB_Any)
  SetMaterialColor(ms(1)\ma, #PB_Material_SelfIlluminationColor, $1DEBFF)
  SetEntityMaterial(ms(1)\id, MaterialID(ms(1)\ma))
  MoveEntity(ms(1)\id, 20, 0, -4000)
  RotateEntity(ms(1)\id, 90, 0, 0)
  
  ms(2)\id = CopyEntity(ms(0)\id, #PB_Any)
  ms(2)\ma = CopyMaterial(ms(0)\ma, #PB_Any)
  SetMaterialColor(ms(2)\ma, #PB_Material_SelfIlluminationColor, $001CFF)
  SetEntityMaterial(ms(2)\id, MaterialID(ms(2)\ma))
  MoveEntity(ms(2)\id, -20, 0, -4000)
  RotateEntity(ms(2)\id, -90, 0, 0)
  
  ms(0)\sc = 500 
  ScaleEntity(ms(0)\id, 500, 500, 500)
  ScaleEntity(ms(1)\id, 500, 500, 500)
  ScaleEntity(ms(2)\id, 500, 500, 500)
  ProcedureReturn #True
EndProcedure

Procedure.i Calc(*ReturnVec.Vector3D, CenterX.f, CenterY.f, CenterZ.f, AngleX.f, AngleY.f, RadiusX.i, RadiusY.i, RadiusZ.i )
  *ReturnVec\X = CenterX + RadiusX*Cos(AngleY)*Cos(AngleX)
  *ReturnVec\Y = CenterY + RadiusY*Sin(AngleX)
  *ReturnVec\Z = CenterZ + RadiusZ*Sin(AngleY)*Cos(AngleX)
EndProcedure

Procedure.i MakeSprite()
  Protected tx.s, x
  Restore History
  For x = 0 To 15
    Read.s tx
    sp(x) = CreateSprite(#PB_Any, ScreenWidth(), 100)
    StartDrawing(SpriteOutput(sp(x)))
    DrawingFont(FontID(fn))
    DrawingMode(#PB_2DDrawing_Transparent)
    DrawText(ScreenWidth()/2 - TextWidth(tx)/2, 0, tx, $F7E343)
    StopDrawing()
    TransparentSpriteColor(sp(x), $0)
  Next x
  ProcedureReturn #True
EndProcedure

Procedure.f RandomF(min.f, Max.f, SeedVal.i = #PB_Ignore)
  If SeedVal = #PB_Ignore : SeedVal = ElapsedMilliseconds() : EndIf
  ProcedureReturn (Min + (Max - Min) * Random(SeedVal) / SeedVal)
EndProcedure

DataSection
  History:
  Data.s "The universe..."
  Data.s "Billions of galaxies -"
  Data.s "each containing billions of suns."
  Data.s "Countless of possibilities for life to flourish"
  Data.s "and vanish again in a tiny cosmic blink of an eye."
  Data.s "Now..."
  Data.s "We're travelling back...."
  Data.s "to the very beginning of time."
  Data.s "Back to the creation of the universe...."
  Data.s "The primordial soup of creation."
  Data.s "The moments after the big bang.."
  Data.s "Now...The singularity..."
  Data.s "The point of creation."
  Data.s "The very beginning of time."
  Data.s "The End"
  Data.s "Created by DK_PETER"
EndDataSection

Re: Mooob

Posted: Mon Feb 01, 2016 11:54 am
by IdeasVacuum
mesmerising 8)

Re: Mooob

Posted: Mon Feb 01, 2016 2:04 pm
by AndyLy
This program is for relaxation :)
Very nice.