learning about sprites
Posted: Sun Aug 16, 2015 1:15 am
				
				I have been playing around with sprites, but when ever i try and move the character sprite it always shows a collision even when its miles from the one sprite im trying to detect. Can anyone tell me what im doing wrong please  
 
thanks
			Code: Select all
UseJPEGImageDecoder()
Structure mapdata
  blocktype.s
  blockx.i
  blocky.i
  blocksprite.i
  
EndStructure
Global thomasx.i,thomasy.i
Global movestep.i = 5
If InitSprite() = 0 Or InitKeyboard() = 0
  MessageRequester("Error", "Sprite system can't be initialized", 0)
  End
EndIf
;
; Now, open a 800*600 - 32 bits screen
;
Enumeration
  #mainwin
  #mazewin
  
  #fwall
  #hwall
  #vwall
  #floor0
  #thomas
EndEnumeration
Procedure drawscreen()
  ClearList(currentmap())
  
  ClearScreen(RGB(255,255,255))
  y = 0
  
  If IsSprite(#thomas)
            DisplaySprite(#thomas,thomasx,thomasy)
  EndIf
  Restore level1
  Repeat
    Read.s mapline$
    If mapline$ <> "end"
    bs = 1
    x = 0
    
    For c = 1 To 40 
      blockcode$ = Mid(mapline$,bs,2)
      bs + 2
      Select blockcode$
                 
        Case "01"
          If IsSprite(#fwall)
            
            DisplaySprite(#fwall,x,y)
           
          EndIf
          
        Case "02"
          If IsSprite(#vwall)
            
            DisplaySprite(#vwall,x,y)
          EndIf
          
        Case "03"
          If IsSprite(#vwall)
           
            DisplaySprite(#vwall,x,y)
          EndIf
          
        Case "04"
          If IsSprite(#floor0)
            ns = CopySprite(#floor0,#PB_Any)
            DisplaySprite(#floor0,x,y)
          EndIf
          
      EndSelect
      
      x + 32
    Next c
    y + 32
  EndIf
  Until mapline$ = "end"
    FlipBuffers()
  
EndProcedure
  
Procedure movementthread(blank.i = 0)
    
  oldposx = thomasx
  oldposy = thomasy
    ExamineKeyboard()
    
    If KeyboardPushed(#PB_Key_Down)                       
            thomasy + movestep           
           
            kp = 1
    EndIf
     
    If KeyboardPushed(#PB_Key_Up)                   
            thomasy - movestep
          
            kp = 1
    EndIf
    
    If KeyboardPushed(#PB_Key_Right)                
           thomasx + movestep
              
           kp = 1
    EndIf
    
    If KeyboardPushed(#PB_Key_Left)               
            thomasx - movestep
          
    EndIf
    
    If kp > 0
      pow  = 0
     pow = SpriteCollision(#thomas,thomasx,thomasy,#fwall,thomasx,thomasy) 
          
          Debug pow 
          
      If pow > 0
        thomasx = oldposx
        thomasy = oldposy
        
      Else
        drawscreen()
      EndIf                             
  EndIf
  
EndProcedure
If OpenWindow(#mainwin,1,1,800,600, "Casper Compile",#PB_Window_TitleBar  |  #PB_Window_Invisible | #PB_Window_ScreenCentered | #PB_Window_MinimizeGadget | #PB_Window_SystemMenu)   
    
   If OpenWindowedScreen(WindowID(#mainwin),0,0,800, 600)
  ; Load our 16 bit sprite (which is a 24 bit picture in fact, as BMP doesn't support 16 bit format)
  
  
  LoadSprite(#fwall,"sprites\fwall.jpg")
  LoadSprite(#hwall,"sprites\hwall.jpg")
  LoadSprite(#vwall,"sprites\vwall.jpg")
  LoadSprite(#floor0,"sprites\floortrip.jpg")
  LoadSprite(#thomas,"sprites\thomas.jpg")
  
  thomasx = 133
  thomasy = 133
  drawscreen()
  
  HideWindow(#mainwin,0)
  
  Repeat ; Start of the event loop    
       WindowID = EventWindow() ; The Window where the event is generated, can be used in the gadget procedures 
       Event = WaitWindowEvent(2) ; This line waits until an event is received from Windows    
       GadgetID = EventGadget() ; Is it a gadget event? 
       EventType = EventType() ; The event type
      
    If  Event = #PB_Event_Gadget 
      
      Select GadgetID 
          
                 
                           
          
      EndSelect
         
    EndIf
    
    
    movementthread()
    
  Until Event = #PB_Event_CloseWindow 
  
  
  
Else
  MessageRequester("Error", "Can't open a 800*600 - 32 bit screen !", 0)
EndIf 
EndIf
  
  
DataSection
  level1:
  Data.s "01010101010101010101010101010101010101010101010101"
  Data.s "01000000000000000000000000000000000000000000000001"
  Data.s "01000000000000000000000000000000000000000000000001"
  Data.s "01000000030000000000000000000000000000000000000001"
  Data.s "01000000000000000000000000000000000000000000000001"
  Data.s "01000000000000000000000000000000000000000000000001"
  Data.s "01000000000000000000000000000000000000000000000001"
  Data.s "01000000000000000000000000000000000000000000000001"
  Data.s "01000000000000000000000000000000000000000000000001"
  Data.s "01000000000000000000000000000000000000000000000001"
  Data.s "01000000000000000000000000000000000000000000000001"
  Data.s "01000000000000000000000000000000000000000000000001"
  Data.s "01000000000000000000000000000000000000000000000001"
  Data.s "01000000000000000000000000000000000000000000000001"
  Data.s "01000000000000000000000000000000000000000000000001"
  Data.s "01000000000000000000000000000000000000000000000001"
  Data.s "01000000000000000000000000000000000000000000000001"
  Data.s "01000000000000000000000000000000000000000000000001"
  Data.s "01010101010101010101010101010101010101010101010101"
  Data.s  "end"
  
EndDataSection