EDIT2:
Third attempt to do bullet holes.
download the file below and unpack the texture folder.
*poof*
Link won't remain permanently since you easily can add images from your own collection.
Save the code below OUTSIDE the texture folder.
Code: Select all
;Something I would find immensely useful:
;RemoveMaterialLayer(mat, optional LayerNumber)
;Test 3:
;Doing bullet holes...Don't know if this is the right way to do it
;but right now - it was the only thing I could come up with.
;The bullet holes are now placed correctly...I think
;Added primitive particle to bullet hole
;The zoom function isn't finished since it only moves at the z axis.
;If someone knows a different way to do bullet holes (not sprites or anything)
;I would love to change the texture itself
;Anyway..Let me know if you have a better solution.
;TIA
;Left click - shoot
;right click - zoom
;escape - exit
InitEngine3D()
InitSprite()
InitMouse()
InitKeyboard()
DeclareModule _Holes
Declare.i SetResolution(Width.i = 1024, Height.i = 768, Title.s = "", FullScreen.i = #False)
Declare.i RunDemo()
EndDeclareModule
Module _Holes
UsePNGImageDecoder()
UseJPEGImageDecoder()
Add3DArchive("texture", #PB_3DArchive_FileSystem)
Declare.i MakeWalls()
Declare.i MakeScope()
Declare.i MakePart(x.i, y.i, z.i)
Declare.i MakeHole(x.i, y.i, z.i)
Structure _Mesh
id.i
ms.i
ma.i
hole.i[2]
tex.i
im.i
tx2.i
EndStructure
Structure _Par
id.i
tx.i
ma.i
EndStructure
Structure _vars
Scope.i
Coords.i
Zoom.f
Fs.i
Win.i
Cam.i
Shot.i
par.i
parem.i
EndStructure
Global Fs.i = False
Global va._vars
Global wall._Mesh
Global pa._Par
Global gpoint.POINT
Procedure.i SetResolution(Width.i = 1024, Height.i = 768, Title.s = "", FullScreen.i = #False)
va\Fs = FullScreen
If FullScreen = #False
va\Win = OpenWindow(#PB_Any, 0, 0, Width, Height, Title, #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
Scr = OpenWindowedScreen(WindowID(va\Win), 0 ,0 , Width, Height, #False, 0, 0, #PB_Screen_SmartSynchronization)
Else
Scr = OpenScreen(1024, 768, 32, Title,#PB_Screen_SmartSynchronization, 60)
EndIf
va\Cam = CreateCamera(#PB_Any, 0, 0, 100, 100)
MoveCamera(va\Cam, 0, 0, 0)
va\Zoom = #False
EndProcedure
Procedure.i MakeScope()
Protected w.i = ScreenWidth(), h.i = ScreenHeight(), Rest.i
va\Coords = CreateSprite(#PB_Any, 300, 50)
Rest = (ScreenWidth()/2-ScreenHeight()/2)+52
va\Scope = CreateSprite(#PB_Any,w, h)
StartDrawing(SpriteOutput(va\Scope))
Box(0, 0, ScreenWidth(), ScreenHeight(), $1)
Circle(w/2,h/2,h/2-30,$555353)
Circle(w/2,h/2,h/2-51, $FFF251)
LineXY(w/2, 52, w/2, h/3, $555251)
For y = 53 To h/3 Step 4
LineXY(w/2-5, y, w/2+5,y, $555251)
Next y
LineXY(w/2, h-52, w/2, h-h/3, $555251)
For y = h-52 To h-h/3 Step -4
LineXY(w/2-5, y, w/2+5,y, $555251)
Next y
LineXY(Rest, h/2, Rest+w/4, h/2, $555251)
For x = Rest To (Rest+w/4) Step 4
LineXY(x, (h/2)-5, x,(h/2)+5, $555251)
Next x
LineXY(w-Rest, h/2, (w/2-Rest) + w/4, h/2, $555251)
For x = (w-Rest) To (w-Rest)-w/4 Step -4
LineXY(x, (h/2)-5, x,(h/2)+5, $555251)
Next x
Circle(w/2,h/2, 2,$555251)
StopDrawing()
TransparentSpriteColor(va\Scope, $FFF251)
EndProcedure
Procedure.i MakeWalls()
Protected tmptx.i
wall\im = LoadImage(#PB_Any, "texture\man2.jpg")
ResizeImage(wall\im, 60, 100,#PB_Image_Smooth)
tmptx = CreateTexture(#PB_Any, 1024, 1024)
StartDrawing(TextureOutput(tmptx))
DrawingMode(#PB_2DDrawing_AllChannels)
For x = 0 To 1024 Step 80
For y = 0 To 1024 Step 105
DrawImage(ImageID(wall\im), x, y)
Next y
Next x
StopDrawing()
wall\hole[0] = LoadImage(#PB_Any, "texture\1a.jpg")
wall\hole[1] = LoadImage(#PB_Any, "texture\2a.jpg")
wall\tex = LoadTexture(#PB_Any, "glass_grey.jpg")
wall\ma = CreateMaterial(#PB_Any, TextureID(wall\tex))
MaterialBlendingMode(wall\ma, #PB_Material_Add)
AddMaterialLayer(wall\ma, TextureID(tmptx), #PB_Material_Color)
MaterialFilteringMode(wall\ma, #PB_Material_Anisotropic, 8)
wall\ms = CreatePlane(#PB_Any, 1024, 1024, 1, 1, 1, 1)
wall\id = CreateEntity(#PB_Any, MeshID(wall\ms), MaterialID(wall\ma), 0, 0, -450)
RotateEntity(wall\id, 90, 0, 180)
EndProcedure
Procedure.i MakePart(x.i, y.i, z.i)
pa\id = CreateParticleEmitter(#PB_Any, 15,15,200,#PB_Particle_Point, x, y, z)
pa\tx = CreateTexture(#PB_Any,10,10)
StartDrawing(TextureOutput(pa\tx))
DrawingMode(#PB_2DDrawing_AlphaBlend)
Box(2,2,4,3, $C2F0B4A8)
Box(6,7,2,1, $C2F0B4A8)
StopDrawing()
pa\ma = CreateMaterial(#PB_Any, TextureID(pa\tx))
MaterialBlendingMode(pa\ma, #PB_Material_Add)
ParticleEmissionRate(pa\id, 309)
ParticleEmitterDirection(pa\id, 0, 0, 1)
ParticleMaterial(pa\id, MaterialID(pa\ma))
ParticleSize(pa\id, 10,10)
ParticleTimeToLive(pa\id, 0.2, 0.9)
ParticleVelocity(pa\id, 400, 500)
ParticleSpeedFactor(pa\id, 5.3)
EndProcedure
Procedure.i MakeHole(x.i, y.i, z.i)
Protected Thehole.i, tx.i, ty.i
If Random(100,0) < 50
Thehole = 0
Else
Thehole = 1
EndIf
If IsTexture(wall\tx2)
FreeTexture(wall\tx2)
EndIf
wall\tx2 = CreateTexture(#PB_Any, 1024, 1024)
StartDrawing(TextureOutput(wall\tx2))
If x < 0
tx = 512 - Abs(x) ;(x * -1)
Else
tx = 512+x
EndIf
If y < 0
ty = 512 + Abs(y) ;(y * -1)
Else
ty = 512-y
EndIf
DrawImage(ImageID(wall\hole[Thehole]),tx-ImageWidth(wall\hole[Thehole])/2,ty-ImageHeight(wall\hole[Thehole])/2)
StopDrawing()
AddMaterialLayer(wall\ma, TextureID(wall\tx2) , #PB_Material_Color)
;
StartDrawing(SpriteOutput(va\Coords))
Box(0,0,300, 50, $1)
DrawText(0, 0, "x = " + Str(tx) + " y = " + Str(ty) + " z = " + Str(z), $50B4A8)
StopDrawing()
EndProcedure
Procedure.i RunDemo()
MakeScope()
MakeWalls()
va\Zoom = 0
va\Shot = 0
va\par = 0
va\parem = 500
gpoint\x = 0
gpoint\y = 0
Repeat
If va\Fs = #False
Repeat
ev = WindowEvent()
Until ev = 0
EndIf
ExamineMouse()
If MouseButton(#PB_MouseButton_Right) = 1 And va\Zoom > -320
va\Zoom - 10
ElseIf MouseButton(#PB_MouseButton_Right) = 0 And va\Zoom < 0
va\Zoom + 10
EndIf
If MouseButton(#PB_MouseButton_Left) = 1 And va\Shot = 0
;Bang
ret = MousePick(va\Cam, ScreenWidth()/2, ScreenHeight()/2, #PB_Ignore)
If ret
va\parem = ElapsedMilliseconds()
va\par = 1
MakeHole(PickX(),PickY(), PickZ())
MakePart(PickX(),PickY(), PickZ())
EndIf
va\Shot = 1
ElseIf MouseButton(#PB_MouseButton_Left) = 0 And va\Shot = 1
va\Shot = 0
EndIf
If va\par = 1 And ElapsedMilliseconds()-va\parem > 100
If IsParticleEmitter(pa\id)
FreeParticleEmitter(pa\id)
FreeMaterial(pa\ma)
FreeTexture(pa\tx)
EndIf
va\par = 0
EndIf
MoveCamera(va\Cam, 0, 0, va\Zoom, #PB_Absolute)
RotateCamera(va\Cam, -MouseDeltaY() * 0.03 , -MouseDeltaX() * 0.03, 0,#PB_Relative)
ExamineKeyboard()
RenderWorld()
DisplayTransparentSprite(va\Scope, 0, 0)
DisplaySprite(va\Coords, 0,0)
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
EndProcedure
EndModule
_Holes::SetResolution(1024, 768, "Sniper")
_Holes::RunDemo()