Graphics3D 800,600,0,0
CentreX=GraphicsWidth()/2
CentreY=GraphicsHeight()/2
; bullet hole & spark sprites
hole=CreateSprite()
ScaleSprite hole,0.25,0.25
SpriteViewMode hole,2
EntityBlend hole,2
EntityTexture hole,Cirtex(32)
HideEntity hole
spark=CreateSprite()
ScaleSprite spark,0.1,0.1
EntityBlend spark,3
HideEntity spark
; make environment
AmbientLight 0,0,0
camera=CreateCamera()
PositionEntity camera, 0,-15,0
room=CreatePivot()
Cube=CreateSegCube(12,room)
EntityPickMode cube,2
EntityColor cube,250,100,50
ScaleMesh cube,40,40,40
FlipMesh cube
Column=CreateCylinder(16,True,room)
EntityPickMode column,2
EntityFX column,4
EntityColor column,150,120,120
PositionMesh column,0,1,0
ScaleMesh Column,6,24,6
sphere=CreateSphere(12,column)
EntityShininess sphere,0.25
EntityColor sphere,200,200,50
EntityPickMode sphere,2
ScaleMesh sphere,-6,-6,-6 ; flip normals
PositionMesh sphere,0,54,0
PositionEntity Column,-30,-40,-30
PositionEntity CopyEntity(column,room),30,-40,-30
PositionEntity CopyEntity(column,room),30,-40,30
PositionEntity CopyEntity(column,room),-30,-40,30
; add a few lights
lpiv=CreatePivot(room)
light=CreateLight(2,lpiv) : PositionEntity light,-30,14,-30
light=CreateLight(2,lpiv) : PositionEntity light,30,14,-30
light=CreateLight(2,lpiv) : PositionEntity light,30,14,30
light=CreateLight(2,lpiv) : PositionEntity light,-30,14,30
; load gunshot sound - your path to this may be different.
shot = LoadSound("C:\Program Files\Blitz3D\Samples\Blitz 3D Samples\si\fps\gunshot.wav")
holes = CreatePivot(room) ; bullet hole list
sparks = CreatePivot(room) ; sparks list
; main ---------------------------------------------------------
MoveMouse CentreX,CentreY
Repeat
mxs#=MouseXSpeed()
mys#=MouseYSpeed()
If MouseDown(2) Then
MoveEntity camera,0,0,-mys*0.25
Else
TurnEntity camera,mys*0.5,0,0 : TurnEntity camera,0,-mxs*0.5,0,True
EndIf
MoveMouse centrex,centrey
If MouseDown(1) Or KeyHit(57) Then
If MilliSecs()>delaytime Then
delaytime=MilliSecs()+100
If shot Then PlaySound shot
picked=CameraPick(camera, CentreX+Rnd(-10,10),CentreY+Rnd(-10,10))
If picked<>0 Then
makehole(hole,holes)
makespark(spark,sparks)
EndIf
EndIf
EndIf
updatesparks(sparks)
For i=1 To CountChildren(lpiv)
light=GetChild(lpiv,i)
LightRange light,15+Sin((MilliSecs() And $FFFFF)/24+i*90 )*8
Next
If KeyHit(17) Then wire=Not wire : WireFrame wire
RenderWorld
Color 255,255,255
Line centrex-4,centrey,centrex+4,centrey : Line centrex,centrey-4,centrex,centrey+4
Flip
Until KeyHit(1)
;----------------------------------------------------------------------------------------
Function makehole(hole,holes)
hole=CopyEntity(hole,holes)
PositionEntity hole,PickedX(),PickedY(),PickedZ(),True
AlignToVector hole,-PickedNX(),-PickedNY(),-PickedNZ(),3
MoveEntity hole,0,0,-0.05
If CountChildren(holes)>200 Then FreeEntity GetChild(holes,1)
End Function
Function makespark(spark,sparks)
Local rv#=Rnd(-0.8,0.8)
spark=CopyEntity(spark,sparks)
PositionEntity spark,PickedX(),PickedY(),PickedZ(),True
AlignToVector spark,-PickedNX()+Rv,-PickedNY()+Rv,-PickedNZ()+Rv,3
End Function
Function updatesparks(sparks)
Local i,life
For i=1 To CountChildren(sparks)
spark=GetChild(sparks,i)
life=EntityName(spark) : life=life+1 : NameEntity spark,life
MoveEntity spark,0,0,-1 : TranslateEntity spark,0,-life/5.0,0,True
EntityColor spark,512/life,512/life,512/life
If life>20 Then FreeEntity spark : i=i-1
Next
End Function
Function Cirtex(rad)
texture=CreateTexture(rad,rad)
SetBuffer TextureBuffer(texture)
Color 255,255,255 : Rect 0,0,rad,rad,True
Color 200,200,200 : Oval 0,0,rad,rad,True
Color 100,100,100 : Oval 12,12,rad-24,rad-24,True
SetBuffer BackBuffer()
Return texture
End Function
; Birdies CreateSegCube Function from the archives (slightly modified)
Function CreateSegCube(segs=1,parent=0)
Local a,b,scnt,stp#=2.0/segs,stx#,sty#,x#,y#,u#,v#,v0,v1,v2
Local mesh=CreateMesh( parent )
For scnt=0 To 5
surf= CreateSurface( mesh )
stx = -1 : sty = stx : y = sty
For a=0 To segs
x = stx : v = a / Float(segs)
For b=0 To segs
u = b / Float(segs)
VertexNormal(surf,AddVertex(surf,x,y,1,u,v),0,0,1)
x = x + stp
Next
y = y + stp
Next
For a=0 To segs-1
For b=0 To segs-1
v0 = a*(segs+1)+b : v1 = v0+1
v2 = (a+1)*(segs+1)+b+1 : v3 = v2-1
AddTriangle( surf,v0,v1,v2 )
AddTriangle( surf,v0,v2,v3 )
Next
Next
If scnt<4 Then RotateMesh mesh,0,90,0 ; rotate to side
If scnt=3 Then RotateMesh mesh,90,0,0 ; rotate to top
If scnt>3 Then RotateMesh mesh,180,0,0 ; rotate to bottom
Next
Return mesh
End Function