[GAME] - Bug Planet

Advanced game related topics
miso
Enthusiast
Enthusiast
Posts: 466
Joined: Sat Oct 21, 2023 4:06 pm
Location: Hungary

[GAME] - Bug Planet

Post by miso »

1 post long full minigame, 2 good, 1 bad ending. (Hard)
Controls: W, A S, D, E, Leftmouse, Rightmouse.

Code: Select all

;VER PB 6.21 Beta 9 OpenGL prototyping, probably cross platform, tested on WIN7 64bit
#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       = 0
#COMPILER_MINIMUM_VERSION = 621

#MAINCAMERA = 1
#FINAL_RENDERCAMERA = 31
#MASK_GENERALPICKMASK=1<<1
#MASK_NOPICKMASK=1<<31
#MASK_MAINCAMERA=1<<1
#MASK_FINAL_RENDERCAMERA=1<<31
#RENDEROBJECT=1
#RENDERWIDTH  = 640
#RENDERHEIGHT = 480

#GROUND = 2
#BOX = 5
#btex1 = 13
#btex2 = 14
#BUG=15
#RESS=100
#RESE=500
#BGS = 800
#BGE = 999

Global matanim.i
Global tsp.f
Global c1.i =RGB(150,80,20)
Global c2.i =RGB(0,0,0)

Structure coord3d
  x.f
  y.f
  z.f
EndStructure


Structure coord2d
  x.f
  y.f
EndStructure

Global midscreen.coord2d
Global mins.i, seconds.i, score.i

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 cto(x,y,text.s,color.i,outlinecolor.i,intensity.i=255)
  Declare destroy()
EndDeclareModule

Module petskii
  #USED_CHARACTERS="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()-_=+[{]};:',<.>/?"+Chr(34)
  Global Dim petskiifont(370):Global Dim fontimport.i(370)
  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
  
  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 cto(x,y,text.s,color.i,outlinecolor.i,intensity=255)
    textlength.i = Len(text.s)
    x=x-(textlength*16)/2 : y=y-8
    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
  
  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

