collideimage.bmx 935 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. Strict
  2. Local rot,x,y
  3. Graphics 640,480
  4. AutoMidHandle True 'image will rotate around it's center
  5. Local image:TImage=LoadImage("bullet.png")
  6. While Not KeyHit(KEY_ESCAPE)
  7. Cls
  8. ResetCollisions
  9. ' draw the first image at 5 times the size and on an arbitrary angle
  10. SetScale 5,5
  11. SetRotation 125
  12. DrawImage image,200,200
  13. ' add the first image to the first collision layer at same postion, rotation
  14. ' and scale as it has just been drawn
  15. CollideImage image,200,200,0,0,1
  16. ' move the other image relative to the mouse and rotate it continuously
  17. x=MouseX()
  18. y=MouseY()-20
  19. rot:+1
  20. SetRotation rot
  21. DrawImage image,x,y
  22. ' test the image at it's current rotation, scale and position with images
  23. ' that have been added to the first collision layer
  24. If CollideImage(image,x,y,0,1,0)
  25. ' reset scale and rotation states so our text is drawn correctly
  26. SetScale 1,1
  27. SetRotation 0
  28. DrawText "COLLISION!",20,20
  29. EndIf
  30. Flip
  31. Wend