PureBasic Forum
https://www.purebasic.fr/english/

Atomic ghost
https://www.purebasic.fr/english/viewtopic.php?f=36&t=73789
Page 1 of 1

Author:  DK_PETER [ Sat Oct 12, 2019 6:06 pm ]
Post subject:  Atomic ghost

Just a little particle ghost.
Code:
;Atomic Ghost
InitEngine3D()
InitSprite()
InitKeyboard()

Structure bVector
  x.f
  y.f
  z.f
  bas.f
EndStructure

Structure _Part
  ma.i
  id.i
EndStructure

Structure object Extends _Part
  ms.i
  tx.i
EndStructure


Global NewList b.object()
Global NewList p._Part()
Global ground.object, Sky.object, geo.i, cma.i, ret.i
Global Dim t.i(5)

Declare.i MakeGrad(RGBAInnerColor.i = $FFD2D7DA, RGBAOuterColor.i = $FF000000, Size.i = 1024, CircGrad.f = #PB_Any)
Declare.i CreateBuilding(*o.object)
Declare.i CreateGround()
Declare.i MakeTexture(Size.i = 512)
Declare.f RandomF(Min.f, Max.f, Res.i = 100000)
Declare.i CreateGhost()

If InitEngine3D(#PB_Engine3D_DebugLog) = 0 Or InitSprite() = 0 Or InitKeyboard() = 0
  MessageRequester("Error", "Unable to initialize...")
  End
EndIf
OpenWindow(0, 0, 0, 800, 800, "Atomic Clown", #PB_Window_ScreenCentered|#PB_Window_BorderLess)
OpenWindowedScreen(WindowID(0), 0, 0, 800, 800)
CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0, 0, 1, 0)

t(0) = MakeGrad()
t(1) = MakeGrad($9B4B4B4B, $0F000000)
t(2) = MakeGrad($D24B4BDC, $024B4BDC)

ret = CreateGround()

geo = CreateStaticGeometry(#PB_Any, 600, 10, 600, #False)
MakeTexture()
For x = 0 To 100
  AddElement(b())
  ret.i = CreateBuilding(b())
Next x
BuildStaticGeometry(geo)

ret = CreateGhost()

Repeat
  Repeat : ev.i = WindowEvent() : Until ev = 0
 
  RenderWorld()
 
  FlipBuffers()
 
  ExamineKeyboard()
 
  While IsScreenActive() = 0 : Wend
 
Until KeyboardPushed(#PB_Key_Escape)

Procedure.i MakeGrad(RGBAInnerColor.i = $FFD2D7DA, RGBAOuterColor.i = $FF000000, Size.i = 1024, CircGrad.f = #PB_Any)
  Protected im.i = CreateImage(#PB_Any, Size*2, Size*2, 32)
  Protected rad = (Size/5)
  StartDrawing(ImageOutput(im))
  DrawingMode(#PB_2DDrawing_AlphaBlend|#PB_2DDrawing_Gradient)
  BackColor(RGBAInnerColor) : FrontColor(RGBAOuterColor)
  CircularGradient(Size, Size, Size-rad)
  Circle(Size, Size,  Size-rad)
  If CircGrad <> #PB_Any
    GradientColor(CircGrad, RGBAOuterColor)
  EndIf
  StopDrawing()
  ResizeImage(im, Size/2, Size/2)
  ProcedureReturn im
EndProcedure

Procedure.i MakeTexture(Size.i = 512)
  Protected c.i, x.i, y.i, gCol.i = 100
  For c = 0 To 5
    t(c) = CreateTexture(#PB_Any, Size, Size, "BuildTex_" + Str(c))
    StartDrawing(TextureOutput(t(c)))
    Box(0, 0, Size, Size, RGB(gCol, gCol, gCol))
    For y = 0 To Size Step 32
      For x = 0 To Size Step 32
        If Random(200) > 150
          Box(x, y, 16, 16, RGB(200, 200, 200))
        Else
          Box(x, y, 16, 16, RGB(gCol+25, gCol+20, gCol))
        EndIf
      Next x
    Next y
    gCol + 25
    StopDrawing()
  Next c
  ProcedureReturn #True
EndProcedure

Procedure.i CreateBuilding(*o.object)
  Protected val.f, sca.f
  With *o
    Select Random(500)
      Case 0 To 100
        val = 0.5
      Case 101 To 200
        val = 0.7
      Case 201 To 300
        val = 0.9
      Case 301 To 400
        val = 1.2
      Default
        val = 1.4
    EndSelect
    \ms = CreateCube(#PB_Any, val)
    \ma = CreateMaterial(#PB_Any, TextureID(t(Random(5))))
    \id = CreateEntity(#PB_Any,MeshID(\ms), MaterialID(\ma))
    If Random(100) > 60
      sca = RandomF(1.0, 3.0)
      AddStaticGeometryEntity(geo, EntityID(\id), RandomF(-30, 30), val/2, RandomF(-50, -40), 1.0, sca*val, 1.0)
    Else
      AddStaticGeometryEntity(geo, EntityID(\id), RandomF(-30, 30), val/2, RandomF(-50, -40))
    EndIf
  EndWith
  ProcedureReturn #True
EndProcedure

Procedure.i CreateGhost()
  Protected tx.i, im.i, x.i
  im = MakeGrad($FF666666, $0F111111, 1024, 0.5)
  tx = CreateTexture(#PB_Any, 512, 512, "major_cloud1")
  StartDrawing(TextureOutput(tx))
  DrawImage(ImageID(im), 0, 0, OutputWidth(), OutputHeight())
  StopDrawing() 
  For x = 0 To 3
    AddElement(p())
    With p()
      \ma = CreateMaterial(#PB_Any, TextureID(tx))
      If x = 1 Or x = 3 : MaterialBlendingMode(\ma, #PB_Material_Color) : Else : MaterialBlendingMode(\ma, #PB_Material_Add) : EndIf
      AddMaterialLayer(\ma, TextureID(tx), #PB_Material_Replace)
      \id = CreateParticleEmitter(#PB_Any, 1, 0, 1, #PB_Particle_Point, 0, 0.3, -40)
      ParticleMaterial(\id, MaterialID(\ma))
      If x = 0 Or x = 2 : ParticleSize(\id, 0.4, 0.4) : Else : ParticleSize(\id, 0.1, 0.1) : EndIf
      If x = 0 Or x = 1 : ParticleEmitterDirection(\id, 1, 0, 0) : Else : ParticleEmitterDirection(\id, -1, 0, 0) : EndIf
      ParticleScaleRate(\id, 2.51)
      ParticleVelocity(\id, #PB_Particle_MinimumVelocity, 2.5)
      ParticleVelocity(\id, #PB_Particle_Velocity, 3.5)
      ParticleVelocity(\id, #PB_Particle_MaximumVelocity, 4.8)
      ParticleTimeToLive(\id, 1.8, 3.3)
      ParticleEmissionRate(\id, 25)
      ParticleSpeedFactor(\id, 0.4)
      ParticleAngle(\id, 0, 260)
    EndWith
  Next x
  For x  = 0 To 1
    AddElement(p())
    With p()
      \ma = CreateMaterial(#PB_Any, TextureID(tx))
      If x = 0 : MaterialBlendingMode(\ma, #PB_Material_Add) : Else : MaterialBlendingMode(\ma, #PB_Material_Color) : EndIf
      \id = CreateParticleEmitter(#PB_Any, 1, 0, 3, #PB_Particle_Box, 0, 0.3, -40)
      ParticleMaterial(\id, MaterialID(\ma))
      If x = 1 : ParticleSize(\id, 1, 2) : Else : ParticleSize(\id, 3, 2) : EndIf
      ParticleEmitterDirection(\id, 0, 1, 0)
      ParticleScaleRate(\id, 0.51)
      ParticleVelocity(\id, #PB_Particle_MinimumVelocity, 3)
      ParticleVelocity(\id, #PB_Particle_Velocity, 3)
      ParticleVelocity(\id, #PB_Particle_MaximumVelocity, 3)
      ParticleTimeToLive(\id, 2, 2)
      ParticleEmissionRate(\id, 50)
      ParticleSpeedFactor(\id, 0.3)
      ParticleAngle(\id, 0, 160)
    EndWith
  Next x
  For x = 0 To 1
    AddElement(p())
    With p()
      \ma = CreateMaterial(#PB_Any, TextureID(tx))
      If x = 0 : MaterialBlendingMode(\ma, #PB_Material_Add) : Else : MaterialBlendingMode(\ma, #PB_Material_Color) : EndIf
      \id = CreateParticleEmitter(#PB_Any, 10, 3, 12, #PB_Particle_Box, 0, 7, -40)
      ParticleMaterial(\id, MaterialID(\ma))
      If x = 1 : ParticleSize(\id, 2, 1) : Else : ParticleSize(\id, 1, 2) : EndIf
      ParticleEmitterDirection(\id, 0, 0, 1)
      ParticleScaleRate(\id, 9)
      ParticleVelocity(\id, #PB_Particle_MinimumVelocity, 0.6)
      ParticleVelocity(\id, #PB_Particle_Velocity, 1.0)
      ParticleVelocity(\id, #PB_Particle_MaximumVelocity, 1.1)
      ParticleTimeToLive(\id, 1.0, 1.2)
      ParticleEmissionRate(\id, 70)
      ParticleSpeedFactor(\id, 0.7)
      ParticleAngle(\id, 90, 160)
    EndWith
  Next x
  For x = 0 To 1
    AddElement(p())
    With p()
      \ma = CreateMaterial(#PB_Any, TextureID(tx))
      If x = 0 : MaterialBlendingMode(\ma, #PB_Material_Add) : Else : MaterialBlendingMode(\ma, #PB_Material_Color) : EndIf
      \id = CreateParticleEmitter(#PB_Any, 10, 3, 12, #PB_Particle_Box, 0, 11, -40)
      ParticleMaterial(\id, MaterialID(\ma))
      If x = 1 : ParticleSize(\id, 2, 1) : Else : ParticleSize(\id, 1, 2) : EndIf
      ParticleEmitterDirection(\id, 0, 0, 1)
      ParticleScaleRate(\id, 15)
      ParticleVelocity(\id, #PB_Particle_MinimumVelocity, 0.6)
      ParticleVelocity(\id, #PB_Particle_Velocity, 1.0)
      ParticleVelocity(\id, #PB_Particle_MaximumVelocity, 1.1)
      ParticleTimeToLive(\id, 1.0, 1.2)
      ParticleEmissionRate(\id, 75)
      ParticleSpeedFactor(\id, 0.7)
      ParticleAngle(\id, 90, 160)
    EndWith
  Next x
  For x = 0 To 1
    AddElement(p())
    With p()
      \ma = CreateMaterial(#PB_Any, TextureID(tx))
      SetMaterialColor(\ma, #PB_Material_AmbientColor, $FB0017FF)
      MaterialBlendingMode(\ma, #PB_Material_Add)
      If x = 0
        \id = CreateParticleEmitter(#PB_Any, 0.1, 1, 0.1, #PB_Particle_Point, -2, 9, -34)
      Else
        \id = CreateParticleEmitter(#PB_Any, 0.1, 1, 0.1, #PB_Particle_Point, 2, 9, -34)
      EndIf
      ParticleMaterial(\id, MaterialID(\ma))
      ParticleSize(\id, 1, 2)
      ParticleEmitterDirection(\id, 0, 0, 1)
      ParticleVelocity(\id, #PB_Particle_MinimumVelocity, 0.1)
      ParticleVelocity(\id, #PB_Particle_Velocity, 0.5)
      ParticleVelocity(\id, #PB_Particle_MaximumVelocity, 0.8)
      ParticleTimeToLive(\id, 1.0, 1.2)
      ParticleEmissionRate(\id, 25)
      ParticleSpeedFactor(\id, 0.5)
    EndWith
  Next x
  For x = 0 To 1
    AddElement(p())
    With p()
      \ma = CreateMaterial(#PB_Any, TextureID(tx))
      SetMaterialColor(\ma, #PB_Material_SelfIlluminationColor, $FB00FFFF)
      MaterialBlendingMode(\ma, #PB_Material_Add)
      If x = 0
        \id = CreateParticleEmitter(#PB_Any, 0.1, 0.5, 0.1, #PB_Particle_Box, 0, 6, -34)
      Else
        \id = CreateParticleEmitter(#PB_Any, 0.1, 0.5, 0.1, #PB_Particle_Box, 0, 6, -34)
      EndIf
      ParticleMaterial(\id, MaterialID(\ma))
      ParticleSize(\id, 1.5, 0.5)
      If x = 0
        ParticleEmitterDirection(\id, -1, 0.2, 0)
      Else
        ParticleEmitterDirection(\id, 1, 0.2, 0)
      EndIf
      ParticleVelocity(\id, #PB_Particle_MinimumVelocity, 0.1)
      ParticleVelocity(\id, #PB_Particle_Velocity, 0.5)
      ParticleVelocity(\id, #PB_Particle_MaximumVelocity, 0.8)
      ParticleTimeToLive(\id, 1.0, 1.6)
      ParticleEmissionRate(\id, 10)
      ParticleSpeedFactor(\id, 0.6)
      ParticleColorFader(\id, 0, 1, 1, 0)
    EndWith
  Next x
  For x = 0 To 1
    AddElement(p())
    With p()
      \ma = CreateMaterial(#PB_Any, TextureID(tx))
      SetMaterialColor(\ma, #PB_Material_SelfIlluminationColor, $FB00FFFF)
      MaterialBlendingMode(\ma, #PB_Material_Add)
      If x = 0
        \id = CreateParticleEmitter(#PB_Any, 0.1, 0.5, 0.1, #PB_Particle_Box, 0, 5.4, -34)
      Else
        \id = CreateParticleEmitter(#PB_Any, 0.1, 0.5, 0.1, #PB_Particle_Box, 0, 5.4, -34)
      EndIf
      ParticleMaterial(\id, MaterialID(\ma))
      ParticleSize(\id, 1.3, 0.3)
      If x = 0
        ParticleEmitterDirection(\id, -1, 0.5, 0)
      Else
        ParticleEmitterDirection(\id, 1, 0.5, 0)
      EndIf
      ParticleVelocity(\id, #PB_Particle_MinimumVelocity, 0.1)
      ParticleVelocity(\id, #PB_Particle_Velocity, 0.5)
      ParticleVelocity(\id, #PB_Particle_MaximumVelocity, 0.8)
      ParticleTimeToLive(\id, 1.0, 3)
      ParticleEmissionRate(\id, 30)
      ParticleSpeedFactor(\id, 0.6)
      ParticleColorFader(\id, 0, 1, 1, 0)
    EndWith
  Next x
EndProcedure

Procedure.i CreateGround()
  ground\ms = CreatePlane(#PB_Any,10, 10, 1, 1, 1, 1)
  ground\tx = CreateTexture(#PB_Any, 50, 50, "ground")
  cma = MakeGrad($9B4B4B4B, $0F222222)
  StartDrawing(TextureOutput(ground\tx))
  Box(0, 0, 50, 50, $3E4443)
  For x = 0 To 100
    DrawImage(ImageID(cma), Random(50), Random(50), Random(3,1), Random(3,1))
  Next x
  StopDrawing()
  ground\ma = CreateMaterial(#PB_Any, TextureID(ground\tx))
  MaterialCullingMode(ground\ma, #PB_Material_NoCulling)
  ScaleMaterial(ground\ma, 0.03, 0.03)
  ground\id = CreateEntity(#PB_Any, MeshID(ground\ms), MaterialID(ground\ma), 0, 0, 0)
  RotateEntity(ground\id, 0, 0, 0)
  ScaleEntity(ground\id, 20, 1, 20)
  ProcedureReturn #True
EndProcedure

Procedure.f RandomF(Min.f, Max.f, Res.i = 100000)
  ProcedureReturn (Min + (Max - Min) * Random(Res) / Res)
EndProcedure

Author:  chi [ Sat Oct 12, 2019 7:02 pm ]
Post subject:  Re: Atomic ghost

Nice! Kinda reminds me of the Stay Puft Marshmallow Man :)

Author:  Kwai chang caine [ Tue Oct 15, 2019 7:38 pm ]
Post subject:  Re: Atomic ghost

Nice !!!! :lol:

I almost called the

Image

Thanks for sharing 8)

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/