DeclareModule ticker
  #TICKS_FOREVER = -10
  #MAXIMUM_ALLOWED_TICKERS = 255
  
  Structure tickerstructure
    timeout.i
    lasttick.i
    current_tick_count.i
    target_tick_count.i
    alive.i
  EndStructure

  Declare.i create(ID.i,ticktime_ms.i,number_of_ticks.i=#TICKS_FOREVER)
  Declare.i triggered(ID.i)
  Declare.i kill(ID.i)
EndDeclareModule

Module ticker
  Global Dim tickers.tickerstructure(#MAXIMUM_ALLOWED_TICKERS)
  Procedure.i create(ID.i,ticktime_ms.i,number_of_ticks.i=#TICKS_FOREVER)
    If ID.i>=0 And ID.i<=#MAXIMUM_ALLOWED_TICKERS
      With tickers(ID.i)
        \lasttick.i = ElapsedMilliseconds()
        \timeout.i = ticktime_ms.i
        \current_tick_count.i = 0
        \alive.i = #True
        \target_tick_count = number_of_ticks.i
      EndWith
      ProcedureReturn #True
    EndIf
    ProcedureReturn #False
  EndProcedure
  
  Procedure.i triggered(ID.i)
    If ID.i<0 Or ID.i>#MAXIMUM_ALLOWED_TICKERS
      Debug Str(ID.i) + " not exists, cant be checked"
      ProcedureReturn #False
    EndIf
    If tickers(ID.i)\alive <> #True
      ProcedureReturn #False
    EndIf
    If ElapsedMilliseconds()-tickers(ID.i)\lasttick<tickers(ID.i)\timeout
      ProcedureReturn #False
    EndIf
    tickers(ID.i)\current_tick_count + 1
    tickers(ID.i)\lasttick = ElapsedMilliseconds()
    If tickers(ID.i)\current_tick_count = tickers(ID.i)\target_tick_count
      tickers(ID.i)\alive = #False
    EndIf
    ProcedureReturn #True
  EndProcedure
  
  Procedure.i Kill(ID.i)
    If ID.i<0 Or ID.i>#MAXIMUM_ALLOWED_TICKERS
      ProcedureReturn #False
    EndIf
    tickers(ID.i)\alive = #False
    ProcedureReturn #True
  EndProcedure
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    

  #b_Idle=0
  #b_attack=1
  #b_wonder=2
  #b_guard=3
  
  #WALL = 30
  
  Structure pstruct
    id.i
    armor.i
    ammo.i
    box.i
    dmgmin.i
    dmgmax.i
    spmax.i
    mat.i
    kills.i
    behavior.i
    aggrorange.i
    t.i
    tx.i
    ty.i
    load.i
    fired.i
    collected.i
    boxdestroyed.i
    spentarmor.i
    spentammo.i
    won.i
  EndStructure
  
  Global p.pstruct
  p\ammo=450
  p\armor = 250
  p\box = 0
  p\dmgmin = 1
  p\dmgmax = 3
  p\load = 0
  
  Global bugscount.i = 0
  Global bugswiper.i =#BGS
  Global NewList bugs()
  Global Dim o.pstruct(2000)
  
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

Procedure spawnbug(num,x1,y1,x2,y2,big,behavior)
    count = 0
    For x=#BGS To #BGE
      If Not IsEntity(x)And count<num
        AddElement(bugs()) : bugs()=x : bugscount+1
        CreateEntity(x,MeshID(#box),MaterialID(#btex1),x1+Random(x2-x1),20,y1+Random(y2-y1),#MASK_GENERALPICKMASK,#MASK_MAINCAMERA)
        c=Random(big,0)
        o(x)\t=-1
        If c =1
          o(x)\armor=50
          o(x)\ID=#BUG
          o(x)\spmax=10+Random(20,10)
          f.f=1.5+Random(500)/1000
          ScaleEntity(x,2,2,2)
          o(x)\behavior = behavior
          o(x)\aggrorange=250000+Random(250000)
        Else
          o(x)\armor=6
          o(x)\ID=#BUG
          o(x)\spmax=60+Random(30,10)
          f.f=1.0+Random(100)/1000
          ScaleEntity(x,f,f,f)
          o(x)\behavior = behavior
          o(x)\aggrorange=400000+Random(100000)
        EndIf
        count+1
        EntityRenderMode(x,#PB_Shadow_None)
        CreateEntityBody(x,#PB_Entity_BoxBody,1,1,1)
        EntityAngularFactor(x,0,1,0)
        EntityLinearFactor(x,1,0,1)
        If count=num : x = #BGE : EndIf
      EndIf
    Next x
EndProcedure

Procedure createmat(id.i,*img,size.i)
  CreateTexture(id,size,size)
  CatchImage(id,*img)
  StartDrawing(TextureOutput(id))
  DrawingMode(#PB_2DDrawing_AllChannels)
  Box(0,0,OutputWidth(),OutputHeight())
  DrawAlphaImage(ImageID(id),0,0)
  StopDrawing()
  CreateMaterial(id,TextureID(id))
  MaterialFilteringMode(id,#PB_Material_None)
  FreeImage(id)
EndProcedure

Procedure setmat_basic(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)
EndProcedure

Procedure.i dist(x1,y1,x2,y2)
  Protected retval.i
  retval.i = ((x2-x1)*(x2-x1))+((y2-y1)*(y2-y1))
  ProcedureReturn retval
EndProcedure

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()
  Add3DArchive(#PB_Compiler_Home+"examples/3d/Data/Main",#PB_3DArchive_FileSystem)
  Parse3DScripts()
  
  EnableWorldPhysics(#True)
  WorldShadows( #PB_Shadow_Additive,50000,RGBA(1,1,100,21))
  SetWorldAttribute(#PB_Shadow_FarDistance,50000)
  
  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)
  RotateCamera(#MAINCAMERA,0,180,0)
  
  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)
  
  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 eggdimg = CatchImage(#PB_Any,?eggd)
  ResizeImage(eggdimg,10,10,#PB_Image_Raw)
  Global bugdimg = CatchImage(#PB_Any,?deadbug)
  ResizeImage(bugdimg,8,8,#PB_Image_Raw)
  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()
  
  createmat(#ground,?ground,16)
  AddMaterialLayer(#ground,TextureID(layertexture),#PB_Material_AlphaBlend)
  ScaleMaterial(#GROUND,0.01,0.01,0)
  CreatePlane(#GROUND,10240,10240,1,1,1,1)
  CreateEntity(#GROUND,MeshID(#GROUND),MaterialID(2),0,0,0,#MASK_NOPICKMASK,#MASK_MAINCAMERA)
  CreateEntityBody(#GROUND,#PB_Entity_StaticBody,1,1,1)
  
  MoveCamera(#MAINCAMERA,0,3000,0,#PB_World|#PB_Absolute)
  CameraLookAt(#MAINCAMERA,EntityX(2),EntityY(2),EntityZ(2))
  
  #HULL=3
  a=3
  createmat(a,?base,16)
  setmat_basic(a) 
  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)
  EntityLinearFactor(a,1,0,1)
  #TURR=4
  a=4
  createmat(a,?turret,16)
  setmat_basic(a)
  CreateCube(a,80)
  CreateEntity(a,MeshID(a),MaterialID(a),0,61,0,#MASK_NOPICKMASK,#MASK_MAINCAMERA)
  EntityRenderMode(a,#PB_Shadow_None)
  
  a=8
  #ammopod = 8
  CatchImage(a,?ammopod)
  ResizeImage(a,25,25,#PB_Image_Raw)
  StartDrawing(TextureOutput(layertexture))
  DrawingMode(#PB_2DDrawing_AllChannels)
  DrawAlphaImage(ImageID(a),530,500)
  StopDrawing()
  
  a=20
  #REP = 20
  CatchImage(a,?rep)
  ResizeImage(a,25,25,#PB_Image_Raw)
  StartDrawing(TextureOutput(layertexture))
  DrawingMode(#PB_2DDrawing_AllChannels)
  DrawAlphaImage(ImageID(a),470,500)
  StopDrawing()

  a=21
  #HELI = 21
  CatchImage(a,?heli)
  ResizeImage(a,25,25,#PB_Image_Raw)
  StartDrawing(TextureOutput(layertexture))
  DrawingMode(#PB_2DDrawing_AllChannels)
  DrawAlphaImage(ImageID(a),500,500)
  StopDrawing()
    
  a=8
  #EGG = 8
  createmat(a,?egg,16)
  setmat_basic(a)
  
  a=5
  createmat(a,?box,16)
  setmat_basic(a)
  CreateCube(a,40)
  CatchSprite(a,?box,#PB_Sprite_AlphaBlending) : ZoomSprite(a,64,64)
  
  For x = #RESS To #RESE
      test = Random(4,1)
      If test = 4
        CreateEntity(x,MeshID(a),MaterialID(#BOX),-5000+Random(10000),20,-5000+Random(10000),#MASK_GENERALPICKMASK,#MASK_MAINCAMERA)
        EntityRenderMode(x,#PB_Entity_CastShadow)
        o(x)\id=#BOX
        o(x)\armor=3+Random(3)
        CreateEntityBody(x,#PB_Entity_BoxBody,1,1,10) : RotateEntity(x,0,Random(360),0)
      Else
        CreateEntity(x,MeshID(a),MaterialID(#EGG),-5000+Random(10000),20,-5000+Random(10000),#MASK_GENERALPICKMASK,#MASK_MAINCAMERA)
        ScaleEntity(x,2,2,2)
        EntityRenderMode(x,#PB_Shadow_None)
        o(x)\id=#EGG
        o(x)\armor=10+Random(10)
        CreateEntityBody(x,#PB_Entity_BoxBody,1,1,10) : RotateEntity(x,0,Random(360),0)
      EndIf
      If o(x)\id = #egg
        EntityAngularFactor(x,0,0.025,0)
        EntityLinearFactor(x,0.025,0,0.025)
        SetEntityAttribute(x,#PB_Entity_AngularSleeping,0.1)
        SetEntityAttribute(x,#PB_Entity_LinearSleeping,1)
        SetEntityAttribute(x,#PB_Entity_MaxVelocity,0)
        SetEntityAttribute(x,#PB_Entity_Friction,10)
      Else
        EntityAngularFactor(x,0,0.1,0)
        EntityLinearFactor(x,0.1,0,0.1)
        SetEntityAttribute(x,#PB_Entity_AngularSleeping,10)
        SetEntityAttribute(x,#PB_Entity_LinearSleeping,10)
        SetEntityAttribute(x,#PB_Entity_MaxVelocity,20)
      EndIf
  Next x
  
  a=7
  createmat(a,?wall,16)
  setmat_basic(a)
  
  CreateCube(a,102)
  For x = 2000 To 2020
    Repeat  
      tx = Random(10000)-20000
    Until Abs(tx)>250
    Repeat  
      tz = Random(10000)-20000
    Until Abs(tz)>250
    CreateEntity(x,MeshID(a),MaterialID(a),tx,48+x*0.001,tz,#MASK_GENERALPICKMASK,#MASK_MAINCAMERA): RotateEntity(x,0,Random(360),0)
    ScaleEntity(x,2,1,2)
    CreateEntityBody(x,#PB_Entity_StaticBody,1,1,1) 
    o(x)\id=#WALL
  Next x
  x=226
  CreateEntity(x,MeshID(a),MaterialID(a),tx,58+x*0.1,tz,#MASK_GENERALPICKMASK,#MASK_MAINCAMERA) 
  ScaleEntity(x,100,10,2,#PB_Absolute)
  MoveEntity(x,0,10,5012.5,#PB_World|#PB_Absolute)
  CreateEntityBody(x,#PB_Entity_StaticBody,1,1,1) 
  o(x)\id=#WALL
  
  x=227
  CreateEntity(x,MeshID(a),MaterialID(a),tx,98+x*0.1,tz,#MASK_GENERALPICKMASK,#MASK_MAINCAMERA) 
  ScaleEntity(x,100,10,2,#PB_Absolute)
  MoveEntity(x,0,15,-5012.5,#PB_World|#PB_Absolute)
  CreateEntityBody(x,#PB_Entity_StaticBody,1,1,1) 
  o(x)\id=#WALL
  
  x=228
  CreateEntity(x,MeshID(a),MaterialID(a),tx,98+x*0.1,tz,#MASK_GENERALPICKMASK,#MASK_MAINCAMERA)
  RotateEntity(x,0,90,0)
  ScaleEntity(x,100,10,2,#PB_Absolute)
  MoveEntity(x,-5012.5,20,0,#PB_World|#PB_Absolute)
  CreateEntityBody(x,#PB_Entity_StaticBody,1,1,1) 
  o(x)\id=#WALL
  
  x=229
  CreateEntity(x,MeshID(a),MaterialID(a),tx,98+x*0.1,tz,#MASK_GENERALPICKMASK,#MASK_MAINCAMERA)
  RotateEntity(x,0,90,0)
  ScaleEntity(x,100,10,2,#PB_Absolute)
  MoveEntity(x,5012.5,25,0,#PB_World|#PB_Absolute)
  CreateEntityBody(x,#PB_Entity_StaticBody,1,1,1) 
  o(x)\id=#WALL
  
  #NEST=12
  a=12
  createmat(a,?nest,16)
  setmat_basic(a)
  CreateCube(a,300)
  CreateEntity(a,MeshID(a),MaterialID(a),0,0,0,#MASK_GENERALPICKMASK,#MASK_MAINCAMERA)
  EntityRenderMode(a,#PB_Shadow_None)
  CreateEntityBody(a,#PB_Entity_SphereBody,1,1,1,1,200,200,200) 
  MoveEntity(a,0,-100,4500,#PB_World|#PB_Absolute)
  EntityAngularFactor(a,0,0,0)
  EntityLinearFactor(a,0,0,0)
  o(a)\id=#NEST
  o(a)\armor=1500
  MoveEntity(a,0,0,0,#PB_Local|#PB_Relative)
  UpdateMeshBoundingBox(a)
  
  a=13
  createmat(a,?bug1,16)
  setmat_basic(a)
  
  a=14
  createmat(a,?bug2,16)
  setmat_basic(a)
  
  #AIM=6
  a=6
  createmat(a,?aim,16)
  setmat_basic(a)
  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)
  ticker::create(1,500)
  ticker::create(2,200)
  ticker::create(3,15000)
  ticker::create(4,6000)
  
  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,18)
  SetSoundFrequency(engine,5000)
  PlaySound(engine,#PB_Sound_Loop)
  
  Global pickup.i=snd(200,80,30,30,1,300,1200,120,0,1,1.0,1)
  SoundVolume(pickup,25)
  
  Global eat.i=snd(200,180,30,30,1,3000,1200,1200,100,1,1.0,1)
  SoundVolume(eat,50)
  Global crunch.i=snd(300,80,30,30,1,3000,1200,1200,100,1,1.0,1)
  SoundVolume(crunch,50)
  
  Global bcrunch.i=snd(450,120,10,300,100,30,2500,200,10,1,5.0,0.5)
  SoundVolume(bcrunch,50)
  MoveEntity(#HULL,0,0,tsp,#PB_Local|#PB_Relative)
EndProcedure
#MAXDIST = 1000
Global tsp.f

Procedure splashimage(img,x,y,a)
  StartDrawing(TextureOutput(layertexture))
  DrawingMode(#PB_2DDrawing_AlphaBlend)
  DrawAlphaImage(ImageID(img),x,y,a)
  StopDrawing()
EndProcedure

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
  
  If p\armor>0 And p\won=0
    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.5,0,#PB_World|#PB_Relative)
      EndIf
      
      If KeyboardPushed(#PB_Key_D)
        RotateEntity(#HULL,0,-1.5,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) 
      If KeyboardPushed(#PB_Key_S)
        tsp=tsp*0.97+(100*-0.03)
        If tsp<-60 : tsp = -60 : EndIf
      EndIf

      If KeyboardPushed(#PB_Key_W)
        tsp=tsp*0.95+(100*0.05)
        If tsp>100 : tsp = 100 : EndIf
      EndIf
    Else
      tsp=tsp*0.95
    EndIf

    If tsp>1 Or tsp<-1
      MoveEntity(#HULL,0,0,tsp,#PB_Local|#PB_Relative)
      SetSoundFrequency(engine,5000+Abs(tsp)*10)
    Else
      EntityVelocity(#hull,0,0,0)
    EndIf

    MoveEntity(#TURR,EntityX(#HULL),61,EntityZ(#HULL),#PB_World|#PB_Absolute)
    
    If MouseButton(#PB_MouseButton_Left) Or KeyboardPushed(#PB_Key_E)
      rayhitbool = RayCast(EntityX(#aim),5000,EntityZ(#aim),0 ,-5000,0,#MASK_GENERALPICKMASK)
      If rayhitbool
        If IsEntity(rayhitbool)
          If p\box<5 And o(rayhitbool)\id=#BOX
            If (EntityX(#HULL)-PickX())*(EntityX(#HULL)-PickX())+(EntityZ(#HULL)-PickZ())*(EntityZ(#HULL)-PickZ())<5000
               FreeEntity(rayhitbool)
               p\box+1
               p\collected+1
               PlaySound(pickup)
             EndIf
           ElseIf rayhitbool>=#RESS And rayhitbool<=#RESE And p\box=5
             PlaySound(empty)
          EndIf
        EndIf
      EndIf
      
      If rayhitbool = -1
        If EntityX(#aim)>-100 And EntityX(#aim)<100 And EntityX(#hull)>-100 And EntityX(#hull)<100
          If EntityZ(#aim)>-100 And EntityZ(#aim)<100 And EntityZ(#hull)>-100 And EntityZ(#hull)<100
            If p\box>0 And p\load<50 And ticker::triggered(1)
              p\box-1
              p\load+1
              If p\load=50
                p\won=2
                  For x = 1 To 1000
                    If o(x)\id=#BUG
                      If IsEntity(x)
                        FreeEntity(x)
                      EndIf
                    EndIf
                  Next x
                EndIf

              PlaySound(pickup)
            EndIf
          EndIf
        EndIf
        
        If EntityX(#aim)>184 And EntityX(#aim)<406 And EntityX(#hull)>184 And EntityX(#hull)<406
          If EntityZ(#aim)>-100 And EntityZ(#aim)<100 And EntityZ(#hull)>-100 And EntityZ(#hull)<100
            If p\box>0 And p\armor<450 And ticker::triggered(1)
              p\box-1
              p\armor+25
              If p\armor>450 : p\armor = 450 : EndIf
              p\spentarmor+1
              PlaySound(pickup)
            EndIf
          EndIf
        EndIf

      If EntityX(#aim)>-400 And EntityX(#aim)<-200 And EntityX(#hull)>-400 And EntityX(#hull)<-200
          If EntityZ(#aim)>-100 And EntityZ(#aim)<100 And EntityZ(#hull)>-100 And EntityZ(#hull)<100
            If p\box>0 And p\ammo<999 And ticker::triggered(1)
              p\box-1
              p\ammo+50
              p\spentammo+1
              If p\ammo>999 : p\ammo = 999 : EndIf
              PlaySound(pickup)
            EndIf
          EndIf
        EndIf
        
        
      EndIf
    EndIf
    
    If MouseButton(#PB_MouseButton_Right)
      If p\ammo<1 And SoundStatus(empty)<>#PB_Sound_Playing
        PlaySound(empty) 
      EndIf
      
      If SoundStatus(shot)<>#PB_Sound_Playing And p\ammo>0: PlaySound(shot) 
        aoff=Random(10)-5
        boff=Random(10)-5
        p\fired+1
        p\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<651:distb=25 :Else:distb=100:EndIf
            If Abs(distent)<Abs(dist)+distb
              CreateLine3D(3000,EntityX(#hull),EntityY(#hull),EntityZ(#hull),RGB(255,0,0),PickX(),PickY(),PickZ(),RGB(255,255,127))
              hg2=1
              If rayhitbool<#BGE
                If o(rayhitbool)\id = #box
                  ApplyEntityImpulse(rayhitbool,NormalX()*-50,0,NormalZ()*-50)
                Else
                  ApplyEntityImpulse(rayhitbool,NormalX()*-15,0,NormalZ()*-15)
                EndIf
                
                o(rayhitbool)\armor-(Random(p\dmgmax,p\dmgmin))
                o(rayhitbool)\behavior=#b_attack
                If o(rayhitbool)\armor<1
                  If o(rayhitbool)\id = #box
                    FreeEntity(rayhitbool)
                    PlaySound(bcrunch)
                  ElseIf o(rayhitbool)\id=#nest
                    FreeEntity(rayhitbool)
                    ticker::kill(1):ticker::kill(2):ticker::kill(3)
                    For x = 1 To 1000
                      If o(x)\id=#BUG
                        If IsEntity(x)
                          FreeEntity(x)
                        EndIf
                      EndIf
                    Next x
                    PlaySound(bcrunch)
                    p\won = 1
                  ElseIf o(rayhitbool)\id = #Egg
                    SetEntityMaterial(rayhitbool,MaterialID(#box))
                    EntityRenderMode(rayhitbool,#PB_Entity_CastShadow)
                    StartDrawing(TextureOutput(layertexture))
                    DrawingMode(#PB_2DDrawing_AlphaBlend)
                    DrawAlphaImage(ImageID(eggdimg),506-(EntityX(rayhitbool)/10),506-EntityZ(rayhitbool)/10,156)
                    StopDrawing()
                    o(rayhitbool)\id =#box
                    o(rayhitbool)\armor =8
                    ScaleEntity(rayhitbool,0.5,0.5,0.5)
                    EntityAngularFactor(x,0,1,0)
                    EntityLinearFactor(x,1,0,1)
                    PlaySound(crunch)
                    spawnbug(Random(5,0),PickX()-5,PickZ()-5,PickX()+5,PickZ()+5,0,#b_attack)
                  ElseIf o(rayhitbool)\id = #BUG
                    StartDrawing(TextureOutput(layertexture))
                    DrawingMode(#PB_2DDrawing_AlphaBlend)
                    DrawAlphaImage(ImageID(bugdimg),506-(EntityX(rayhitbool)/10),506-EntityZ(rayhitbool)/10,156)
                    StopDrawing()
                    PlaySound(crunch)
                    FreeEntity(rayhitbool)
                    bugscount-1
                    p\kills+1
                  EndIf
                  
                EndIf
              EndIf
            Else
              CreateLine3D(3000,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(3000,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(3000,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
      splashimage(holeimg,512-((EntityX(#aim)+aoff)/10),512-(EntityZ(#aim)+boff)/10,128)
      hg=0
    EndIf
      
    If hg2 >0
      If o(rayhitbool)\id=#EGG Or o(rayhitbool)\id=#BUG Or o(rayhitbool)\id=#Nest
        splashimage(splatimg,510-(EntityX(rayhitbool)/10),510-EntityZ(rayhitbool)/10,128)
      Else
        splashimage(holeimg,512-(PickX()/10),512-PickZ()/10,128)
      EndIf
      hg2=0
    EndIf
  Else
    EntityVelocity(#hull,0,0,0)
    EntityAngularFactor(#hull,0,0,0)
    MoveEntity(#TURR,EntityX(#HULL),61,EntityZ(#HULL),#PB_World|#PB_Absolute)
    MoveCamera(#MAINCAMERA,EntityX(#HULL),CameraY(#MAINCAMERA),EntityZ(#HULL),#PB_World|#PB_Absolute)
    StopSound(engine)
EndIf




If ticker::triggered(4) 
  If o(#NEST)\armor<1000
    spawnbug(1,0,4550,1,4551,1,#b_attack)
  EndIf
  If o(#NEST)\armor<500
    spawnbug(5,3,4550,1,4551,0,#b_attack)
  EndIf
  If p\ammo>500 And p\load>25
    spawnbug(5,3,4550,1,4551,1,#b_attack)
  EndIf
EndIf


  
  
  

If ticker::triggered(3) 
  If bugscount=0
    If killcount<200
      spawnbug(Random(10,5),0,4550,1,4551,0,#b_guard)
      spawnbug(Random(10,5),0,4550,1,4551,0,#b_wonder)
    Else
      spawnbug(Random(5,1),0,4550,1,4551,10,#b_guard)
      spawnbug(Random(10,5),0,4550,1,4551,10,#b_wonder)
    EndIf
  ElseIf bugscount<50
      If killcount<200
        spawnbug(Random(6,2),0,4550,1,4551,15,#b_wonder)
      Else
        spawnbug(Random(5,1),0,4550,1,4551,5,#b_wonder)
      EndIf
  ElseIf bugscount>=50
    If killcount<500
      spawnbug(Random(8,3),0,4550,1,4551,0,#b_attack)
    Else
      spawnbug(Random(20,5),0,4550,1,4551,10,#b_attack)
      spawnbug(Random(20,5),0,4550,1,4551,10,#b_wonder)
      spawnbug(Random(1,1),0,4550,1,4551,2,#b_guard)
    EndIf
  EndIf
EndIf




For z=1 To 2
  If bugswiper>#BGE : bugswiper = #BGS : EndIf : x=bugswiper
  If IsEntity(x) And o(x)\id=#bug
    If o(x)\behavior = #b_wonder
      If o(x)\t = -1 
        o(x)\t = 0 : o(x)\tx = Random(10000)-5000 : o(x)\ty = Random(10000)-5000
      Else
        If dist(EntityX(x),EntityZ(x),o(x)\tx,o(x)\ty)<10000
          o(x)\t = -1
        EndIf
        If dist(EntityX(x),EntityZ(x),EntityX(#HULL),EntityZ(#HULL))<o(x)\aggrorange
          o(x)\behavior = #b_attack
          If SoundStatus(eat)=#PB_Sound_Stopped:PlaySound(eat):EndIf
        EndIf
      EndIf
    EndIf
    If o(x)\behavior = #b_idle
      If dist(EntityX(x),EntityZ(x),EntityX(#HULL),EntityZ(#HULL))<o(x)\aggrorange
        o(x)\behavior = #b_attack
        If SoundStatus(eat)=#PB_Sound_Stopped:PlaySound(eat):EndIf
      EndIf
    EndIf
    
    If o(x)\behavior = #b_guard
      If dist(EntityX(x),EntityZ(x),EntityX(#HULL),EntityZ(#HULL))<o(x)\aggrorange+500000
        o(x)\behavior = #b_attack
        If SoundStatus(eat)=#PB_Sound_Stopped:PlaySound(eat):EndIf
      EndIf
    EndIf
  EndIf
  bugswiper+1
Next

ForEach bugs()
  If IsEntity(bugs())
    x=bugs()
    If o(x)\behavior = #b_attack
      EntityLookAt(x,EntityX(#hull),20,EntityZ(#hull))
      MoveEntity(x,0,0,-o(x)\spmax,#PB_Local|#PB_Relative)
    ElseIf o(x)\behavior = #b_wonder
      EntityLookAt(x,o(x)\tx,20,o(x)\ty)
      MoveEntity(x,0,0,-o(x)\spmax/2,#PB_Local|#PB_Relative)
    ElseIf o(x)\behavior = #b_guard
      EntityLookAt(x,o(x)\tx,20,o(x)\ty)
      MoveEntity(x,0,0,0,#PB_Local|#PB_Relative)
    Else
      EntityLookAt(x,0,20,0)
      MoveEntity(x,0,0,0,#PB_Local|#PB_Relative)
    EndIf
    If EntityCollide(x,#HULL)
      o(x)\behavior = #b_attack
      p\armor-Random(5,1)
      If SoundStatus(eat)=#PB_Sound_Stopped
        PlaySound(eat)
      EndIf
    EndIf
  Else
    DeleteElement(bugs())
  EndIf
Next




If ticker::triggered(2)
    matanim=1-matanim
    For x=#BGS To #BGE
      If IsEntity(x)
        If matanim = 1
          SetEntityMaterial(x,MaterialID(#btex1))
        Else
          SetEntityMaterial(x,MaterialID(#btex2))
        EndIf
      EndIf
    Next x
  EndIf
    
  UpdateRenderTexture(#RENDEROBJECT)
  
  
  If IsMesh(3000)
    FreeMesh(3000)
  EndIf
  
  If IsMesh(3001)
    FreeMesh(3001)
  EndIf
  RenderWorld(60)
  
  If EntityX(#hull)>-400 And EntityX(#hull)<406
    If EntityZ(#hull)>-100 And EntityZ(#hull)<100
      If EntityX(#hull)>-400 And EntityX(#hull)<-200
        petskii::cto(ScreenWidth()/2,ScreenHeight()/2+50,"Exchange 1 crate for 50 AMMUNITION.",c1,c2)
      EndIf
      
      If EntityX(#hull)>-100 And EntityX(#hull)<100
        petskii::cto(ScreenWidth()/2,ScreenHeight()/2+50,"Load 50 crates to Helipad to WIN.",c1,c2)
      EndIf
      If EntityX(#hull)>200 And EntityX(#hull)<400
        petskii::cto(ScreenWidth()/2,ScreenHeight()/2+50,"Exchange 1 crate for 25 ARMOR.",c1,c2)
      EndIf
    EndIf
  EndIf
   
  If p\won = 1
    c3=RGB(0,255,0)
    petskii::cto(ScreenWidth()/2,100,"TRIUMPHED (WIN)",c3,c2)
    petskii::cto(ScreenWidth()/2,150,"You fired "+Str(p\fired)+" shots.",c3,c2)
    petskii::cto(ScreenWidth()/2,180,"You killed "+Str(p\kills)+" bugs.",c3,c2)
    petskii::cto(ScreenWidth()/2,210,"You accidentally destroyed "+Str(p\boxdestroyed)+" crates.",c3,c2)
    petskii::cto(ScreenWidth()/2,240,"You collected "+Str(p\collected)+" crates,",c3,c2)
    petskii::cto(ScreenWidth()/2,270,"You uploaded "+Str(p\load)+" crates.",c3,c2)
    petskii::cto(ScreenWidth()/2,300,"You spent "+Str(p\spentarmor)+" crates on armor and "+Str(p\spentammo)+" on ammo.",c3,c2)
    If o(12)\armor>0
      petskii::cto(ScreenWidth()/2,330,"The Nest has been destroyed.",c3,c2)
    EndIf
    If mins = 0 And seconds = 0
      mins = (ElapsedMilliseconds()/1000)/60
      seconds = Mod(ElapsedMilliseconds()/1000,60)
      score = 5000+(p\kills*8) + p\fired -(p\boxdestroyed*10) + p\collected*10 + (p\load*50)-p\spentarmor-p\spentammo-o(12)\armor
    EndIf
    petskii::cto(ScreenWidth()/2,380,"You survived "+Str(mins)+" minutes and "+Str(seconds)+" seconds.",c3,c2)
    petskii::cto(ScreenWidth()/2,410,"Your Score is "+Str(score)+".",c3,c2)
  EndIf
  If p\won = 2
    c3=RGB(255,255,0)
    petskii::cto(ScreenWidth()/2,100,"COLLECTED (WIN)",c3,c2)
    petskii::cto(ScreenWidth()/2,150,"You fired "+Str(p\fired)+" shots.",c3,c2)
    petskii::cto(ScreenWidth()/2,180,"You killed "+Str(p\kills)+" bugs.",c3,c2)
    petskii::cto(ScreenWidth()/2,210,"You accidentally destroyed "+Str(p\boxdestroyed)+" crates.",c3,c2)
    petskii::cto(ScreenWidth()/2,240,"You collected "+Str(p\collected)+" crates,",c3,c2)
    petskii::cto(ScreenWidth()/2,270,"You uploaded "+Str(p\load)+" crates.",c3,c2)
    petskii::cto(ScreenWidth()/2,300,"You spent "+Str(p\spentarmor)+" crates on armor and "+Str(p\spentammo)+" on ammo.",c3,c2)
    If o(12)\armor>0
      petskii::cto(ScreenWidth()/2,330,"The Nest has not been destroyed.",RGB(255,0,0),c2)
    EndIf
    If mins = 0 And seconds = 0
      mins = (ElapsedMilliseconds()/1000)/60
      seconds = Mod(ElapsedMilliseconds()/1000,60)
      score = 5000+(p\kills*8) + p\fired -(p\boxdestroyed*10) + p\collected*10 + (p\load*50)-p\spentarmor-p\spentammo-o(12)\armor
    EndIf
    petskii::cto(ScreenWidth()/2,380,"You survived "+Str(mins)+" minutes and "+Str(seconds)+" seconds.",c3,c2)
    petskii::cto(ScreenWidth()/2,410,"Your Score is "+Str(score)+".",c3,c2)
  EndIf
  
  If p\armor<=0 And p\won=0
    p\armor = 0
    c3=RGB(255,0,0)
    petskii::cto(ScreenWidth()/2,100,"DEVOURED",c3,c2)
    petskii::cto(ScreenWidth()/2,150,"You fired "+Str(p\fired)+" shots.",c3,c2)
    petskii::cto(ScreenWidth()/2,180,"You killed "+Str(p\kills)+" bugs.",c3,c2)
    petskii::cto(ScreenWidth()/2,210,"You accidentally destroyed "+Str(p\boxdestroyed)+" crates.",c3,c2)
    petskii::cto(ScreenWidth()/2,240,"You collected "+Str(p\collected)+" crates,",c3,c2)
    petskii::cto(ScreenWidth()/2,270,"You uploaded "+Str(p\load)+" crates.",c3,c2)
    petskii::cto(ScreenWidth()/2,300,"You spent "+Str(p\spentarmor)+" crates on armor and "+Str(p\spentammo)+" on ammo.",c3,c2)
    If o(12)\armor>0
      petskii::cto(ScreenWidth()/2,330,"The nest has not been destroyed.",c3,c2)
    EndIf
    If mins = 0 And seconds = 0
      mins = (ElapsedMilliseconds()/1000)/60
      seconds = Mod(ElapsedMilliseconds()/1000,60)
      score = (p\kills*8) + p\fired -(p\boxdestroyed*10) + p\collected*10 + (p\load*50)-p\spentarmor-p\spentammo-o(12)\armor
    EndIf
    petskii::cto(ScreenWidth()/2,380,"You survived "+Str(mins)+" minutes and "+Str(seconds)+" seconds.",c3,c2)
    petskii::cto(ScreenWidth()/2,410,"Your Score is "+Str(score)+".",c3,c2)
  Else
    petskii::textoutlined(0,0,"NEST HEALTH : "+Str(o(12)\armor)+"/1500",c1,c2)
    petskii::textoutlined(0,30,"AMMO : "+Str(p\ammo),c1,c2)
    petskii::textoutlined(0,60,"ARMOR : "+Str(p\armor),c1,c2)
    petskii::textoutlined(0,90,"LOAD : "+Str(p\load)+"/50",c1,c2)
  EndIf
  For x = 5 To 1 Step -1
    If x<=p\box
      DisplayTransparentSprite(#box,ScreenWidth()-480+(x*80),0,255)
    Else
      DisplayTransparentSprite(#box,ScreenWidth()-480+(x*80),0,128)
    EndIf
  Next x
  FlipBuffers()
  Delay(#MAINLOOP_DELAY)
EndProcedure

Procedure main()
  app_start()
  Repeat
    app_update()
  Until KeyboardPushed(#PB_Key_Escape)
EndProcedure

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
aim:
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
ammopod:
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,$80,$02,$46,$46,$C6,$FF,$A4,$60,$06,$64,$00,$12,$D8,$BD,$7B,$37,$49,$18,$6E,$08,$39,$9A,$51,$0C,$81,$19,$50,$5E,$5E,$0E,$C6,$F8,$D8,$B4,$35,$C0,$D8
Data.a $D8,$18,$8C,$F1,$B1,$47,$0D,$A0,$C0,$00,$E4,$14,$88,$D3,$00,$42,$09,$06,$99,$26,$CB,$00,$DA,$B9,$80,$E2,$CC,$44,$69,$76,$06,$00,$AB,$1B,$41,$63,$3C,$CF,$AC,$CB,$00
Data.a $00,$00,$00,$49,$45,$4E,$44,$AE,$42,$60,$82
egg:
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,$88,$49,$44,$41,$54
Data.a $38,$CB,$B5,$93,$8B,$09,$00,$21,$0C,$43,$75,$26,$87,$73,$38,$87,$BB,$A3,$42,$24,$A4,$B5,$CA,$C1,$15,$8A,$1F,$C8,$33,$95,$B6,$94,$BF,$A2,$D6,$FA,$20,$3F,$09,$5B,$6B
Data.a $2B,$AF,$41,$2C,$B4,$E8,$BD,$3B,$D0,$15,$C0,$84,$1C,$38,$A7,$10,$88,$C7,$18,$33,$55,$8C,$FB,$10,$02,$B1,$0A,$18,$82,$33,$CA,$5A,$90,$48,$0C,$00,$84,$0C,$73,$90,$A8
Data.a $6E,$76,$81,$BD,$AE,$0E,$90,$39,$50,$F0,$D1,$01,$BF,$1C,$95,$E0,$3E,$92,$5D,$B0,$40,$A1,$00,$6F,$01,$6A,$79,$17,$61,$2F,$70,$17,$EE,$3E,$CE,$D6,$B4,$1B,$75,$0E,$50
Data.a $EF,$B1,$0B,$B3,$49,$3C,$4D,$E5,$0B,$14,$A4,$B1,$9C,$BF,$6A,$0C,$CE,$00,$00,$00,$00,$49,$45,$4E,$44,$AE,$42,$60,$82
eggd:
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,$A4,$49,$44,$41,$54
Data.a $38,$CB,$8D,$93,$8B,$09,$00,$21,$0C,$43,$75,$26,$87,$73,$38,$87,$BB,$23,$C2,$83,$5C,$AF,$7E,$02,$A2,$62,$4D,$63,$5A,$4B,$B9,$40,$6B,$ED,$11,$B6,$41,$B5,$D6,$19,$30
Data.a $C6,$78,$32,$02,$DF,$67,$31,$29,$21,$A4,$57,$67,$92,$48,$26,$1D,$82,$18,$C8,$59,$4A,$EE,$04,$1A,$92,$CA,$7C,$CC,$8E,$82,$DE,$FB,$BC,$A0,$B5,$66,$ED,$35,$8E,$26,$7A
Data.a $16,$08,$04,$2E,$6F,$8D,$53,$90,$AF,$B9,$0C,$50,$82,$F4,$B4,$AC,$FE,$36,$CF,$0A,$48,$12,$4B,$5A,$32,$D7,$21,$88,$0A,$E2,$33,$3E,$2A,$5C,$01,$66,$6A,$66,$0D,$BC,$E9
Data.a $52,$63,$91,$EA,$EE,$BB,$47,$4B,$13,$3D,$08,$66,$24,$C7,$0A,$2D,$4B,$E8,$32,$E3,$1F,$59,$FD,$9D,$5F,$33,$79,$CD,$63,$DB,$1E,$9B,$E9,$2A,$53,$C0,$0B,$4C,$01,$22,$3E
Data.a $EB,$4B,$38,$B0,$00,$00,$00,$00,$49,$45,$4E,$44,$AE,$42,$60,$82
bug1:
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,$7D,$49,$44,$41,$54
Data.a $38,$CB,$63,$60,$C0,$02,$18,$19,$19,$FF,$E3,$E3,$E3,$05,$20,$C5,$FF,$CB,$CB,$FF,$C3,$34,$A1,$F3,$B1,$6A,$C0,$66,$63,$9A,$0B,$03,$1C,$63,$93,$47,$11,$C3,$66,$08,$48
Data.a $E3,$DD,$8E,$50,$B0,$01,$84,$2C,$C4,$2A,$81,$EC,$02,$82,$9A,$D1,$15,$20,$6B,$46,$F6,$06,$51,$81,$89,$CD,$10,$A2,$35,$A3,$3B,$1D,$16,$06,$E8,$5E,$C1,$6B,$33,$3E,$17
Data.a $10,$15,$80,$84,$5C,$40,$30,$0A,$89,$09,$03,$82,$2E,$C1,$E6,$02,$A2,$A3,$10,$DD,$1B,$78,$9D,$8F,$2F,$C3,$E0,$0A,$7D,$A2,$0D,$80,$19,$42,$8C,$3A,$8A,$00,$00,$EB,$05
Data.a $9B,$3C,$30,$13,$76,$9B,$00,$00,$00,$00,$49,$45,$4E,$44,$AE,$42,$60,$82
bug2:
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,$81,$49,$44,$41,$54
Data.a $38,$CB,$A5,$52,$C1,$0D,$80,$30,$08,$84,$DD,$5C,$C1,$15,$5C,$A1,$2B,$B8,$A4,$B3,$D4,$60,$82,$39,$09,$D4,$AB,$5E,$C2,$83,$96,$3B,$0E,$82,$48,$02,$55,$ED,$A3,$7C,$08
Data.a $2B,$EE,$AD,$75,$27,$C5,$9C,$16,$D9,$16,$B9,$63,$8A,$EC,$30,$E2,$B1,$AF,$97,$80,$7C,$01,$3A,$F8,$45,$A6,$45,$6C,$4E,$8C,$B8,$03,$8C,$92,$58,$75,$47,$17,$A5,$10,$DA
Data.a $77,$07,$BE,$44,$CF,$E9,$11,$B2,$EE,$C3,$CE,$F8,$C8,$38,$78,$88,$64,$67,$5B,$39,$A0,$CE,$1B,$05,$DC,$01,$7D,$8D,$71,$94,$78,$03,$AF,$22,$B1,$20,$6E,$7E,$5A,$80,$F9
Data.a $3F,$01,$DC,$74,$90,$72,$05,$16,$E0,$DE,$00,$00,$00,$00,$49,$45,$4E,$44,$AE,$42,$60,$82
deadbug:
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,$7D,$49,$44,$41,$54
Data.a $38,$CB,$9D,$93,$D1,$0D,$80,$30,$08,$44,$61,$37,$67,$71,$85,$AE,$E0,$D6,$35,$7C,$60,$F0,$42,$F5,$29,$5F,$A6,$1E,$AF,$07,$B9,$9A,$81,$3A,$CC,$E6,$AB,$68,$DF,$80,$A8
Data.a $E8,$6E,$FA,$AE,$79,$8E,$81,$80,$ED,$0D,$15,$18,$DF,$75,$04,$77,$9F,$18,$12,$8D,$0A,$6C,$F7,$51,$A9,$29,$C8,$C6,$76,$66,$52,$01,$D5,$DB,$D1,$18,$EA,$46,$21,$F1,$1F
Data.a $ED,$41,$5D,$74,$4E,$AE,$B3,$A7,$A0,$04,$24,$9D,$A0,$60,$A9,$C5,$CE,$05,$4A,$26,$1D,$63,$99,$7B,$75,$52,$01,$78,$89,$9F,$E2,$4B,$5F,$E1,$EF,$60,$AD,$EA,$04,$78,$05
Data.a $5F,$7C,$02,$34,$D9,$67,$00,$00,$00,$00,$49,$45,$4E,$44,$AE,$42,$60,$82
nest:
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,$95,$49,$44,$41,$54
Data.a $38,$CB,$95,$53,$09,$0E,$80,$30,$08,$63,$6F,$DA,$17,$7C,$8B,$5F,$D8,$F3,$67,$30,$A9,$E9,$2A,$E0,$24,$21,$C8,$5C,$29,$D7,$CC,$44,$5A,$6B,$F3,$3C,$6C,$F6,$DE,$17,$0B
Data.a $B5,$4A,$00,$1E,$63,$DC,$16,$3E,$14,$7E,$08,$E6,$0B,$0C,$8C,$BE,$DD,$86,$CC,$60,$77,$DF,$D5,$D3,$67,$AB,$01,$1F,$66,$FC,$C0,$C5,$48,$39,$48,$18,$40,$D9,$AB,$20,$DC
Data.a $58,$E3,$4E,$57,$60,$0E,$B2,$64,$B1,$CB,$AE,$25,$82,$D8,$F8,$E0,$4F,$06,$F0,$4D,$E7,$BC,$93,$01,$97,$BD,$DD,$C4,$68,$A4,$CB,$24,$AA,$46,$6A,$ED,$AF,$B5,$E6,$C3,$6A
Data.a $99,$CA,$75,$46,$16,$BA,$95,$D9,$4A,$97,$6F,$81,$67,$9D,$D6,$9D,$89,$96,$F3,$05,$BC,$00,$A1,$34,$23,$9B,$6A,$83,$C8,$21,$00,$00,$00,$00,$49,$45,$4E,$44,$AE,$42,$60
Data.a $82
rep:
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,$BD,$93,$51,$0A,$00,$20,$08,$43,$F5,$D4,$1E,$CE,$C3,$15,$45,$85,$1F,$6A,$93,$20,$61,$24,$C1,$1E,$53,$90,$68,$15,$33,$B7,$8A,$C8,$D6,$F8,$50,$D5,$92,$0E,$04
Data.a $31,$8B,$C8,$94,$0B,$41,$01,$5E,$FF,$07,$B0,$E3,$5B,$C1,$80,$C8,$08,$01,$6E,$E6,$14,$80,$98,$5D,$40,$36,$2F,$0C,$88,$B6,$ED,$25,$2D,$01,$EC,$0B,$EF,$A0,$9C,$20,$9B
Data.a $35,$4C,$F0,$7C,$4C,$AF,$E7,$DC,$01,$9F,$A3,$6B,$FF,$D7,$FF,$9D,$8F,$00,$00,$00,$00,$49,$45,$4E,$44,$AE,$42,$60,$82
heli:
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,$57,$49,$44,$41,$54
Data.a $38,$CB,$63,$60,$80,$02,$46,$46,$C6,$FF,$A4,$60,$06,$64,$00,$12,$D8,$BD,$7B,$37,$49,$18,$6E,$08,$36,$CD,$E5,$E5,$E5,$58,$31,$56,$43,$90,$0D,$C0,$A5,$11,$97,$41,$58
Data.a $0D,$80,$01,$74,$4D,$C8,$E2,$58,$0D,$C0,$A6,$10,$97,$01,$30,$43,$68,$6B,$00,$2E,$40,$3F,$03,$E8,$1F,$06,$14,$47,$23,$55,$12,$12,$59,$49,$99,$E2,$CC,$44,$69,$76,$06
Data.a $00,$FE,$37,$75,$77,$2B,$A4,$71,$D7,$00,$00,$00,$00,$49,$45,$4E,$44,$AE,$42,$60,$82
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
User avatar
pf shadoko
Enthusiast
Enthusiast
Posts: 386
Joined: Thu Jul 09, 2015 9:07 am

Re: [GAME] - Bug Planet

Post by pf shadoko »

it's great
i've been playing for a while
i'm waiting for the real 3D version!
miso
Enthusiast
Enthusiast
Posts: 466
Joined: Sat Oct 21, 2023 4:06 pm
Location: Hungary

Re: [GAME] - Bug Planet

Post by miso »

Thank you for trying out this! ;) (I might challenge myself with a one post long 3D version one day.)
User avatar
minimy
Enthusiast
Enthusiast
Posts: 616
Joined: Mon Jul 08, 2013 8:43 pm
Location: off world

Re: [GAME] - Bug Planet

Post by minimy »

Wow miso, very nice game! LOL very fun. Remember me the game ant attack in zx spectrum.
Another good demo to learn a little more.
Thanks for share!, go for any coins to play a little more :lol:
If translation=Error: reply="Sorry, Im Spanish": Endif
User avatar
IceSoft
Addict
Addict
Posts: 1694
Joined: Thu Jun 24, 2004 8:51 am
Location: Germany

Re: [GAME] - Bug Planet

Post by IceSoft »

I like it too.
Nice idea.
Belive! C++ version of Puzzle of Mystralia
Bug Planet
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
User avatar
IceSoft
Addict
Addict
Posts: 1694
Joined: Thu Jun 24, 2004 8:51 am
Location: Germany

Re: [GAME] - Bug Planet

Post by IceSoft »

@miso
which tool have you used for creating the data from an image?
Belive! C++ version of Puzzle of Mystralia
Bug Planet
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
miso
Enthusiast
Enthusiast
Posts: 466
Joined: Sat Oct 21, 2023 4:06 pm
Location: Hungary

Re: [GAME] - Bug Planet

Post by miso »

Hello IceSoft!

I wrote a small tool for that. I already shared the code here:

viewtopic.php?t=86453
User avatar
IceSoft
Addict
Addict
Posts: 1694
Joined: Thu Jun 24, 2004 8:51 am
Location: Germany

Re: [GAME] - Bug Planet

Post by IceSoft »

miso wrote: Tue Aug 05, 2025 10:30 am Hello IceSoft!
I wrote a small tool for that. I already shared the code here:
viewtopic.php?t=86453
@miso
Thanks, very usefull!

About Bug Planet,
Is it ok when I create an own version/fork of your "Bug Planet" which some improvements?
I will use an own treat because i have the full control on the first entry have (for edit with the latest source version from me)
Belive! C++ version of Puzzle of Mystralia
Bug Planet
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
miso
Enthusiast
Enthusiast
Posts: 466
Joined: Sat Oct 21, 2023 4:06 pm
Location: Hungary

Re: [GAME] - Bug Planet

Post by miso »

@Icesoft
Sure ;)
You are allowed to do anything with it. ;)
User avatar
IceSoft
Addict
Addict
Posts: 1694
Joined: Thu Jun 24, 2004 8:51 am
Location: Germany

Re: [GAME] - Bug Planet

Post by IceSoft »

miso wrote: Tue Aug 05, 2025 4:52 pm @Icesoft
Sure ;)
You are allowed to do anything with it. ;)
Great! Thanks.
Belive! C++ version of Puzzle of Mystralia
Bug Planet
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
SMaag
Enthusiast
Enthusiast
Posts: 324
Joined: Sat Jan 14, 2023 6:55 pm
Location: Bavaria/Germany

Re: [GAME] - Bug Planet

Post by SMaag »

I'm not that gamer. Maybe because of that I do not understand what to do!
What's the gooal of that game!
miso
Enthusiast
Enthusiast
Posts: 466
Joined: Sat Oct 21, 2023 4:06 pm
Location: Hungary

Re: [GAME] - Bug Planet

Post by miso »

Hello SMaag!

For me, this was a challenge, to create something standalone, fully working with the limitation in code size to fit in 1 post in the forums. That limit is 60k characters. Because of that limit, I left out some planned game features, and made some poorly named functions and variables (more and more at the end of the code) I would not have done otherwise. For example cto(some parameters) instead of centertext_outlined(some parameters)

This original version of the game is limited in features. Main purpose is to survive long enough to get points. I added 2 win conditions, 1 is to find and destroy an alien bug nest (Hidden quest), the other is to collect 50 crates and upload it into your base (Displayed quest). You lose if the bugs bite trough the armor of your vehicle.
(If you go close to a crate and press E or leftclick on it, you collect it. Same way you can spend them at the base, at the center of the area.
You can even exchange them for ammo or armor.)

Without some win and lose condition, I would not call this a game. But that's all it does ;)

Gameplay time is circa 20-25 minutes until someone wins or loses. (I never was able to collect 50 crates, but managed to destroy the nest.)
SMaag
Enthusiast
Enthusiast
Posts: 324
Joined: Sat Jan 14, 2023 6:55 pm
Location: Bavaria/Germany

Re: [GAME] - Bug Planet

Post by SMaag »

I don't want to play a lot and I'm not a game programmer!
I play Just to understand and see how it is done in the code!

To get firm with PureBasic my first project was a fork of the Snake game, that's all my expirience
with games in PB. Because of that I like to see how the game programers do such things in PB.

You lose if the bugs bite trough the armor of your vehicle.
thanks @miso
miso
Enthusiast
Enthusiast
Posts: 466
Joined: Sat Oct 21, 2023 4:06 pm
Location: Hungary

Re: [GAME] - Bug Planet

Post by miso »

SMaag wrote: Thu Aug 07, 2025 1:36 pm I don't want to play a lot and I'm not a game programmer!
I play Just to understand and see how it is done in the code!
I'm aware, thats why I'm trying to explain some of my poor choices in the code.
thanks @miso
Sure, anytime. Your welcome.
Post Reply