; ==================================== ; Part 1 - Create two coloured images ; ==================================== Cls RGB(0,0,0) For lp=0 To 20 x=Rnd(128) y=Rnd(128) Select Rnd(1) Case 0 BoxC x,y,x+2,y+2,true,RndRGB() Case 1 CircleC x,y,10,true,RndRGB() EndSelect Next GetImage 1,0,0,128,128 PrepareFXImage 1 Cls RGB(0,155,100) CircleC 0,32,16,true,RGB(0,0,0) GetImage 2,0,0,64,64 PrepareFXImage 2 ; ============================= ; Part 2- Create some sprites ; ============================= ; Create Sprite 1, and assign it image 1 CreateSprite 1 SpriteImage 1,1 CenterSpriteHandle 1 ; Set Sprites Drawing mode to rotated SpriteDrawMode 1,2 ; Rotate this sprite 45 degree RotateSprite 1,45 ; Enable Collision for Sprite #1 SpriteCollision 1,on ; Set Sprite #1 to collision Class %0001 SpriteCollisionClass 1,%0001 ; Set Sprite #1 to collision mode to 6 (Pixel perfect) SpriteCollisionMode 1,6 ; ===================================================== ; Create a bunch of sprites to check collision against ; ===================================================== For Sprites=2 To 50 CreateSprite Sprites SpriteImage Sprites,2 CenterSpriteHandle Sprites x=Rnd(GetScreenWidth()-32) y=Rnd(GetScreenHeight()-32) PositionSprite sprites,x,y ; Set the sprites draw mode/rotation and scale SpriteDrawMode Sprites,2 RotateSprite Sprites,Rnd(360) ScaleSprite Sprites,0.5+(Rnd(100)/100.0) ; Enable Collision for this sprite SpriteCollision Sprites,on ; Set sprite to Collision Class %0010 SpriteCollisionClass Sprites,%0010 ; Set sprite to Collision mode 6 (pixel perfect) SpriteCollisionMode Sprites,6 Next ; ============================= ; Part 3- The Main Loop ; ============================= ; Start a DO/Loop Do ; Clear the screen Cls RGB(80,80,80) ; turn all the sprites For Sprites=1 To 50 SpriteDrawMode Sprites,2 If sprites>1 Then TurnSprite Sprites,0.15 SpriteCollisionDebug Sprites,Debugflag Next ; Position the Sprite 1 at the mouses position PositionSprite 1,MouseX(),MouseY() ; Check if sprite #1 hit another sprite ; of this sprite class ThisSprite=SpriteHit(1,GetFirstSprite(),%0010) ; If there was impact, then we loop through and ; find any other sprites we might have also hit While ThisSprite>0 ; set sprite to rotated + COlour Flash mode SpriteDrawMode ThisSprite,2+4096 ; Check if this sprite hit another sprite ? NextSprite=GetNextSprite(ThisSprite) ThisSprite=SpriteHit(1,NextSprite,%0010) EndWhile If SpaceKey() Then DebugFlag=1-debugFlag ; Draw All of the sprites DrawAllSprites ; Display a message SetCursor 0,0 Print "Checking For Pixel Perfect Sprite Collisions" Print "Collision Accuracy:"+Str$(GetSpriteCollisionAccuracy()) Print "Fps:"+Str$(FPS()) ; Use left/Right arrow leys to adjust the accuracy If LeftKey() And GetSpriteCollisionAccuracy()>0.2 SpriteCollisionAccuracy GetSpriteCollisionAccuracy()-0.025 FlushKeys EndIf If RightKey() And GetSpriteCollisionAccuracy()<5 SpriteCollisionAccuracy GetSpriteCollisionAccuracy()+0.025 FlushKeys EndIf ; Draw the screen Sync ; Loop back to the DO statement Loop |