@ windows killer
I don't get how to use your code heres what i've done
remstart
space invader tut
remend
sync on
load bitmap "media/master.bmp" ,0
`CODE FOR GETTING IMAGES FROM THE BOXES
FOR W=0 TO 6
FOR I=0 TO 9
GET IMAGE 1+I+10*W,0+60*I,0+W*60,60+60*I,60+W*60
NEXT I
NEXT W
cls
shipy = 416
shipx = 293
REM ***********************************************************************************
REM * Ultimate Pixel-Perfect Sprite Collision for DarkBASIC Professional, Version 2.0 *
REM ***********************************************************************************
REM * Original Code by IanM *
REM * Enhancements by Timo Weirich a.k.a. WindowsKiller (webmaster@retro-net.de) *
REM ***********************************************************************************
REM * Version History: *
REM * v1.0: Added support for animated sprites *
REM * v2.0: Added support for 16-bit color modes, 0 as target sprite, bug fixes *
REM ***********************************************************************************
FUNCTION SpriteCollision(Sprite1,Sprite2)
IF Sprite2 = 0 THEN EXITFUNCTION SPRITE COLLISION(Sprite1,0)
LOCAL MinAlpha AS DWORD = 128 ` for 32-bit color modes only!
LOCAL MMax1 AS DWORD
LOCAL MMax2 AS DWORD
LOCAL Sprite1Addr AS DWORD : LOCAL Sprite1Base AS DWORD
LOCAL Sprite2Addr AS DWORD : LOCAL Sprite2Base AS DWORD
LOCAL V16 AS WORD
LOCAL V32 AS DWORD
LOCAL MemBlock1 AS INTEGER = 252 : LOCAL MemBlock3 AS INTEGER = 254
LOCAL MemBlock2 AS INTEGER = 253 : LOCAL MemBlock4 AS INTEGER = 255
GLOBAL BytesPerPixel AS INTEGER = BytesPerPixel
IF BytesPerPixel = 0 THEN BytesPerPixel = SCREEN DEPTH()/8
IF SPRITE COLLISION(Sprite1,Sprite2) = 1
MAKE MEMBLOCK FROM IMAGE MemBlock1,SPRITE IMAGE(Sprite1)
MAKE MEMBLOCK FROM IMAGE MemBlock2,SPRITE IMAGE(Sprite2)
IF MEMBLOCK DWORD(MemBlock1,0) > SPRITE WIDTH(Sprite1) OR MEMBLOCK DWORD(MemBlock1,4) > SPRITE HEIGHT(Sprite1)
across = MEMBLOCK DWORD(MemBlock1,0)/SPRITE WIDTH(Sprite1)
down = MEMBLOCK DWORD(MemBlock1,4)/SPRITE HEIGHT(Sprite1)
SpritesheetToFrame(across,down,SPRITE FRAME(Sprite1),MemBlock1,MemBlock3)
MemBlock1 = MemBlock3
ENDIF
IF MEMBLOCK DWORD(MemBlock2,0) > SPRITE WIDTH(Sprite2) OR MEMBLOCK DWORD(MemBlock2,4) > SPRITE HEIGHT(Sprite2)
across = MEMBLOCK DWORD(MemBlock2,0)/SPRITE WIDTH(Sprite2)
down = MEMBLOCK DWORD(MemBlock2,4)/SPRITE HEIGHT(Sprite2)
SpritesheetToFrame(across,down,SPRITE FRAME(Sprite2),MemBlock2,MemBlock4)
MemBlock2 = MemBlock4
ENDIF
Sprite1Base = GET MEMBLOCK PTR(MemBlock1)
Sprite2Base = GET MEMBLOCK PTR(MemBlock2)
MMax1 = Sprite1Base+GET MEMBLOCK SIZE(MemBlock1)
MMax2 = Sprite2Base+GET MEMBLOCK SIZE(MemBlock2)
XPos1 = SPRITE X(Sprite1)
YPos1 = SPRITE Y(Sprite1)
Width1 = *Sprite1Base
INC Sprite1Base,4
Height1 = *Sprite1Base
INC Sprite1Base,8
XPos2 = SPRITE X(Sprite2)-SPRITE OFFSET X(Sprite2)+SPRITE OFFSET X(Sprite1)
YPos2 = SPRITE Y(Sprite2)-SPRITE OFFSET Y(Sprite2)+SPRITE OFFSET Y(Sprite1)
Width2 = *Sprite2Base
INC Sprite2Base,4
Height2 = *Sprite2Base
INC Sprite2Base,8
IF XPos2 > XPos1
XStart1 = XPos2-XPos1
XStart2 = 0
XOverlapSize = Width1-XStart1-1
IF XOverlapSize => Width2 THEN XOverlapSize = Width2-1
ELSE
XStart1 = 0
XStart2 = XPos1-XPos2
XOverlapSize = Width2-XStart2-1
IF XOverlapSize => Width1 THEN XOverlapSize = Width1-1
ENDIF
IF YPos2 > YPos1
YStart1 = YPos2-YPos1
YStart2 = 0
YOverlapSize = Height1-YStart1-1
IF YOverlapSize => Height2 THEN YOverlapSize = Height2-1
ELSE
YStart1 = 0
YStart2 = YPos1-YPos2
YOverlapSize = Height2-YStart2-1
IF YOverlapSize => Height1 THEN YOperlapSize = Height1-1
ENDIF
XStart1 = XStart1*BytesPerPixel : Width1 = Width1*BytesPerPixel
XStart2 = XStart2*BytesPerPixel : Width2 = Width2*BytesPerPixel
FOR YOffset = YOverlapSize TO 0 STEP -1
Sprite1Addr = Sprite1Base+((YOffset+YStart1)*Width1)+XStart1
Sprite2Addr = Sprite2Base+((YOffset+YStart2)*Width2)+XStart2
FOR XOffset = XOverlapSize TO 0 STEP -1
IF Sprite1Addr => MMax1 OR Sprite2Addr => MMax2 THEN EXIT
SELECT BytesPerPixel
CASE 2
V16 = *Sprite1Addr
IF (V16 >> 15) = 1
V16 = *Sprite2Addr
IF (V16 >> 15) = 1
DELETE MEMBLOCK MemBlock1 : DELETE MEMBLOCK MemBlock2 : EXITFUNCTION 1
ENDIF
ENDIF
ENDCASE
CASE 4
V32 = *Sprite1Addr
IF (V32 >> 24) => MinAlpha
V32 = *Sprite2Addr
IF (V32 >> 24) => MinAlpha
DELETE MEMBLOCK MemBlock1 : DELETE MEMBLOCK MemBlock2 : EXITFUNCTION 1
ENDIF
ENDIF
ENDCASE
ENDSELECT
INC Sprite1Addr,BytesPerPixel
INC Sprite2Addr,BytesPerPixel
NEXT XOffset
NEXT YOffset
DELETE MEMBLOCK MemBlock1
DELETE MEMBLOCK MemBlock2
ENDIF
ENDFUNCTION 0
FUNCTION SpritesheetToFrame(tiles_across,tiles_down,frame_num,source_mem,target_mem)
GLOBAL bytes_per_pixel AS INTEGER = bytes_per_pixel
IF bytes_per_pixel = 0 THEN bytes_per_pixel = SCREEN DEPTH()/8
spritesheet_width = MEMBLOCK DWORD(source_mem,0)
frame_width = spritesheet_width / tiles_across
frame_height = MEMBLOCK DWORD(source_mem,4) / tiles_down
MAKE MEMBLOCK target_mem,(frame_width*frame_height*bytes_per_pixel)+12
WRITE MEMBLOCK DWORD target_mem,0,frame_width
WRITE MEMBLOCK DWORD target_mem,4,frame_height
WRITE MEMBLOCK DWORD target_mem,8,bytes_per_pixel*8
IF frame_num > tiles_across THEN downskip = INT((frame_num-1)/tiles_across)
offset = ((frame_num-1) MOD tiles_across)*frame_width*bytes_per_pixel
mem1pos = (tiles_across*downskip*frame_width*frame_height*bytes_per_pixel)+12+offset
mem2pos = 12
bytes2copy = frame_width*bytes_per_pixel
bytes2skip = spritesheet_width*bytes_per_pixel
FOR row = 1 TO frame_height
COPY MEMBLOCK source_mem,target_mem,mem1pos,mem2pos,bytes2copy
INC mem1pos,bytes2skip
INC mem2pos,bytes2copy
NEXT row
DELETE MEMBLOCK source_mem
ENDFUNCTION
do
sprite 1,shipx,shipy,1
sprite 2,0,0,2
if sprite collision(1,2)
print "Omg this still doesn't work"
endif
if downkey() = 1
shipy=shipy+1
endif
if upkey() = 1
shipy=shipy-1
endif
if rightkey() = 1
shipx=shipx+1
endif
if leftkey() = 1
shipx=shipx-1
endif
sync
cls
print "shipx" ;shipx
print "shipy" ;shipy
loop
it says you must hit a function declartion in mid program
[edit]
one more question can you only use this for 2 sprites?
Windows Is better than everything