3d orthographic camera for 2d. Contains some issues for rotation already reported. Beta8 PB6.21 and debugger off needed.
Code: Select all
;VER PB 6.21 Beta 8 OpenGL, probably cross platform, tested on WIN7 64bit
;-CONSTANTS
#MAINDESKTOP_H = 0
#MAINWINDOW_H = 0
#MAINWINDOW_NAME = "Test Application"
#MAINWINDOW_FLAGS = #PB_Window_BorderLess
#MAINWINDOW_RESIZE = 1
#MAINWINDOW_TOPOFFSET = 0
#SCREEN_FLAGS = #PB_Screen_WaitSynchronization
#SCREEN_FRAMERATE = 60
#AUTOSTRETCH_ON = 1
#AUTOSTRETCH_OFF = 0
#MAINLOOP_DELAY = 1
#COMPILER_MINIMUM_VERSION = 621
;-RENDER CONSTANTS
#MAINCAMERA = 1
#FINAL_RENDERCAMERA = 31
#MASK_GENERALPICKMASK=1<<1
#MASK_NOPICKMASK=1<<31
#MASK_MAINCAMERA=1<<1
#MASK_FINAL_RENDERCAMERA=1<<31
#RENDEROBJECT=1 ;RenderTexture, Material, Mesh, Entity shared
#RENDERWIDTH = 1366/2 ;Aspect ratio does not matter here, it can stretch pixels though
#RENDERHEIGHT = 768 ;but not the render
Structure coord3d
x.f
y.f
z.f
EndStructure
Structure coord2d
x.f
y.f
EndStructure
Global midscreen.coord2d
DeclareModule petskii
Declare init()
Declare textout(x,y,text.s,color.i,intensity.i=255)
Declare textoutlined(x,y,text.s,color.i,outlinecolor.i,intensity.i=255)
Declare destroy()
EndDeclareModule
Module petskii
;-HIDDEN VARIABLES/CONSTANTS
#USED_CHARACTERS="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()-_=+[{]};:',<.>/?"+Chr(34)
Global Dim petskiifont(370):Global Dim fontimport.i(370)
;-SUB PROCEDURES
Procedure sub_loadfont()
Protected x.i,i.i,j.i,sprline.a
For i = 1 To Len(#USED_CHARACTERS):fontImport(Asc(Mid(#USED_CHARACTERS,i,1)))=1 : Next i
Restore petskii_font
For x= 1 To 370
If fontimport(x)=1
petskiifont(x)=CreateSprite(-1,8,12,#PB_Sprite_AlphaBlending)
StartDrawing(SpriteOutput(petskiifont(x)))
DrawingMode(#PB_2DDrawing_AllChannels)
For j=0 To 11
Read.a sprline
For i=0 To 7
If sprline&%1 :Plot(i,j,RGBA(255,255,255,255)): Else : Plot(i,j,RGBA(0,0,0,0)) : EndIf
sprline>>1
Next i
Next j
StopDrawing()
ZoomSprite(petskiifont(x),16,24)
EndIf
Next x
EndProcedure
;-PUBLIC PROCEDURES
Procedure init()
sub_loadfont()
EndProcedure
Procedure textout(x,y,text.s,color.i,intensity.i=255) : Protected.i textlength,i,character
textlength.i = Len(text.s)
For i = 1 To textlength.i
character.i = Asc(Mid(text.s,i,1))
If character.i>ArraySize(petskiifont()) : ProcedureReturn #Null : EndIf
If IsSprite(petskiifont(character))
DisplayTransparentSprite(petskiifont(character),(x+((i-1) * 16)),(y),intensity,color.i)
EndIf
Next i
EndProcedure
Procedure textoutlined(x,y,text.s,color.i,outlinecolor.i,intensity=255)
textout(x-2,y,text.s,outlinecolor,intensity)
textout(x+2,y,text.s,outlinecolor,intensity)
textout(x,y-2,text.s,outlinecolor,intensity)
textout(x,y+2,text.s,outlinecolor,intensity)
textout(x,y,text.s,color,intensity)
EndProcedure
Procedure destroy()
Protected i.i
For i = 1 To Len(#USED_CHARACTERS)
If IsSprite(petskiifont(i)) : FreeSprite(petskiifont(i)) : EndIf
Next i
EndProcedure
;-MODULE DATA
DataSection
petskii_font:
Data.a $00,$00,$38,$38,$38,$38,$38,$38,$00,$38,$00,$00,$00,$00,$EE,$EE,$EE,$00,$00,$00,$00,$00,$00,$00,$00,$00,$EE,$EE,$EE,$FF,$EE,$FF,$EE,$EE,$00,$00,$00,$00,$38,$38,$FC,$0E,$7C,$E0,$7E,$38,$00,$00
Data.a $00,$00,$CE,$CE,$EE,$70,$38,$1C,$EE,$E6,$00,$00,$00,$00,$7C,$7C,$EE,$7C,$3C,$EE,$EE,$FC,$00,$00,$00,$00,$E0,$E0,$70,$38,$00,$00,$00,$00,$00,$00,$00,$00,$70,$70,$38,$1C,$1C,$1C,$38,$70,$00,$00
Data.a $00,$00,$1C,$1C,$38,$70,$70,$70,$38,$1C,$00,$00,$00,$00,$00,$00,$EE,$7C,$FF,$7C,$EE,$00,$00,$00,$00,$00,$00,$00,$38,$38,$FE,$38,$38,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$38,$38,$1C,$00
Data.a $00,$00,$00,$00,$00,$00,$FE,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$38,$38,$00,$00,$00,$00,$00,$00,$C0,$E0,$70,$38,$1C,$0E,$00,$00,$00,$00,$7C,$7C,$EE,$FE,$FE,$EE,$EE,$7C,$00,$00
Data.a $00,$00,$38,$38,$38,$3C,$38,$38,$38,$FE,$00,$00,$00,$00,$7C,$7C,$EE,$E0,$70,$1C,$0E,$FE,$00,$00,$00,$00,$7C,$7C,$EE,$E0,$78,$E0,$EE,$7C,$00,$00,$00,$00,$E0,$E0,$F0,$F8,$EE,$FE,$E0,$E0,$00,$00
Data.a $00,$00,$FE,$FE,$0E,$7E,$E0,$E0,$EE,$7C,$00,$00,$00,$00,$7C,$7C,$EE,$0E,$7E,$EE,$EE,$7C,$00,$00,$00,$00,$FE,$FE,$EE,$70,$38,$38,$38,$38,$00,$00,$00,$00,$7C,$7C,$EE,$EE,$7C,$EE,$EE,$7C,$00,$00
Data.a $00,$00,$7C,$7C,$EE,$EE,$FC,$E0,$EE,$7C,$00,$00,$00,$00,$38,$38,$38,$00,$00,$00,$38,$38,$00,$00,$00,$00,$38,$38,$38,$00,$00,$00,$38,$38,$1C,$00,$00,$00,$F0,$F0,$38,$1C,$0E,$1C,$38,$F0,$00,$00
Data.a $00,$00,$00,$00,$00,$FE,$00,$FE,$00,$00,$00,$00,$00,$00,$1E,$1E,$38,$70,$E0,$70,$38,$1E,$00,$00,$00,$00,$7C,$7C,$EE,$E0,$70,$38,$00,$38,$00,$00,$00,$00,$7C,$7C,$EE,$FE,$FE,$0E,$CE,$7C,$00,$00
Data.a $00,$00,$38,$38,$7C,$EE,$FE,$EE,$EE,$EE,$00,$00,$00,$00,$7E,$7E,$EE,$EE,$7E,$EE,$EE,$7E,$00,$00,$00,$00,$7C,$7C,$EE,$0E,$0E,$0E,$EE,$7C,$00,$00,$00,$00,$3E,$3E,$7E,$EE,$EE,$EE,$7E,$3E,$00,$00
Data.a $00,$00,$FE,$FE,$0E,$0E,$3E,$0E,$0E,$FE,$00,$00,$00,$00,$FE,$FE,$0E,$0E,$3E,$0E,$0E,$0E,$00,$00,$00,$00,$7C,$7C,$EE,$0E,$FE,$EE,$EE,$7C,$00,$00,$00,$00,$EE,$EE,$EE,$EE,$FE,$EE,$EE,$EE,$00,$00
Data.a $00,$00,$7C,$7C,$38,$38,$38,$38,$38,$7C,$00,$00,$00,$00,$F8,$F8,$70,$70,$70,$70,$7E,$3C,$00,$00,$00,$00,$EE,$EE,$7E,$3E,$1E,$3E,$7E,$EE,$00,$00,$00,$00,$0E,$0E,$0E,$0E,$0E,$0E,$0E,$FE,$00,$00
Data.a $00,$00,$CE,$CE,$FE,$FE,$FE,$CE,$CE,$CE,$00,$00,$00,$00,$EE,$EE,$FE,$FE,$FE,$FE,$EE,$EE,$00,$00,$00,$00,$7C,$7C,$EE,$EE,$EE,$EE,$EE,$7C,$00,$00,$00,$00,$7E,$7E,$EE,$EE,$7E,$0E,$0E,$0E,$00,$00
Data.a $00,$00,$7C,$7C,$EE,$EE,$EE,$EE,$7C,$F0,$00,$00,$00,$00,$7E,$7E,$EE,$EE,$7E,$3E,$7E,$EE,$00,$00,$00,$00,$7C,$7C,$EE,$0E,$7C,$E0,$EE,$7C,$00,$00,$00,$00,$FE,$FE,$38,$38,$38,$38,$38,$38,$00,$00
Data.a $00,$00,$EE,$EE,$EE,$EE,$EE,$EE,$EE,$7C,$00,$00,$00,$00,$EE,$EE,$EE,$EE,$EE,$EE,$7C,$38,$00,$00,$00,$00,$CE,$CE,$CE,$CE,$FE,$FE,$FE,$CE,$00,$00,$00,$00,$EE,$EE,$EE,$7C,$38,$7C,$EE,$EE,$00,$00
Data.a $00,$00,$EE,$EE,$EE,$EE,$7C,$38,$38,$38,$00,$00,$00,$00,$FE,$FE,$E0,$70,$38,$1C,$0E,$FE,$00,$00,$00,$00,$7C,$7C,$1C,$1C,$1C,$1C,$1C,$7C,$00,$00,$00,$00,$7C,$7C,$70,$70,$70,$70,$70,$7C,$00,$00
Data.a $00,$00,$38,$38,$7C,$FE,$38,$38,$38,$38,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$FF,$00,$00,$00,$00,$00,$00,$00,$7C,$E0,$FC,$EE,$FC,$00,$00,$00,$00,$00,$00,$0E,$0E,$7E,$EE,$EE,$7E,$00,$00
Data.a $00,$00,$00,$00,$00,$7C,$0E,$0E,$0E,$7C,$00,$00,$00,$00,$00,$00,$E0,$E0,$FC,$EE,$EE,$FC,$00,$00,$00,$00,$00,$00,$00,$7C,$EE,$FE,$0E,$7C,$00,$00,$00,$00,$00,$00,$F0,$38,$FC,$38,$38,$38,$00,$00
Data.a $00,$00,$00,$00,$00,$FC,$EE,$EE,$FC,$E0,$7E,$00,$00,$00,$0E,$0E,$0E,$7E,$EE,$EE,$EE,$EE,$00,$00,$00,$00,$38,$38,$00,$3C,$38,$38,$38,$7C,$00,$00,$00,$00,$00,$00,$70,$00,$70,$70,$70,$70,$3C,$00
Data.a $00,$00,$0E,$0E,$0E,$0E,$7E,$3E,$7E,$EE,$00,$00,$00,$00,$3C,$3C,$38,$38,$38,$38,$38,$7C,$00,$00,$00,$00,$00,$00,$00,$EE,$FE,$FE,$FE,$CE,$00,$00,$00,$00,$00,$00,$00,$7E,$EE,$EE,$EE,$EE,$00,$00
Data.a $00,$00,$00,$00,$00,$7C,$EE,$EE,$EE,$7C,$00,$00,$00,$00,$00,$00,$00,$7E,$EE,$EE,$7E,$0E,$0E,$00,$00,$00,$00,$00,$00,$FC,$EE,$EE,$FC,$E0,$E0,$00,$00,$00,$00,$00,$00,$7E,$EE,$0E,$0E,$0E,$00,$00
Data.a $00,$00,$00,$00,$00,$FC,$0E,$7C,$E0,$7E,$00,$00,$00,$00,$00,$00,$38,$FE,$38,$38,$38,$F0,$00,$00,$00,$00,$00,$00,$00,$EE,$EE,$EE,$EE,$FC,$00,$00,$00,$00,$00,$00,$00,$EE,$EE,$EE,$7C,$38,$00,$00
Data.a $00,$00,$00,$00,$00,$CE,$FE,$FE,$FC,$FC,$00,$00,$00,$00,$00,$00,$00,$EE,$7C,$38,$7C,$EE,$00,$00,$00,$00,$00,$00,$00,$EE,$EE,$EE,$FC,$70,$3E,$00,$00,$00,$00,$00,$00,$FE,$70,$38,$1C,$FE,$00,$00
Data.a $00,$00,$F0,$F0,$38,$38,$1E,$38,$38,$F0,$00,$00,$00,$00,$1E,$1E,$38,$38,$F0,$38,$38,$1E,$00,$00
EndDataSection
EndModule
Procedure.f LERP(a.f,b.f,t.f)
ProcedureReturn(((1.0-t.f)*a) + (b*t))
EndProcedure
Procedure.f INVLERP(a.f,b.f,v.f)
If a=b : ProcedureReturn(1) : EndIf
ProcedureReturn((v-a) / (b-a))
EndProcedure
Procedure.f remap(iMin.f,iMAX.f, oMin.f, oMax.f, v.f)
Protected t.f
t.f = INVLERP(iMin,iMAX,v)
ProcedureReturn(LERP(oMin,oMax,t))
EndProcedure
#SOUND_SAMPLE_RATE=8000
#SOUND_BITS_PER_SAMPLE=8
#SOUND_CHANNELS=1
#SOUND_BYTERATE = (#SOUND_SAMPLE_RATE*#SOUND_CHANNELS*#SOUND_BITS_PER_SAMPLE)/8
Procedure snd(frequency.f,length.i, attack,decay,sustain,release ,wf,af,tac,ns.i,vs.f,vd.f)
Protected chunk.l = Int((length/1000)*#SOUND_BYTERATE)
Protected samples.i = Int((length/1000)*#SOUND_SAMPLE_RATE)
Protected headersize.i = 40
Protected result_id.i,i.i,mydata.a,output.i, position.i
Protected fl_variable
Protected *buffer
Protected mastervolume.i=127
*buffer=AllocateMemory(headersize+4+(chunk))
Restore waveheader3
For i= 1 To 40
Read.a mydata.a
PokeA(*buffer+position,mydata.a) : position=position+1
Next i
PokeL(*buffer+position,chunk) : position = position+4
Protected singlewavetime.f = 1.0/frequency
Protected awt.f =1.0/af
Protected samplesperwave.i = Round(#SOUND_SAMPLE_RATE*singlewavetime,#PB_Round_Up)
Protected aspw = Round(#SOUND_SAMPLE_RATE*awt,#PB_Round_Up)
Protected wavecount.i=Round(length/singlewavetime,#PB_Round_Up)
Protected duty.f=0.5
Protected vbtp.f= 0
Protected steps.f,vbtstp.f
steps = #SOUND_SAMPLE_RATE/frequency
vbtstp = #SOUND_SAMPLE_RATE*vs/frequency
Protected capc.i=0
Protected attacksamples.i,decaysamples.i,sustainsamples.i,releasesamples.i,currentvolume.i
attacksamples =remap(1,attack+decay+sustain+release,1,samples,attack)
decaysamples =remap(1,attack+decay+sustain+release,1,samples,attack+decay)
sustainsamples=remap(1,attack+decay+sustain+release,1,samples,attack+decay+sustain)
releasesamples=samples
Protected counter.i, targetperiod.i,apn = 0
counter.i = 0
targetperiod = samplesperwave
For i= 1 To samples
counter.i=counter+1
capc.i=capc.i+1
If capc=tac
capc=0
apn = 1-apn
EndIf
If counter>=targetperiod
counter=0 : duty=duty*-1
If vd>0 And vs>0
vbtp=vbtp+vs
vbtp=((2*3.14)/steps)*i*vs
If apn
targetperiod =Round(aspw*((1.0+(Sin(vbtp)*vd))),#PB_Round_Nearest)
Else
targetperiod =Round(samplesperwave*((1.0+(Sin(vbtp)*vd))),#PB_Round_Nearest)
EndIf
Else
If apn
targetperiod = aspw
Else
targetperiod = samplesperwave
EndIf
EndIf
EndIf
If i<attacksamples
currentvolume =lerp(0,mastervolume,i/attacksamples)
ElseIf i<decaysamples
currentvolume =lerp(mastervolume,mastervolume*0.8,i/decaysamples)
ElseIf i<sustainsamples
currentvolume =mastervolume*0.8
Else
currentvolume =lerp(0,mastervolume,i/releasesamples)
EndIf
output= 127+((currentvolume*duty)+(Random(ns)))
PokeA(*buffer+position,output):position = position+1
Next i
result_id = CatchSound(#PB_Any,*buffer,headersize+4+(chunk))
FreeMemory(*buffer)
ProcedureReturn(result_id)
EndProcedure
;-AUXILIARY PROCEDURES
Procedure sub_checks()
If Int(#PB_Compiler_Version) < #COMPILER_MINIMUM_VERSION
Debug "Please compile with the currently newest beta 8 6.21."
Debug "This snippet uses features presented with that update."
End
EndIf
If #PB_Compiler_Debugger
Debug "Please compile debugger off"
End
EndIf
EndProcedure
;-PROCEDURES
Procedure app_start()
UsePNGImageDecoder()
sub_checks()
ExamineDesktops()
InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()
InitSound()
OpenWindow(#MAINWINDOW_H,0,0,DesktopUnscaledX(DesktopWidth(#MAINDESKTOP_H)),DesktopUnscaledY(DesktopHeight(#MAINDESKTOP_H)),#MAINWINDOW_NAME,#MAINWINDOW_FLAGS)
OpenWindowedScreen(WindowID(#MAINWINDOW_H),0,0,WindowWidth(#MAINWINDOW_H),WindowHeight(#MAINWINDOW_H),#AUTOSTRETCH_ON,0,0,#SCREEN_FLAGS)
SetFrameRate(#SCREEN_FRAMERATE)
midscreen\x=ScreenWidth()/2
midscreen\y=ScreenHeight()/2
petskii::init()
;internal shaders
Add3DArchive(#PB_Compiler_Home+"examples/3d/Data/Main",#PB_3DArchive_FileSystem)
Parse3DScripts()
;shadows and bullet phy
EnableWorldPhysics(#True)
WorldShadows( #PB_Shadow_Additive,50000,RGBA(1,1,100,21))
SetWorldAttribute(#PB_Shadow_FarDistance,50000)
;cameras
CreateCamera(#MAINCAMERA,0,0,100,100,#MASK_MAINCAMERA)
CameraRenderMode(#MAINCAMERA,#PB_Camera_Textured)
CameraProjectionMode(#MAINCAMERA,#PB_Camera_Orthographic)
MoveCamera(#MAINCAMERA,0,-0,-8,#PB_Absolute)
CreateCamera(#FINAL_RENDERCAMERA,0,0,100,100,#MASK_FINAL_RENDERCAMERA)
CameraRenderMode(#FINAL_RENDERCAMERA,#PB_Camera_Textured)
CameraProjectionMode(#FINAL_RENDERCAMERA,#PB_Camera_Perspective)
CameraRange(#FINAL_RENDERCAMERA,0,100000)
MoveCamera(#FINAL_RENDERCAMERA,0,-0,200,#PB_Absolute|#PB_World)
;renderquad
CreateRenderTexture(#RENDEROBJECT,CameraID(#MAINCAMERA),#RENDERWIDTH,#RENDERHEIGHT,#PB_Texture_ManualUpdate)
CreateMaterial(#RENDEROBJECT,TextureID(#RENDEROBJECT))
DisableMaterialLighting(#RENDEROBJECT,#True)
MaterialFilteringMode(#RENDEROBJECT,#PB_Material_None)
CreatePlane(#RENDEROBJECT,(ScreenWidth()/ScreenHeight())*1000,1000,1,1,1,1)
CreateEntity(#RENDEROBJECT,MeshID(#RENDEROBJECT),MaterialID(#RENDEROBJECT),0,0,-1000,#MASK_NOPICKMASK,#MASK_FINAL_RENDERCAMERA)
RotateEntity(#RENDEROBJECT,90,180,0,#PB_Absolute)
SetRenderQueue(EntityID(#RENDEROBJECT),0,0)
Global holeimg = CatchImage(#PB_Any,?hole)
ResizeImage(holeimg,8,8)
Global splatimg = CatchImage(#PB_Any,?bsplat)
ResizeImage(splatimg,8,8)
Global layertexture = CreateTexture(#PB_Any,1024,1024)
StartDrawing(TextureOutput(layertexture))
DrawingMode(#PB_2DDrawing_AllChannels)
Box(0,0,OutputWidth(),OutputHeight(),RGBA(0,0,0,0))
StopDrawing()
;creating the ground
CreateTexture(2,16,16)
CatchImage(2,?ground)
StartDrawing(TextureOutput(2))
DrawingMode(#PB_2DDrawing_AllChannels)
Box(0,0,OutputWidth(),OutputHeight())
DrawAlphaImage(ImageID(2),0,0)
StopDrawing()
CreateMaterial(2,TextureID(2))
AddMaterialLayer(2,TextureID(layertexture),#PB_Material_AlphaBlend)
ScaleMaterial(2,0.01,0.01,0)
MaterialFilteringMode(2,#PB_Material_None)
CreatePlane(2,10240,10240,1,1,1,1)
CreateEntity(2,MeshID(2),MaterialID(2),0,0,0,#MASK_NOPICKMASK,#MASK_MAINCAMERA)
CreateEntityBody(2,#PB_Entity_StaticBody,1,1,1)
MoveCamera(#MAINCAMERA,0,3000,0,#PB_World|#PB_Absolute)
CameraLookAt(#MAINCAMERA,EntityX(2),EntityY(2),EntityZ(2))
;creating the turretbase
#HULL=3
a=3
CreateTexture(a,16,16)
CatchImage(a,?base)
StartDrawing(TextureOutput(a))
DrawingMode(#PB_2DDrawing_AllChannels)
Box(0,0,OutputWidth(),OutputHeight())
DrawAlphaImage(ImageID(a),0,0)
StopDrawing()
CreateMaterial(a,TextureID(a))
SetMaterialAttribute(a,#PB_Material_DepthWrite,#True)
SetMaterialAttribute(a,#PB_Material_AlphaReject,#True)
SetMaterialAttribute(a,#PB_Material_TAM,#PB_Material_ClampTAM)
MaterialFilteringMode(a,#PB_Material_None)
CreateCube(a,100)
CreateEntity(a,MeshID(a),MaterialID(a),0,40,0,#MASK_NOPICKMASK,#MASK_MAINCAMERA)
ScaleEntity(a,1/2,1/1.5,1/1.5)
CreateEntityBody(a,#PB_Entity_BoxBody,1,1,1)
EntityAngularFactor(a,0,1,0)
EntityLinearFactor(a,1,0,1)
;SetEntityAttribute(a,#PB_Entity_MaxVelocity,200)
;creating the actual turret
#TURR=4
a=4
CreateTexture(a,16,16)
CatchImage(a,?turret)
StartDrawing(TextureOutput(a))
DrawingMode(#PB_2DDrawing_AllChannels)
Box(0,0,OutputWidth(),OutputHeight())
DrawAlphaImage(ImageID(a),0,0)
StopDrawing()
CreateMaterial(a,TextureID(a))
SetMaterialAttribute(a,#PB_Material_DepthWrite,#True)
SetMaterialAttribute(a,#PB_Material_AlphaReject,#True)
SetMaterialAttribute(a,#PB_Material_TAM,#PB_Material_ClampTAM)
MaterialFilteringMode(a,#PB_Material_None)
CreateCube(a,80)
CreateEntity(a,MeshID(a),MaterialID(a),0,61,0,#MASK_NOPICKMASK,#MASK_MAINCAMERA)
EntityRenderMode(a,#PB_Shadow_None)
;creating a box
a=5
CreateTexture(a,16,16)
CatchImage(a,?box)
StartDrawing(TextureOutput(a))
DrawingMode(#PB_2DDrawing_AllChannels)
Box(0,0,OutputWidth(),OutputHeight())
DrawAlphaImage(ImageID(a),0,0)
StopDrawing()
CreateMaterial(a,TextureID(a))
SetMaterialAttribute(a,#PB_Material_DepthWrite,#True)
SetMaterialAttribute(a,#PB_Material_AlphaReject,#True)
SetMaterialAttribute(a,#PB_Material_TAM,#PB_Material_ClampTAM)
MaterialFilteringMode(a,#PB_Material_None)
CreateCube(a,40)
For x = 100 To 150
CreateEntity(x,MeshID(a),MaterialID(a),-1000+Random(2000),20,-1000+Random(2000),#MASK_GENERALPICKMASK,#MASK_MAINCAMERA)
CreateEntityBody(x,#PB_Entity_BoxBody,1,1,1) : RotateEntity(x,0,Random(360),0)
EntityAngularFactor(x,0,1,0)
EntityLinearFactor(x,1,0,1)
SetEntityAttribute(x,#PB_Entity_AngularSleeping,1)
SetEntityAttribute(x,#PB_Entity_LinearSleeping,1)
Next x
;creating a walls
a=7
CreateTexture(a,16,16)
CatchImage(a,?wall)
StartDrawing(TextureOutput(a))
DrawingMode(#PB_2DDrawing_AllChannels)
Box(0,0,OutputWidth(),OutputHeight())
DrawAlphaImage(ImageID(a),0,0)
StopDrawing()
CreateMaterial(a,TextureID(a))
SetMaterialAttribute(a,#PB_Material_DepthWrite,#True)
SetMaterialAttribute(a,#PB_Material_AlphaReject,#True)
SetMaterialAttribute(a,#PB_Material_TAM,#PB_Material_ClampTAM)
MaterialFilteringMode(a,#PB_Material_None)
CreateCube(a,220)
For x = 200 To 225
Repeat
tx = Random(4000)-2000
Until Abs(tx)>250
Repeat
tz = Random(4000)-2000
Until Abs(tz)>250
CreateEntity(x,MeshID(a),MaterialID(a),tx,98+x*0.1,tz,#MASK_GENERALPICKMASK,#MASK_MAINCAMERA): RotateEntity(x,0,Random(360),0)
CreateEntityBody(x,#PB_Entity_StaticBody,1,1,1)
Next x
;creating the aim
#AIM=6
a=6
CreateTexture(a,16,16)
CatchImage(a,?cursor)
StartDrawing(TextureOutput(a))
DrawingMode(#PB_2DDrawing_AllChannels)
Box(0,0,OutputWidth(),OutputHeight())
DrawAlphaImage(ImageID(a),0,0)
StopDrawing()
CreateMaterial(a,TextureID(a))
SetMaterialAttribute(a,#PB_Material_DepthWrite,#True)
SetMaterialAttribute(a,#PB_Material_AlphaReject,#True)
SetMaterialAttribute(a,#PB_Material_TAM,#PB_Material_ClampTAM)
MaterialFilteringMode(a,#PB_Material_None)
CreateCube(a,50)
CreateEntity(a,MeshID(a),MaterialID(a),0,300,0,#MASK_NOPICKMASK,#MASK_MAINCAMERA)
EntityRenderMode(a,#PB_Shadow_None)
Global aim.coord3d
aim\x=0 : aim\y=250 : aim\z=0
CreateLight(0,RGB(255,255,255),0,0,0,#PB_Light_Directional)
LightDirection(0,1,-2,1)
WorldDebug(#PB_World_DebugNone)
;Global shot.i=snd(440,100,30,30,100,30,0,440,0,1,0.016,0.8)
Global shot.i=snd(840,100,30,30,100,30,0,440,0,1,0.016,0.8)
SoundVolume(shot,25)
Global empty.i=snd(200,200,30,30,1,300,0,0,0,0,0.0,0)
SoundVolume(empty,25)
Global engine.i=snd(60,20,30,30,1,30,60,60,0,0,0.0,0)
SoundVolume(engine,10)
SetSoundFrequency(engine,5000)
PlaySound(engine,#PB_Sound_Loop)
EndProcedure
#MAXDIST = 1000
Global ammo.i = 999
Procedure app_update()
Protected w_event.i
Repeat
w_event = WindowEvent() : If w_event = #PB_Event_CloseWindow : End : EndIf
Until Not w_event
ExamineKeyboard():ExamineMouse()
aim\x = aim\x+(MouseDeltaX()*0.5)
aim\z = aim\z+(MouseDeltaY()*0.5)
If aim\x>EntityX(#turr)+#MAXDIST : aim\x = EntityX(#turr)+#MAXDIST : EndIf
If aim\x<EntityX(#turr)-#MAXDIST : aim\x = EntityX(#turr)-#MAXDIST : EndIf
If aim\z>EntityZ(#turr)+#MAXDIST : aim\z =EntityZ(#turr)+ #MAXDIST : EndIf
If aim\z<EntityZ(#turr)-#MAXDIST : aim\z = EntityZ(#turr)-#MAXDIST : EndIf
MoveCamera(#MAINCAMERA,CameraX(#MAINCAMERA)*0.9+EntityX(#aim)*0.1,CameraY(#MAINCAMERA),CameraZ(#MAINCAMERA)*0.9+EntityZ(#aim)*0.1,#PB_World|#PB_Absolute)
MoveEntity(#AIM,aim\x,aim\y,aim\z,#PB_Absolute|#PB_World)
EntityLookAt(#TURR,EntityX(#AIM),EntityY(#TURR),EntityZ(#AIM))
If KeyboardPushed(#PB_Key_A) Or KeyboardPushed(#PB_Key_D)
If KeyboardPushed(#PB_Key_A)
RotateEntity(#HULL,0,1,0,#PB_World|#PB_Relative)
EndIf
If KeyboardPushed(#PB_Key_D)
RotateEntity(#HULL,0,-1,0,#PB_World|#PB_Relative)
EndIf
Else
RotateEntity(#HULL,0,0,0,#PB_World|#PB_Relative)
EndIf
If KeyboardPushed(#PB_Key_W) Or KeyboardPushed(#PB_Key_S)
SetSoundFrequency(engine,6000)
If KeyboardPushed(#PB_Key_W)
MoveEntity(#HULL,0,0,-100,#PB_Local|#PB_Relative)
EndIf
If KeyboardPushed(#PB_Key_S)
MoveEntity(#HULL,0,0,100,#PB_Local|#PB_Relative)
EndIf
Else
MoveEntity(#HULL,0,0,0,#PB_Local|#PB_Relative)
SetSoundFrequency(engine,5000)
EndIf
MoveEntity(#TURR,EntityX(#HULL),61,EntityZ(#HULL),#PB_World|#PB_Absolute)
If MouseButton(#PB_MouseButton_Right)
If ammo<1 And SoundStatus(empty)<>#PB_Sound_Playing
PlaySound(empty)
EndIf
If SoundStatus(shot)<>#PB_Sound_Playing And ammo>0: PlaySound(shot)
aoff=Random(10)-5
boff=Random(10)-5
ammo-1
dist.f = Sqr((EntityX(#aim)+aoff-EntityX(#hull)) * (EntityX(#aim)+aoff-EntityX(#hull))+((EntityZ(#aim)+boff-EntityZ(#hull))*(EntityZ(#aim)+boff-EntityZ(#hull))) )
rayhitbool = RayCast(EntityX(#hull),10,EntityZ(#hull),EntityDirectionX(#turr)*dist ,10,EntityDirectionZ(#turr)*dist,#MASK_GENERALPICKMASK)
If rayhitbool
If IsEntity(rayhitbool)
distent.f = Sqr((EntityX(#hull)-EntityX(rayhitbool)) * (EntityX(#hull)-EntityX(rayhitbool))+((EntityZ(#hull)-EntityZ(rayhitbool))*(EntityZ(#hull)-EntityZ(rayhitbool))) )
If rayhitbool<200:distb=25 :Else:distb=100:EndIf
If Abs(distent)<Abs(dist)+distb
CreateLine3D(1000,EntityX(#hull),EntityY(#hull),EntityZ(#hull),RGB(255,0,0),PickX(),PickY(),PickZ(),RGB(255,255,127))
ApplyEntityImpulse(rayhitbool,NormalX()*-50,0,NormalZ()*-50)
hg2=1
Else
CreateLine3D(1000,EntityX(#hull),EntityY(#hull),EntityZ(#hull),RGB(255,0,0),EntityX(#AIM)+aoff,EntityY(#AIM),EntityZ(#AIM)+boff,RGB(255,255,127))
hg=1
EndIf
Else
CreateLine3D(1000,EntityX(#hull),EntityY(#hull),EntityZ(#hull),RGB(255,0,0),EntityX(#AIM)+aoff,EntityY(#AIM),EntityZ(#AIM)+boff,RGB(255,255,127))
hg=1
EndIf
Else
CreateLine3D(1000,EntityX(#hull),EntityY(#hull),EntityZ(#hull),RGB(255,0,0),EntityX(#AIM)+aoff,EntityY(#AIM),EntityZ(#AIM)+boff,RGB(255,255,127))
hg=1
EndIf
EndIf
EndIf
If hg >0
StartDrawing(TextureOutput(layertexture))
DrawingMode(#PB_2DDrawing_AlphaBlend)
DrawAlphaImage(ImageID(holeimg),512-((EntityX(#aim)+aoff)/10),512-(EntityZ(#aim)+boff)/10,128)
StopDrawing()
hg=0
EndIf
If hg2 >0
StartDrawing(TextureOutput(layertexture))
DrawingMode(#PB_2DDrawing_AlphaBlend)
DrawAlphaImage(ImageID(holeimg),512-(PickX()/10),512-PickZ()/10,128)
StopDrawing()
hg2=0
EndIf
UpdateRenderTexture(#RENDEROBJECT)
If IsMesh(1000)
FreeMesh(1000)
EndIf
If IsMesh(1001)
FreeMesh(1001)
EndIf
RenderWorld(60)
petskii::textoutlined(0,30,"AMMO : "+Str(ammo),RGB(150,80,20),RGB(0,0,0))
petskii::textoutlined(0,0,"Controls: W A S D + Mouse + Right Mouse Button",RGB(150,80,20),RGB(0,0,0))
FlipBuffers()
Delay(#MAINLOOP_DELAY)
EndProcedure
;-MAIN PROGRAM PROCEDURE
Procedure main()
app_start()
Repeat
app_update()
Until KeyboardPushed(#PB_Key_Escape)
EndProcedure
;-MAIN PROGRAM
main()
DataSection
ground:
Data.a $89,$50,$4E,$47,$0D,$0A,$1A,$0A,$00,$00,$00,$0D,$49,$48,$44,$52,$00,$00,$00,$10,$00,$00,$00,$10,$08,$06,$00,$00,$00,$1F,$F3,$FF,$61,$00,$00,$00,$5F,$49,$44,$41,$54
Data.a $38,$CB,$63,$30,$36,$36,$FE,$5F,$5E,$5E,$FE,$1F,$44,$13,$C2,$D8,$D4,$31,$10,$A3,$11,$DD,$10,$64,$83,$48,$36,$80,$24,$17,$C0,$6C,$C3,$E7,$45,$06,$52,$9C,$8E,$D7,$00
Data.a $62,$02,$92,$60,$20,$22,$3B,$97,$90,$D3,$E9,$13,$88,$24,$19,$40,$6C,$62,$22,$2A,$0C,$08,$19,$86,$AC,$86,$22,$2F,$80,$0C,$61,$20,$27,$EE,$31,$BC,$80,$4D,$21,$BA,$18
Data.a $2E,$AF,$D1,$3E,$2F,$10,$32,$00,$00,$6E,$B8,$AD,$94,$79,$97,$60,$22,$00,$00,$00,$00,$49,$45,$4E,$44,$AE,$42,$60,$82
base:
Data.a $89,$50,$4E,$47,$0D,$0A,$1A,$0A,$00,$00,$00,$0D,$49,$48,$44,$52,$00,$00,$00,$10,$00,$00,$00,$10,$08,$06,$00,$00,$00,$1F,$F3,$FF,$61,$00,$00,$00,$83,$49,$44,$41,$54
Data.a $38,$CB,$A5,$53,$01,$0A,$00,$21,$08,$CB,$37,$F5,$38,$1F,$E7,$E3,$EE,$2A,$58,$88,$67,$4D,$B8,$60,$60,$A1,$6B,$DA,$6A,$6D,$2C,$11,$79,$26,$7C,$7C,$42,$CC,$5F,$9B,$DE
Data.a $FB,$C2,$8C,$CD,$6C,$41,$55,$D3,$18,$F9,$9B,$04,$81,$27,$98,$05,$19,$3C,$01,$F2,$3F,$0A,$4E,$C5,$00,$55,$E0,$93,$41,$9C,$11,$1C,$15,$A0,$05,$9C,$79,$92,$D2,$0C,$E2
Data.a $ED,$51,$45,$69,$06,$B1,$D8,$93,$94,$14,$54,$08,$E8,$2B,$B0,$16,$A8,$0F,$D8,$10,$4B,$3E,$B8,$3D,$63,$C9,$07,$37,$23,$51,$1F,$30,$2B,$5F,$67,$90,$91,$C4,$CF,$B4,$15
Data.a $FC,$FD,$CE,$2F,$54,$7B,$A2,$54,$36,$A1,$B0,$04,$00,$00,$00,$00,$49,$45,$4E,$44,$AE,$42,$60,$82
turret:
Data.a $89,$50,$4E,$47,$0D,$0A,$1A,$0A,$00,$00,$00,$0D,$49,$48,$44,$52,$00,$00,$00,$10,$00,$00,$00,$10,$08,$06,$00,$00,$00,$1F,$F3,$FF,$61,$00,$00,$00,$26,$49,$44,$41,$54
Data.a $38,$CB,$63,$60,$C0,$03,$18,$19,$19,$FF,$83,$30,$03,$B9,$60,$D4,$80,$81,$36,$00,$A6,$99,$6C,$43,$28,$36,$80,$2A,$61,$30,$0A,$E8,$04,$00,$60,$10,$18,$31,$8C,$83,$71
Data.a $F8,$00,$00,$00,$00,$49,$45,$4E,$44,$AE,$42,$60,$82
wall:
Data.a $89,$50,$4E,$47,$0D,$0A,$1A,$0A,$00,$00,$00,$0D,$49,$48,$44,$52,$00,$00,$00,$10,$00,$00,$00,$10,$08,$06,$00,$00,$00,$1F,$F3,$FF,$61,$00,$00,$00,$29,$49,$44,$41,$54
Data.a $38,$CB,$63,$60,$64,$64,$FC,$4F,$09,$66,$00,$11,$E5,$E5,$E5,$64,$61,$14,$03,$8C,$8D,$8D,$49,$C2,$A3,$06,$8C,$1A,$30,$5C,$0D,$A0,$28,$33,$51,$82,$01,$88,$AC,$9E,$58
Data.a $A1,$88,$0D,$92,$00,$00,$00,$00,$49,$45,$4E,$44,$AE,$42,$60,$82
box:
Data.a $89,$50,$4E,$47,$0D,$0A,$1A,$0A,$00,$00,$00,$0D,$49,$48,$44,$52,$00,$00,$00,$10,$00,$00,$00,$10,$08,$06,$00,$00,$00,$1F,$F3,$FF,$61,$00,$00,$00,$5B,$49,$44,$41,$54
Data.a $38,$CB,$63,$60,$64,$64,$FC,$4F,$09,$66,$00,$11,$69,$2E,$0C,$64,$61,$14,$03,$60,$F4,$DD,$8E,$50,$BC,$18,$59,$2D,$86,$0B,$08,$19,$82,$AC,$06,$C3,$00,$74,$05,$F8,$34
Data.a $23,$F3,$19,$D0,$35,$60,$33,$04,$9F,$18,$03,$36,$1B,$B1,$39,$15,$97,$1A,$06,$42,$4E,$26,$24,$4F,$1B,$03,$28,$F2,$02,$45,$81,$48,$51,$34,$52,$9C,$90,$A8,$92,$94,$C9
Data.a $CE,$4C,$94,$60,$00,$10,$96,$C7,$44,$CF,$DD,$33,$A8,$00,$00,$00,$00,$49,$45,$4E,$44,$AE,$42,$60,$82
cursor:
Data.a $89,$50,$4E,$47,$0D,$0A,$1A,$0A,$00,$00,$00,$0D,$49,$48,$44,$52,$00,$00,$00,$10,$00,$00,$00,$10,$08,$06,$00,$00,$00,$1F,$F3,$FF,$61,$00,$00,$00,$43,$49,$44,$41,$54
Data.a $38,$CB,$63,$60,$00,$02,$46,$46,$C6,$FF,$30,$CC,$40,$00,$60,$A8,$25,$56,$23,$2E,$83,$18,$C8,$D1,$8C,$6C,$08,$E5,$06,$0C,$5E,$80,$EC,$3C,$B2,$9D,$FA,$EE,$5D,$F9,$7F
Data.a $10,$26,$DB,$15,$14,$19,$40,$15,$2F,$D0,$3F,$B4,$07,$26,$25,$52,$9C,$99,$28,$CD,$CE,$00,$56,$9C,$2D,$89,$00,$54,$A3,$09,$00,$00,$00,$00,$49,$45,$4E,$44,$AE,$42,$60
Data.a $82
hole:
Data.a $89,$50,$4E,$47,$0D,$0A,$1A,$0A,$00,$00,$00,$0D,$49,$48,$44,$52,$00,$00,$00,$10,$00,$00,$00,$10,$08,$06,$00,$00,$00,$1F,$F3,$FF,$61,$00,$00,$00,$4D,$49,$44,$41,$54
Data.a $38,$CB,$63,$60,$64,$64,$FC,$CF,$80,$03,$E0,$93,$43,$51,$04,$C2,$E5,$E5,$E5,$FF,$8D,$8D,$8D,$FF,$C3,$F8,$44,$69,$86,$01,$90,$66,$98,$26,$90,$21,$20,$0C,$12,$23,$DA
Data.a $00,$74,$9B,$49,$76,$05,$36,$E7,$83,$F8,$44,$BB,$00,$5D,$23,$49,$5E,$C0,$17,$88,$24,$05,$24,$C9,$D1,$37,$0A,$46,$01,$12,$00,$00,$76,$BB,$38,$E9,$51,$9C,$DC,$DF,$00
Data.a $00,$00,$00,$49,$45,$4E,$44,$AE,$42,$60,$82
bsplat:
Data.a $89,$50,$4E,$47,$0D,$0A,$1A,$0A,$00,$00,$00,$0D,$49,$48,$44,$52,$00,$00,$00,$10,$00,$00,$00,$10,$08,$06,$00,$00,$00,$1F,$F3,$FF,$61,$00,$00,$00,$38,$49,$44,$41,$54
Data.a $38,$CB,$63,$E8,$60,$60,$F8,$0F,$C2,$0C,$40,$80,$CC,$26,$09,$20,$6B,$82,$19,$42,$92,$61,$E8,$9A,$48,$76,$05,$36,$03,$28,$32,$84,$E4,$F0,$A0,$8A,$ED,$F8,$5C,$43,$94
Data.a $ED,$D8,$F8,$64,$45,$E9,$28,$18,$91,$00,$00,$E3,$7D,$3B,$92,$FC,$FB,$7A,$4E,$00,$00,$00,$00,$49,$45,$4E,$44,$AE,$42,$60,$82
EndDataSection
;// 1 channel mono sample rate 8000 8 bit/sample (unsigned byte)
DataSection
Waveheader3:
Data.a $52,$49,$46,$46,$24,$08,$00,$00,$57,$41,$56,$45,$66,$6D,$74,$20,$10,$00,$00,$00,$01,$00,$01,$00,$40,$1F,$00,$00,$40,$1F,$01,$00,$04,$00,$08,$00,$64,$61,$74,$61
EndDataSection