
If InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse() = 0  Or InitSprite3D() = 0
  MessageRequester("Error", "Can't open the sprite system", 0)
  End
EndIf
  UsePNGImageDecoder()
  

  If OpenWindow(0, 0, 0, 500, 500, "Выдры.", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)
  ButtonGadget(1, 10,  10, 100, 25, "F9-Загрузить")
  ButtonGadget(2, 120,  10, 100, 25, "F8-Сохранить")
  ButtonGadget(3, 230,  10, 100, 25, "Играть")
  ButtonGadget(4, 340,  10, 100, 25, "Выход")
  ;
  ; This is the 'event loop'. All the user actions are processed here.
  ; It's very easy to understand: when an action occurs, the EventID
  ; isn't 0 and we just have to see what have happened...
  ;
   OpenWindowedScreen(WindowID(0), 10, 70, 1024, 768, 1, 0, 0)
  
  
  


  
  
  LoadSprite (1, "gfx/str.png" )
  LoadSprite (2, "gfx/rama.png" )
LoadSprite (3, "fon/1.png" )
LoadSprite (4, "fon/2.png" )
LoadSprite (5, "fon/3.png" )

;-----------------------------------непроходимые
LoadSprite (10, "sprite/1.png" )
LoadSprite (11, "sprite/2.png" )
LoadSprite (12, "sprite/3.png" )
LoadSprite (13, "sprite/4.png" )
LoadSprite (14, "sprite/5.png" )
LoadSprite (15, "sprite/6.png" )
LoadSprite (16, "sprite/7.png" )
LoadSprite (17, "sprite/8.png" )
LoadSprite (18, "sprite/9.png" )
LoadSprite (19, "sprite/10.png" )
LoadSprite (20, "sprite/53.png" )
LoadSprite (21, "sprite/11.png" )
LoadSprite (22, "sprite/12.png" )
LoadSprite (23, "sprite/13.png" )
LoadSprite (24, "sprite/14.png" )
LoadSprite (25, "sprite/15.bmp" )
LoadSprite (26, "sprite/16.bmp" )
LoadSprite (27, "sprite/chest_0000.png" )
LoadSprite (28, "sprite/chest_0001.png" )
LoadSprite (29, "sprite/duplo.png" )
LoadSprite (30, "sprite/77.png" )
;-----------------------------------проходимые

LoadSprite (50, "sprite/50.png" )
LoadSprite (51, "sprite/51.png" )
LoadSprite (52, "sprite/52.png" )
LoadSprite (53, "sprite/53.png" )
LoadSprite (54, "sprite/54.png" )
LoadSprite (55, "sprite/55.png" )
LoadSprite (56, "sprite/56.png" )
LoadSprite (57, "sprite/57.png" )
LoadSprite (58, "sprite/top_lamp_0000.png" )
LoadSprite (59, "sprite/top_lamp_0001.png" )
LoadSprite (60, "sprite/top_lamp_0002.png" )
LoadSprite (61, "sprite/top_lamp_0003.png" )
LoadSprite (62, "sprite/top_lamp_0004.png" )
LoadSprite (63, "sprite/top_lamp_0005.png" )
LoadSprite (64, "sprite/top_lamp_0006.png" )
LoadSprite (65, "sprite/top_lamp_0007.png" )
LoadSprite (66, "sprite/top_lamp_0008.png" )
LoadSprite (67, "sprite/gem_0000.png" )
LoadSprite (68, "sprite/gem_0001.png" )
LoadSprite (69, "sprite/gem_0002.png" )
LoadSprite (70, "sprite/gem_0003.png" )
LoadSprite (71, "sprite/gem_0004.png" )
LoadSprite (72, "sprite/gem_0005.png" )
LoadSprite (73, "sprite/gem_0006.png" )
LoadSprite (74, "sprite/gem_0007.png" )
LoadSprite (75, "sprite/gem_0008.png" )
LoadSprite (76, "sprite/gem_0009.png" )
LoadSprite (77, "sprite/water3_0000.png" )
LoadSprite (78, "sprite/water3_0001.png" )
LoadSprite (79, "sprite/water3_0002.png" )
LoadSprite (80, "sprite/water3_0003.png" )
LoadSprite (81, "sprite/water3_0004.png" )
LoadSprite (82, "sprite/water3_0005.png" )
LoadSprite (83, "sprite/water3_0006.png" )

LoadSprite (84, "sprite/fence_0010.png" )
LoadSprite (85, "sprite/fence_0011.png" )
LoadSprite (86, "sprite/fence_0012.png" )
LoadSprite (87, "sprite/fence_0013.png" )
LoadSprite (88, "sprite/fence_0014.png" )
LoadSprite (89, "sprite/fence_0015.png" )
LoadSprite (90, "sprite/fence_0016.png" )
LoadSprite (91, "sprite/fence_0017.png" )
LoadSprite (92, "sprite/barrell0000.png" )
LoadSprite (93, "sprite/barrell0001.png" )
LoadSprite (94, "sprite/barrell0002.png" )
LoadSprite (95, "sprite/barrell0001.png" )



  ;-----------------------------------Передний план

LoadSprite (100, "sprite/fence_0000.png" )
LoadSprite (101, "sprite/fence_0001.png" )
LoadSprite (102, "sprite/fence_0002.png" )
LoadSprite (103, "sprite/fence_0003.png" )
LoadSprite (104, "sprite/fence_0004.png" )
LoadSprite (105, "sprite/fence_0005.png" )
LoadSprite (106, "sprite/fence_0006.png" )
LoadSprite (107, "sprite/fence_0007.png" )

;-----------------------------------задний план
LoadSprite (120, "fon/1.png" )
LoadSprite (121, "sprite/63.png" )
LoadSprite (122, "sprite/64.png" )
LoadSprite (123, "sprite/65.png" )
LoadSprite (124, "sprite/66.png" )
LoadSprite (125, "sprite/67.png" )
LoadSprite (126, "sprite/68.png" )
LoadSprite (127, "sprite/69.png" )
LoadSprite (128, "sprite/70.png" )
LoadSprite (129, "sprite/71.png" )
LoadSprite (130, "sprite/72.png" )
LoadSprite (131, "sprite/73.png" )
LoadSprite (132, "sprite/74.png" )
LoadSprite (133, "sprite/75.png" )
LoadSprite (134, "sprite/76.png" )


LoadSprite (200, "sprite/58.png" )
LoadSprite (201, "sprite/59.png" )
LoadSprite (202, "sprite/60.png" )
LoadSprite (203, "sprite/61.png" )
LoadSprite (204, "sprite/62.png" )

LoadSprite (220, "sprite/78.png" );   предметы 
LoadSprite (221, "sprite/79.png" )

LoadSprite (250, "sprite/100.png" )
LoadSprite (251, "sprite/101.png" )
LoadSprite (252, "sprite/102.png" )

LoadSprite (300, "sprite/z1.png",#PB_Sprite_Texture )
LoadSprite (301, "sprite/z2.png",#PB_Sprite_Texture )
LoadSprite (302, "sprite/z3.png",#PB_Sprite_Texture )
LoadSprite (303, "sprite/z4.png",#PB_Sprite_Texture )
LoadSprite (304, "sprite/z5.png",#PB_Sprite_Texture )
LoadSprite (305, "sprite/z6.png",#PB_Sprite_Texture )
LoadSprite (306, "sprite/z7.png",#PB_Sprite_Texture )
LoadSprite (307, "sprite/z8.png",#PB_Sprite_Texture )
LoadSprite (308, "sprite/z7.png",#PB_Sprite_Texture )
LoadSprite (309, "sprite/z6.png",#PB_Sprite_Texture )
LoadSprite (310, "sprite/z5.png",#PB_Sprite_Texture )
LoadSprite (311, "sprite/z4.png",#PB_Sprite_Texture )
LoadSprite (312, "sprite/z3.png",#PB_Sprite_Texture )
LoadSprite (313, "sprite/z2.png",#PB_Sprite_Texture )



LoadSprite (500, "harak/vudra_walk_0000.png",#PB_Sprite_Texture )
LoadSprite (501, "harak/vudra_walk_0001.png",#PB_Sprite_Texture )
LoadSprite (502, "harak/vudra_walk_0002.png",#PB_Sprite_Texture )
LoadSprite (503, "harak/vudra_walk_0003.png",#PB_Sprite_Texture )
LoadSprite (504, "harak/vudra_walk_0004.png",#PB_Sprite_Texture )
LoadSprite (505, "harak/vudra_walk_0005.png",#PB_Sprite_Texture )
LoadSprite (506, "harak/vudra_walk_0006.png",#PB_Sprite_Texture )
LoadSprite (507, "harak/vudra_walk_0007.png",#PB_Sprite_Texture )
LoadSprite (96, "sprite/0.bmp",#PB_Sprite_Texture )
LoadSprite (97, "sprite/0.bmp",#PB_Sprite_Texture )


CreateSprite3D(1, 300)
CreateSprite3D(2, 301)
CreateSprite3D(3, 302)
CreateSprite3D(4, 303)
CreateSprite3D(5, 304)
CreateSprite3D(6, 305)
CreateSprite3D(7, 306)
CreateSprite3D(8, 307)
CreateSprite3D(9, 308)
CreateSprite3D(10, 309)
CreateSprite3D(11, 310)
CreateSprite3D(12, 311)
CreateSprite3D(13, 312)
CreateSprite3D(14, 313)

CreateSprite3D(500, 500)
CreateSprite3D(501, 501)
CreateSprite3D(502, 502)
CreateSprite3D(503, 503)
CreateSprite3D(504, 504)
CreateSprite3D(505, 505)
CreateSprite3D(506, 506)
CreateSprite3D(507, 507)



exitm=0

xm=0:ym=0; x y mouse
razmer=128-16; razmer lokacii
c=0:d=0
obx=10
chet=0
obx2=0

Structure Person
    x.w
    y.w
    x2.w
    y2.w
    nom.w
    swo.w
    spid.w
    spid2.w
    iner.w
    iner2.w
  EndStructure

  NewList tur.Person ()
  
  
  Structure Person2
    x.w
    y.w
    xx.w
    yy.w
    nom.w
    ani.w
        tim.w
           tim2.w
           pow.w
  EndStructure
NewList tur2.Person2 ()





  
  
  
okno=0


Gosub load:
Gosub instal:

  AddElement( tur() )
  tur()\x = 800
  tur()\x2 = 900
  tur()\y = 200
  tur()\nom = 500
  AddElement( tur() )
  tur()\x = 800
  tur()\x2 = 900
  tur()\y = 200
  tur()\nom = 97
   tur()\spid =3
   tur()\spid2 = 3
   
   

   
gravitator=0; ----------------------настройки



  Repeat
  

  
   Event = WaitWindowEvent()
  
  
    Select EventGadget()
Case 1
If EventType() =  #PB_EventType_LeftClick 
  If  OpenWindow(1, 0, 0, 400, 200, "Сохранить файл", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    ExplorerListGadget(0, 10, 10, 380, 180, "C:\Documents and Settings\Администратор\Рабочий стол\снусмумр2\Tur", #PB_Explorer_AlwaysShowSelection )
 Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf 

EndIf 


          Case 4
End 
          Case 3
 If EventType() =  #PB_EventType_LeftClick :  exitm=0: EndIf





EndSelect
  
    If Event = #PB_Event_CloseWindow  ; If the user has pressed on the close button
      Quit = 1
    EndIf

 


Gosub print2



Gosub print
Gosub print4
Gosub print3
If okno=1:Gosub okno:EndIf 

Gosub mouse



FlipBuffers()
ClearScreen (RGB(0, 132, 255))




If exitm=0:ReleaseMouse(0):DisableGadget(3, 1):EndIf 
If exitm=1:ReleaseMouse(1):DisableGadget(3, 0):EndIf 

   Until Quit = 1
  
  

    
EndIf

End 

print4:

ResetList( tur() ) 

While NextElement( tur())
If tur()\nom=100:DisplayTransparentSprite( tur()\nom , tur()\x + c, tur()\y + d+12):Goto suu:EndIf 
If tur()\nom=101:DisplayTransparentSprite( tur()\nom , tur()\x + c, tur()\y + d+12):Goto suu:EndIf 
If tur()\nom=102:DisplayTransparentSprite( tur()\nom , tur()\x + c, tur()\y + d+12):Goto suu:EndIf 
If tur()\nom=103:DisplayTransparentSprite( tur()\nom , tur()\x + c, tur()\y + d+12):Goto suu:EndIf 
If tur()\nom=104:DisplayTransparentSprite( tur()\nom , tur()\x + c, tur()\y + d+12):Goto suu:EndIf 
If tur()\nom=105:DisplayTransparentSprite( tur()\nom , tur()\x + c, tur()\y + d+12):Goto suu:EndIf 
If tur()\nom=106:DisplayTransparentSprite( tur()\nom , tur()\x + c, tur()\y + d+12):Goto suu:EndIf 
If tur()\nom=107:DisplayTransparentSprite( tur()\nom , tur()\x + c, tur()\y + d+12):Goto suu:EndIf 
suu:
Wend

Return 


print:

ResetList( tur() ) 

While NextElement( tur())
If tur()\nom=500:Gosub wydra:Goto su:EndIf 
If tur()\nom=97 Or tur()\nom=96:Goto su:EndIf 
If tur()\nom=77:DisplayTransparentSprite( tur()\nom+anim4 , tur()\x + c, tur()\y + d):Goto su:EndIf 
If tur()\nom=92:DisplayTransparentSprite( tur()\nom+anim5 , tur()\x + c, tur()\y + d):Goto su:EndIf 
If tur()\nom=25:DisplayTransparentSprite( tur()\nom , tur()\x + c, tur()\y + d+8):Goto su:EndIf 
If tur()\nom=26:DisplayTransparentSprite( tur()\nom , tur()\x + c, tur()\y + d+28):Goto su:EndIf 
If tur()\nom=29:DisplayTransparentSprite( tur()\nom , tur()\x + c, tur()\y + d+28):Goto su:EndIf 

If tur()\nom=27:DisplayTransparentSprite( tur()\nom , tur()\x + c, tur()\y + d+4):Goto su:EndIf 
If tur()\nom=28:DisplayTransparentSprite( tur()\nom , tur()\x + c, tur()\y + d+4):Goto su:EndIf 
If tur()\nom=250:DisplayTransparentSprite( tur()\nom , tur()\x + c, tur()\y + d+4):Goto su:EndIf 
If tur()\nom=251:DisplayTransparentSprite( tur()\nom , tur()\x + c, tur()\y + d+4):Goto su:EndIf 
If tur()\nom=252:DisplayTransparentSprite( tur()\nom , tur()\x + c, tur()\y + d+4):Goto su:EndIf 

If tur()\nom=21:DisplayTransparentSprite( tur()\nom , tur()\x + c, tur()\y + d+4):Goto su:EndIf 
If tur()\nom=22:DisplayTransparentSprite( tur()\nom , tur()\x + c, tur()\y + d+4):Goto su:EndIf 
If tur()\nom=23:DisplayTransparentSprite( tur()\nom , tur()\x + c, tur()\y + d+4):Goto su:EndIf 
If tur()\nom=24:DisplayTransparentSprite( tur()\nom , tur()\x + c, tur()\y + d+4):Goto su:EndIf 
If tur()\nom=67:DisplayTransparentSprite( tur()\nom+anim3 , tur()\x + c, tur()\y + d):Goto su:EndIf 
If tur()\nom=58:DisplayTransparentSprite( tur()\nom+anim , tur()\x + c, tur()\y + d):Goto su:EndIf 
 If tur()\nom=19:DisplayTransparentSprite( tur()\nom , tur()\x + c, tur()\y + d+16):Goto su:EndIf 
  If tur()\nom=14:DisplayTransparentSprite( tur()\nom , tur()\x + c+25, tur()\y + d):Goto su:EndIf 
  If tur()\nom=52:DisplayTransparentSprite( tur()\nom , tur()\x + c, tur()\y + d-30):Goto su:EndIf 
  If tur()\nom=53 Or tur()\nom=54:DisplayTransparentSprite( tur()\nom , tur()\x + c, tur()\y + d+3):Goto su:EndIf 
  If tur()\nom<=100:DisplayTransparentSprite( tur()\nom , tur()\x + c, tur()\y + d):EndIf 
    If tur()\nom=>123:DisplayTransparentSprite( tur()\nom , tur()\x + c, tur()\y + d):EndIf 
  su:
Wend

Return 

print2:

ResetList( tur() ) 

While NextElement( tur())

  If tur()\nom=>120 And tur()\nom<123:DisplayTransparentSprite( tur()\nom , tur()\x + c/2, tur()\y + d):EndIf 
  
Wend

Return 













escc:

exitm=1:
Return 
a111:
ExamineKeyboard()
If KeyboardPushed(#PB_Key_1):
Goto a111:EndIf 
ResetList( tur() ) 

 While NextElement( tur())
If tur()\nom=97 And tur()\iner=0:
tur()\iner=32:EndIf 
Wend
Return 

mouse:

ExamineKeyboard()


If KeyboardPushed(#PB_Key_Escape):Goto escc:EndIf 
If KeyboardPushed(#PB_Key_Left) And korx>0:korx-1:c+16:xf+4:xff+2:xfff+5:EndIf  
If KeyboardPushed(#PB_Key_Right) And korx<razmer:korx+1:c-16:xf-4:xff-2:xfff-5:EndIf  
If KeyboardPushed(#PB_Key_Up) And kory>0:kory-1:d+16:yf+4:EndIf 
If KeyboardPushed(#PB_Key_Down) And kory<razmer:kory+1:d-16:yf-4:EndIf 
If gravitator=0 And KeyboardPushed(#PB_Key_Space):gravitator=60:space=1:EndIf 
If KeyboardPushed(#PB_Key_1):
Goto a111

:EndIf

ExamineMouse() 
 
 xm = MouseX()                         
 ym = MouseY() 
 
If okno=1 And xm>730:Goto oknono:EndIf 

xm-c:ym-d
xm/48:xm*48
ym/48:ym*48
xm3=xm
ym3=ym






 xm = MouseX()                         
 ym = MouseY() 

DisplayTransparentSprite(1, xm, ym)
anim2+1
anim22+1
If anim2=4:
anim+1
anim3+1
anim4+1
If anim=9:anim=0:EndIf 
If anim4=7:anim4=0:EndIf
If anim3=10:anim3=0:EndIf 
anim2=0
EndIf 
If anim22=10:
anim5+1
If anim5=3:anim5=0:EndIf 
anim22=0
EndIf 


ExamineMouse() 
xm-c:ym-d
If MouseButton(1) 
ResetList( tur() ) 

 While NextElement( tur())
If tur()\nom=97:
xm/tur()\spid:xm*tur()\spid
xm33=xm
ym33=ym
tur()\x2=xm33:EndIf 
Wend
  

EndIf 


Return  








mou:
 ExamineMouse() 
If MouseButton(2) :Goto mou:EndIf 
ResetList( tur() ) 
While NextElement( tur())
 If SpriteCollision(obx, xm3, ym3, tur()\nom, tur()\x, tur()\y): DeleteElement( tur() ):Return:EndIf   
Wend
Return 


sraw:
Return 





prow:

pro=0
Goto prow3a:

If obx=>110:Goto prow3:EndIf 
If obx=>50:Goto prow3a:EndIf 
ResetList( tur() ) 

While NextElement( tur())
If obx<110 And SpriteCollision(obx, xm3, ym3, tur()\nom, tur()\x, tur()\y):pro=1:EndIf 
Wend
Return 
prow3:
ResetList( tur() ) 

While NextElement( tur())
If tur()\nom>10 And SpriteCollision(obx, xm3, ym3, tur()\nom, tur()\x, tur()\y):pro=1:EndIf 
Wend
Return 


prow3a:
 ExamineMouse() 
If obx=>120 And MouseButton(1) :Goto prow3a:EndIf 
If obx=>120 And obx<123:Return:EndIf 
ResetList( tur() ) 

While NextElement( tur())
If tur()\nom=obx And SpriteCollision(obx, xm3, ym3, tur()\nom, tur()\x, tur()\y):pro=1:EndIf 

Wend
Return 

























 oknono:
 If okno=1:
 xmz= MouseX()                        
 ymz = MouseY() 
 DisplayTransparentSprite(1, xm, ym)
 
 xmz/48
ymz/48
  If MouseButton(1) 
  If xmz=16 And ymz=0:obx=10:EndIf 
    If xmz=17 And ymz=0:obx=51:EndIf 
    If xmz=18 And ymz=0:obx=50:EndIf 
    If xmz=19 And ymz=0:obx=52:EndIf 
       If xmz=16 And ymz=1:obx=53:EndIf 
            If xmz=17 And ymz=1:obx=58:EndIf 
             If xmz=18 And ymz=1:obx=67:EndIf 
                      If xmz=19 And ymz=1:obx=21:EndIf 
                      If xmz=16 And ymz=2:obx=100:EndIf 
                         If xmz=17 And ymz=2:obx=84:EndIf 
                          If xmz=18 And ymz=2:obx=120:EndIf 
                             If xmz=16 And ymz=3:obx=92:EndIf 
                               If xmz=16 And ymz=4:obx=200:EndIf 
                                 If xmz=17 And ymz=4:obx=220:EndIf 
                                   If xmz=18 And ymz=4:obx=250:EndIf 
           
           
  EndIf 
EndIf 
Return 








w1:
ExamineKeyboard()
If obx=30:obx=49:EndIf 
If KeyboardPushed(#PB_Key_W):Goto w1:EndIf 
obx+1
Return 
s1:
If obx=50:obx=31:EndIf 
ExamineKeyboard()
If KeyboardPushed(#PB_Key_S):Goto s1:EndIf 
If obx>10:obx-1:EndIf 
Return 
 











text:
  StartDrawing( ScreenOutput() )
      DrawingMode(1)
      
      
  
   DrawText(xp, yp, a$, RGB((0),(0),(0)) )

      
   StopDrawing()


Return 


f1:
ExamineKeyboard()
If KeyboardPushed(#PB_Key_F1):Goto f1:EndIf 
If okno=1:okno=0:Return:EndIf 
If okno=0:okno=1:Return:EndIf 
Return 



okno:
 xmm = MouseX()                         
 ymm = MouseY() 
 xmm+48
 xmm/48:xmm*48
ymm/48:ymm*48
  StartDrawing( ScreenOutput() )
      DrawingMode(1)
      Box(800-70,0,256+8,1024+8,RGB((200),(200),(200)))


  If xmm>730 :Box(xmm-48,ymm+16,48,48,RGB((255),(0),(255))):EndIf 

   StopDrawing()
   
   
  DisplayTransparentSprite(10, 768, 16)
  DisplayTransparentSprite(51, 768+48, 16)
  DisplayTransparentSprite(50, 768+48+48, 16)
  DisplayTransparentSprite(52, 768+96+48, 16)
   DisplayTransparentSprite(53, 768, 16+48)
     DisplayTransparentSprite(58, 768+48, 16+48)
          DisplayTransparentSprite(67, 768+48+48, 16+48)
           DisplayTransparentSprite(21, 768+48+48+48, 16+48)
             DisplayTransparentSprite(100, 768, 16+48+48)
                 DisplayTransparentSprite(84, 768+48, 16+48+48)
                  DisplayTransparentSprite(120, 768+48+48, 16+48+48)
                    DisplayTransparentSprite(92, 768, 16+48+48+48)
            
                       DisplayTransparentSprite(200, 768, 16+48+48+48+48)
                       DisplayTransparentSprite(220, 768+48, 16+48+48+48+48)
                        DisplayTransparentSprite(250, 768+48+48, 16+48+48+48+48)
   
   xp=730:yp=550
a$="Hомер обьекта -"
Gosub text
xp=730:yp=560
a$=Str(obx)
Gosub text
Return 







instal:

ResetList( tur() ) 
While NextElement( tur())
If tur()\nom=10 Or tur()\nom=11 Or tur()\nom=12 Or tur()\nom=13  Or tur()\nom=16 Or tur()\nom=17  Or tur()\nom=18 Or tur()\nom=19 Or tur()\nom=21 Or tur()\nom=22 Or tur()\nom=23 Or tur()\nom=24 Or tur()\nom=25 Or tur()\nom=30:
x=tur()\x
y=tur()\y
 AddElement( tur() )
  tur()\x = x
  tur()\y = y
  tur()\nom = 96
EndIf 

If tur()\nom=30:Gosub instal2:EndIf 
Wend
Return 

instal2:

xx=tur()\x
yy=tur()\y

aas=32
Repeat 


  AddElement( tur2() )
  tur2()\x = tur()\x+Random(48)-8
  tur2()\y = tur()\y+16
  tur2()\xx = tur()\x-8
  tur2()\yy = tur()\y+16
  tur2()\nom = 1
  tur2()\ani = 16+Random(128)
  
  tur2()\tim = 0+Random(8)
    tur2()\tim2= tur2()\tim
    tur2()\pow = Random(3)
      If aas>0:aas-1:EndIf 
    Until aas=0
Return 




print3:

Start3D()

ResetList( tur2() ) 

While NextElement( tur2())

  If tur2()\nom>0:
  :DisplaySprite3D( tur2()\nom , tur2()\x + c, tur2()\y + d, tur2()\ani):EndIf 
  
  If tur2()\pow=1 And tur2()\tim/2=0: tur2()\x-1:EndIf
    If tur2()\pow=2 And tur2()\tim/2=0: tur2()\x+1:EndIf
  
If tur2()\tim>0: tur2()\tim-1:EndIf
If tur2()\tim=0: tur2()\tim=tur2()\tim2:tur2()\nom+1:EndIf
If tur2()\nom=14:tur2()\nom=1:EndIf 

  If tur2()\ani>0:tur2()\ani-1:tur2()\y-1:EndIf
     If tur2()\ani=0:xx=tur2()\xx:yy=tur2()\yy:DeleteElement( tur2() ): Gosub soz:EndIf 
Wend

Stop3D()

Return 





wydra:
;--------------------wydra

Start3D()
If upal=0: RotateSprite3D(tur()\nom+wani, 370, 0):EndIf 
If upal=1: RotateSprite3D(tur()\nom+wani, 360, 0):EndIf 
If gravitator>20 And space=1: RotateSprite3D(tur()\nom+wani, 350, 0):EndIf 
  DisplaySprite3D(tur()\nom+wani , tur()\x + c, tur()\y + d,255)
Stop3D()
Gosub gravitacija
Return 


inercija:
ResetList( tur() ) 
While NextElement( tur())
If tur()\nom=97 And tur()\iner>0:
tur()\iner2=0
If tur()\iner>0:tur()\iner-1:EndIf 
iner=1
Gosub stop
iner=0

:EndIf 


If tur()\nom=97 And tur()\iner2>0:
If tur()\iner2>0:tur()\iner2-1:EndIf 
tur()\iner=0
iner=1
Gosub stop2
iner=0
:EndIf 
Wend
Return 

gravitacija:
Gosub inercija


NextElement( tur())
LastElement( tur())
tur()\x+2

If tur()\nom=97 And upal=1:Gosub upal2:EndIf 
If tur()\nom=97 And tur()\x=tur()\x2:wani=0:Goto pokoj:EndIf 
If tur()\nom=97 And tur()\x=tur()\x2-1:wani=0:Goto pokoj:EndIf 
If tur()\nom=97 And tur()\x=tur()\x2+1:wani=0:Goto pokoj:EndIf 
If gravitator>0 And tur()\nom=97 And tur()\x<tur()\x2 And tur()\iner=0:Gosub stop:Gosub wani2:EndIf 
If gravitator>0 And tur()\nom=97 And tur()\x>tur()\x2 And tur()\iner2=0::Gosub stop2:EndIf
If tur()\nom=97 And tur()\x<tur()\x2 And tur()\iner=0::Gosub stop:Gosub wani2:EndIf 
If tur()\nom=97 And tur()\x>tur()\x2 And tur()\iner2=0::Gosub stop2:EndIf 
pokoj:
 If  tur()\nom=97:wyd=tur()\nom:xww=tur()\x:yww=tur()\y:Gosub gravitacija2:ChangeCurrentElement(tur(), *Old_Element):tur()\y=yww:EndIf 



LastElement( tur())
aas=SpriteWidth(tur()\nom)
tur()\nom=500:tur()\x=xww-(aas/2)+24:tur()\y=yww-44
tur()\x+2

Return


stop:
aaa=0
wyd=tur()\nom:xww=tur()\x:yww=tur()\y:a2=tur()\iner:spi=tur()\spid
*Old_Element = @tur() 
ResetList( tur() )
While NextElement( tur())
If iner=1:Goto sli:EndIf 
If tur()\nom=10 Or tur()\nom=11 Or tur()\nom=12 Or tur()\nom=13  Or tur()\nom=16 Or tur()\nom=17  Or tur()\nom=18 Or tur()\nom=19 Or tur()\nom=21 Or tur()\nom=22 Or tur()\nom=23 Or tur()\nom=24 Or tur()\nom=30:
Gosub stop3
EndIf 
sli2:
Wend 
ChangeCurrentElement(tur(), *Old_Element)

If tur()\iner>0 And iner=1 And aaa=1:
tur()\x2=tur()\x
tur()\iner2=tur()\iner/2
tur()\iner=0
Return 
EndIf

If iner=1 And aaa=0 And tur()\iner>0
tur()\x+tur()\iner/2
tur()\x2+tur()\iner/2
Return 
EndIf 


If aaa=1:tur()\x2=tur()\x:EndIf 
If aaa=0:tur()\x+tur()\spid:EndIf 
Return 

sli:
If tur()\nom=10 Or tur()\nom=11 Or tur()\nom=12 Or tur()\nom=13  Or tur()\nom=16 Or tur()\nom=17  Or tur()\nom=18 Or tur()\nom=19 Or tur()\nom=21 Or tur()\nom=22 Or tur()\nom=23 Or tur()\nom=24 Or tur()\nom=30:
Gosub stop3a
EndIf 
Goto sli2

sli3:
If tur()\nom=10 Or tur()\nom=11 Or tur()\nom=12 Or tur()\nom=13  Or tur()\nom=16 Or tur()\nom=17  Or tur()\nom=18 Or tur()\nom=19 Or tur()\nom=21 Or tur()\nom=22 Or tur()\nom=23 Or tur()\nom=24 Or tur()\nom=30:
Gosub stop4a
EndIf 
Goto sli4

stop2:
aaa=0
wyd=tur()\nom:xww=tur()\x:yww=tur()\y:a2=tur()\iner2:spi=tur()\spid
*Old_Element = @tur() 
ResetList( tur() )
While NextElement( tur())
If iner=1:Goto sli3:EndIf 
If tur()\nom=10 Or tur()\nom=11 Or tur()\nom=12 Or tur()\nom=13  Or tur()\nom=16 Or tur()\nom=17  Or tur()\nom=18 Or tur()\nom=19 Or tur()\nom=21 Or tur()\nom=22 Or tur()\nom=23 Or tur()\nom=24 Or tur()\nom=30:
Gosub stop4
EndIf 
sli4:
Wend 
ChangeCurrentElement(tur(), *Old_Element)

If tur()\iner2>0 And iner=1 And aaa=1
tur()\x+2
tur()\x2=tur()\x
tur()\iner=tur()\iner2/2
tur()\iner2=0
Return 
EndIf 

If iner=1 And aaa=0 And tur()\iner2>0
tur()\x-tur()\iner2/2
tur()\x2-tur()\iner2/2
Return 
EndIf 

If aaa=1:tur()\x2=tur()\x:EndIf 
If aaa=0:tur()\x-tur()\spid:EndIf  
Return 


stop3a:
If SpriteCollision(97, xww, yww, tur()\nom, tur()\x-a2, tur()\y+1)=1:aaa=1:Return:EndIf 
Return 

stop4a:
If SpriteCollision(97, xww, yww, tur()\nom, tur()\x+a2, tur()\y+1)=1:tur()\x2=tur()\x:aaa=1:Return:EndIf 
Return 

stop3:
If SpriteCollision(97, xww, yww, tur()\nom, tur()\x-spi, tur()\y+1)=1:aaa=1:Return:EndIf 
Return 

stop4:
If SpriteCollision(97, xww, yww, tur()\nom, tur()\x+spi, tur()\y+1)=1:tur()\x2=tur()\x:aaa=1:Return:EndIf 
Return 

 
gravitacija2:
*Old_Element = @tur() 
ResetList( tur() )
While NextElement( tur())

If tur()\nom=96 And SpriteCollision(97, xww, yww, tur()\nom, tur()\x, tur()\y)=1:upal=1:Return:EndIf 
If tur()\nom=96 And SpriteCollision(97, xww, yww, tur()\nom, tur()\x, tur()\y+1)=1:upal=1:Return:EndIf
If tur()\nom=96 And SpriteCollision(97, xww, yww, tur()\nom, tur()\x, tur()\y+2)=1:upal=1:Return:EndIf
If tur()\nom=96 And SpriteCollision(97, xww, yww, tur()\nom, tur()\x, tur()\y+3)=1:upal=1:Return:EndIf
If tur()\nom=96 And SpriteCollision(97, xww, yww, tur()\nom, tur()\x, tur()\y+4)=1:upal=1:Return:EndIf
If tur()\nom=96 And SpriteCollision(97, xww, yww, tur()\nom, tur()\x, tur()\y+5)=1:upal=1:Return:EndIf
If tur()\nom=96 And SpriteCollision(97, xww, yww, tur()\nom, tur()\x, tur()\y+6)=1:upal=1:Return:EndIf
If tur()\nom=96 And SpriteCollision(97, xww, yww, tur()\nom, tur()\x, tur()\y+7)=1:upal=1:Return:EndIf
If tur()\nom=96 And SpriteCollision(97, xww, yww, tur()\nom, tur()\x, tur()\y+8)=1:upal=1:Return:EndIf
If tur()\nom=96 And SpriteCollision(97, xww, yww, tur()\nom, tur()\x, tur()\y+9)=1:upal=1:Return:EndIf

sl:

Wend 
If upal=0:
aaa=gravitator/4
If aaa>16:aaa=15:EndIf 
yww+aaa
gravitator+1:EndIf 
Return 






upal2:
gravitator-6
If gravitator>0:tur()\y-(gravitator/4):Return:EndIf
upal=0 
space=0
gravitator=0
Return 



wani2:
If anim2=0:Goto wani3:EndIf
Return 
wani3:
wani+1
If wani=8:wani=0:EndIf 
Return 




soz:



  AddElement( tur2() )
  tur2()\xx = xx
  tur2()\yy = yy
  tur2()\x = xx+Random(48)
  tur2()\y = yy
  tur2()\nom = 1
  tur2()\ani = 16+Random(128)
  tur2()\tim = 0+Random(8)
    tur2()\tim2= tur2()\tim
    tur2()\pow = Random(3)
  
Return 










save:
CreateFile(0,"Tur/tur1.txt")
ResetList( tur() ) 
While NextElement( tur())
WriteLong(0,tur()\nom)
WriteLong(0,tur()\x)
WriteLong(0,tur()\y)
WriteLong(0,tur()\swo)
Wend
CloseFile(0) 
Return
CreateFile(0,"Tur/tur1dubl.txt")
ResetList( tur() ) 
While NextElement( tur())
WriteLong(0,tur()\nom)
WriteLong(0,tur()\x)
WriteLong(0,tur()\y)
WriteLong(0,tur()\swo)
Wend
CloseFile(0) 
Return


load:

ResetList( tur() ) 
While NextElement( tur())
DeleteElement( tur() )
Wend
OpenFile(0,"Tur/tur1.txt")
Length = Lof(0)
ResetList( tur() ) 
Repeat
 AddElement( tur() )
tur()\nom=ReadLong(0)
tur()\x=ReadLong(0)
tur()\y=ReadLong(0)
tur()\swo=ReadLong(0)

Length-16

Until Length=0
 CloseFile(0)

Return

; IDE Options = PureBasic 4.40 (Windows - x86)
; CursorPosition = 736
; FirstLine = 722
; EnableXP