If InitSprite() = 0 Or InitKeyboard() = 0  Or InitMouse()=0  
  MessageRequester("Error", "Can't open DirectX 7 Or later", 0)
  End
EndIf

If InitSprite3D() = 0
  MessageRequester("Error", "Direct3D system can't be initialized correctly", 0)
  End
EndIf
UsePNGImageDecoder()
OpenScreen(1024, 768, 32, "sprite")



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 (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 (100, "sprite/gem_0009.png" )
;-----------------------------------задний план


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
    nom.w
  EndStructure

  NewList tur.Person ()
  


 

okno=1
 

start:
;DisplaySprite(4, xf, yf+120)
;DisplaySprite(3, xff, yf)
;DisplaySprite(5, xfff, yf+730)
Gosub print
If okno=1:Gosub okno:EndIf 
Gosub mouse
Gosub print2
Gosub exit:

FlipBuffers()
ClearScreen (0)
Goto start



















exit:
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Escape)
End 
 EndIf
Return 


mouse:
ExamineKeyboard()

If KeyboardPushed(#PB_Key_F1):Goto f1: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 KeyboardPushed(#PB_Key_W):Goto w1:EndIf 
If KeyboardPushed(#PB_Key_S):Goto s1:EndIf 
If KeyboardPushed(#PB_Key_Z):Goto z1: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
DisplayTransparentSprite(obx, xm3+c, ym3+d)


 xm = MouseX()                         
 ym = MouseY() 

DisplayTransparentSprite(1, xm, ym)

anim2+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 MouseButton(1) 

ExamineMouse() 
 xm = MouseX()                         
 ym = MouseY() 
 xm-c:ym-d

;-------------------------------------

obx2=obx
 Gosub prow
 If pro=0
   ExamineMouse() 
   xm = MouseX()                         
   ym = MouseY() 
   xm-c:ym-d
   xm/48:xm*48
   ym/48:ym*48
 Gosub sraw
  AddElement( tur() )
  tur()\x = xm-sdy
  tur()\y = ym-sdx
  tur()\nom = obx
  obx=obx2
  
EndIf 


EndIf 

If MouseButton(2) 
xm-c:ym-d
xm/48:xm*48
ym/48:ym*48
Goto mou





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=>100:Goto prow3:EndIf 
If obx=>50:Goto prow3a:EndIf 
ResetList( tur() ) 

While NextElement( tur())
If obx<100 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:
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 








z1:
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Z):Goto z1:EndIf 
If KeyboardPushed(#PB_Key_LeftControl):DeleteElement( tur() ):EndIf 
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 
  EndIf 
EndIf 
Return 








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








print:

ResetList( tur() ) 

While NextElement( tur())
If tur()\nom=77:DisplayTransparentSprite( tur()\nom+anim4 , tur()\x + c, tur()\y + d):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 
  su:
Wend

Return 

print2:

ResetList( tur() ) 

While NextElement( tur())

  If tur()\nom=>100:DisplayTransparentSprite( tur()\nom , tur()\x + c, tur()\y + d):EndIf 
  
Wend

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)
   
   xp=730:yp=550
a$="Hомер обьекта -"
Gosub text
xp=730:yp=560
a$=Str(obx)
Gosub text
Return 







; IDE Options = PureBasic 4.40 (Windows - x86)
; CursorPosition = 174
; FirstLine = 158
; IDE Options = PureBasic 4.40 (Windows - x86)
; CursorPosition = 155
; FirstLine = 135