Ooops
November 28, 2020, 01:59:15 PM

Author Topic: [bb] Sight filter : for damage taken | blood loss by RemiD [ 1+ years ago ]  (Read 548 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
Title : Sight filter : for damage taken | blood loss
Author : RemiD
Posted : 1+ years ago

Description : An example to add a filter to the sight of the user so that it intensifies the sensation of damage | blood loss when hurt by something.

Code :
Code: BlitzBasic
  1. Global GWidth% = 800
  2. Global GHeight% = 600
  3. Global GColors% = 32
  4. Global GMode% = 2
  5. Graphics3D(GWidth,GHeight,GColors,GMode)
  6.  
  7. SeedRnd(MilliSecs())
  8.  
  9. Const CDecrease% = 1
  10. Const CIncrease% = 2
  11.  
  12. Global Camera = CreateCamera()
  13. CameraRange(Camera,0.1,100)
  14.  
  15. Global DebugFeet = CreatePivot()  
  16.  
  17. Global DebugEyes = CreatePivot()
  18. PositionEntity(DebugEyes,EntityX(DebugFeet,True),EntityY(DebugFeet,True),EntityZ(DebugFeet,True))
  19. RotateEntity(DebugEyes,EntityPitch(DebugFeet,True),EntityYaw(DebugFeet,True),EntityRoll(DebugFeet,True))
  20. MoveEntity(DebugEyes,0,1.7,0.25)
  21. EntityParent(DebugEyes,DebugFeet,True)
  22.  
  23. DebugMesh = CreateCube()
  24. ScaleMesh(DebugMesh,0.5/2,1.8/2,0.25/2)
  25. PositionMesh(DebugMesh,0,1.8/2,0)
  26. PositionEntity(DebugMesh,EntityX(DebugFeet,True),EntityY(DebugFeet,True),EntityZ(DebugFeet,True))
  27. RotateEntity(DebugMesh,EntityPitch(DebugFeet,True),EntityYaw(DebugFeet,True),EntityRoll(DebugFeet,True))
  28. EntityParent(DebugMesh,DebugFeet,True)
  29. EntityColor(DebugMesh,000,000,255)
  30.  
  31. Global MXSpeed# = 0
  32. Global MYSpeed# = 0
  33. Global DebugFeetYaw# = 0
  34. Global DebugEyesPitch# = 0
  35.  
  36. Const CEditView% = 1
  37. Const CDebugView% = 2
  38. Global CameraMode% = 0
  39. CameraMode = CDebugView
  40. EntityParent(Camera,0)
  41. PositionEntity(Camera,EntityX(DebugEyes,True),EntityY(DebugEyes,True),EntityZ(DebugEyes,True))
  42. RotateEntity(Camera,EntityPitch(DebugEyes,True),EntityYaw(DebugEyes,True),EntityRoll(DebugEyes,True))  
  43. EntityParent(Camera,DebugEyes,True)
  44.  
  45. PositionEntity(DebugFeet,5,0,-3)
  46.  
  47. Global SightFilterMesh = CreateMesh()
  48. Surface = CreateSurface(SightFilterMesh)
  49. AddVertex(Surface, -0.5, 0.5, 0.0, 0.000, 0.000)
  50. AddVertex(Surface, 0.5, 0.5, 0.0, 1.000, 0.000)
  51. AddVertex(Surface, -0.5, -0.5, 0.0, 0.000, 1.000)
  52. AddVertex(Surface, 0.5, -0.5, 0.0, 1.000, 1.000)
  53. AddTriangle(Surface,0,1,2)
  54. AddTriangle(Surface,2,1,3)
  55. UpdateNormals(SightFilterMesh)
  56. EntityFX(SightFilterMesh,1)
  57. EntityOrder(SightFilterMesh,-2)
  58. PositionEntity(SightFilterMesh,EntityX(Camera,True),EntityY(Camera,True),EntityZ(Camera,True))
  59. RotateEntity(SightFilterMesh,EntityPitch(Camera,True),EntityYaw(Camera,True),EntityRoll(Camera,True))
  60. EntityParent(SightFilterMesh,Camera,True)
  61. MoveEntity(SightFilterMesh,0,0,1)
  62. ScaleEntity(SightFilterMesh,2.0,2.0,1)
  63. EntityColor(SightFilterMesh,200,000,000) ;Blood color
  64. EntityFX(SightFilterMesh,1) ;Fullbright
  65. EntityAlpha(SightFilterMesh,1.0) ;Alpha 1.0
  66. EntityOrder(SightFilterMesh,-1) ;To make sure the SightFilterMesh is drawn after all others meshes so that it is always a filter in front of the user eyes
  67. ;HideEntity(SightFilterMesh)
  68. SightFilterAlpha# = 0.0 ;The variable that will be used to hold the value of the transparency of the filter
  69. SightFilterState% = CIncrease
  70.  
  71. For i% = 1 To 20
  72.  Bubble = CreateSphere(16)
  73.  WHD# = Rnd(0.1,1.0)
  74.  ScaleMesh(Bubble,WHD,WHD,WHD)
  75.  PositionEntity(Bubble,Rnd(0,10),Rnd(0,3),Rnd(0,10))
  76.  R% = Rand(000,255)
  77.  G% = Rand(000,255)
  78.  B% = Rand(000,255)
  79.  EntityColor(Bubble,R,G,B)
  80.  EntityAlpha(Bubble,0.1)
  81.  EntityShininess(Bubble,0.5)
  82. Next
  83.  
  84. DLight = CreateLight(1)
  85. LightColor(DLight,240,240,240)
  86. PositionEntity(DLight,-1024,1024,-1024)
  87. RotateEntity(DLight,45,-45,0)
  88.  
  89. AmbientLight(120,120,120)
  90.  
  91. Repeat
  92.  
  93.  CameraModeSelect()
  94.  
  95.  DebugUpdate()
  96.  
  97.  If(SightFilterState = CIncrease)
  98.   If(SightFilterAlpha < 1.0)
  99.    SightFilterAlpha = SightFilterAlpha + 0.01
  100.    EntityAlpha(SightFilterMesh,SightFilterAlpha)
  101.   ElseIf(SightFilterAlpha => 1.0)
  102.    SightFilterAlpha = 1.0
  103.    EntityAlpha(SightFilterMesh,SightFilterAlpha)
  104.    SightFilterState = CDecrease
  105.   EndIf
  106.  ElseIf(SightFilterState = CDecrease)
  107.   If(SightFilterAlpha > 0)
  108.    SightFilterAlpha = SightFilterAlpha - 0.01
  109.    EntityAlpha(SightFilterMesh,SightFilterAlpha)
  110.   ElseIf(SightFilterAlpha <= 0)
  111.    SightFilterAlpha = 0
  112.    EntityAlpha(SightFilterMesh,SightFilterAlpha)
  113.    SightFilterState = CIncrease
  114.   EndIf
  115.  EndIf
  116.  
  117.  If(KeyDown(2)>0)  
  118.   Wireframe(True)  
  119.  Else  
  120.   Wireframe(False)  
  121.  EndIf
  122.  
  123.  SetBuffer(BackBuffer())
  124.  RenderWorld()
  125.  
  126.  Color(255,255,255)
  127.  Text(0,0,"Tris : "+TrisRendered())
  128.  
  129.  Flip(1)
  130.  
  131. Until(KeyDown(1)>0)
  132.  
  133. End
  134.  
  135. Function CameraModeSelect()
  136.  ;Select between DebugView and EditView
  137.  If(KeyHit(15)>0)
  138.   If(CameraMode = CDebugView)
  139.    CameraMode = CEditView
  140.    EntityParent(Camera,0)
  141.   ElseIf(CameraMode = CEditView)
  142.    CameraMode = CDebugView
  143.    EntityParent(Camera,0)
  144.    PositionEntity(Camera,EntityX(DebugEyes,True),EntityY(DebugEyes,True),EntityZ(DebugEyes,True))
  145.    RotateEntity(Camera,EntityPitch(DebugEyes,True),EntityYaw(DebugEyes,True),EntityRoll(DebugEyes,True))  
  146.    EntityParent(Camera,DebugEyes,True)
  147.   EndIf
  148.  EndIf
  149. End Function
  150.  
  151. Function DebugUpdate()
  152.  If(CameraMode = CDebugView)
  153.   MXSpeed = MouseXSpeed()  
  154.   MYSpeed = MouseYSpeed()  
  155.   MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2)
  156.   DebugEyesPitch = DebugEyesPitch+MYSpeed*0.1
  157.   If(DebugEyesPitch > 89)
  158.    DebugEyesPitch = 89
  159.   EndIf
  160.   If(DebugEyesPitch < -89)
  161.    DebugEyesPitch = -89
  162.   EndIf
  163.   DebugFeetYaw = DebugFeetYaw-MXSpeed*0.1  
  164.   RotateEntity(DebugEyes,DebugEyesPitch,0,0)
  165.   RotateEntity(DebugFeet,0,DebugFeetYaw,0)  
  166.   If(KeyDown(42)>0)
  167.    SpeedCoeff# = 10.0
  168.   ElseIf(KeyDown(29)>0)
  169.    SpeedCoeff# = 0.1
  170.   Else
  171.    SpeedCoeff# = 1.0
  172.   EndIf
  173.   If(KeyDown(17)>0)  
  174.    MoveEntity(DebugFeet,0,0,0.1*SpeedCoeff)  
  175.   EndIf  
  176.   If(KeyDown(31)>0)  
  177.    MoveEntity(DebugFeet,0,0,-0.1*SpeedCoeff)  
  178.   EndIf  
  179.   If(KeyDown(30)>0)  
  180.    MoveEntity(DebugFeet,-0.1*SpeedCoeff,0,0)  
  181.   EndIf  
  182.   If(KeyDown(32)>0)  
  183.    MoveEntity(DebugFeet,0.1*SpeedCoeff,0,0)  
  184.   EndIf  
  185.   If(KeyDown(16)>0)  
  186.    MoveEntity(DebugFeet,0,-0.1*SpeedCoeff,0)  
  187.    EndIf
  188.   If(KeyDown(18)>0)  
  189.    MoveEntity(DebugFeet,0,0.1*SpeedCoeff,0)  
  190.   EndIf
  191.   If(KeyHit(201)>0)
  192.    MoveEntity(Camera,0,0,0.1)
  193.   EndIf
  194.   If(KeyHit(209)>0)
  195.    MoveEntity(Camera,0,0,-0.1)
  196.   EndIf
  197.  ElseIf(CameraMode = CEditView)
  198.   MXSpeed = MouseXSpeed()  
  199.   MYSpeed = MouseYSpeed()  
  200.   ;MoveMouse(GWidth/2,GHeight/2)
  201.  EndIf
  202. End Function


Comments :


Kryzon(Posted 1+ years ago)

 For damage type effects this actually looks very good! Reminded me of a few games.EDIT: Also, this could be used for screen fades like in a movie. Fading the screen out to a color, changing the scene, fading it back in.


RemiD(Posted 1+ years ago)

 I'm glad that you like it.Yes, i use this effect to do screen transitions, for example from the title screen to the menu screen. From transparent to black and then from black to transparent.


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal