bgget
Root / Programming Questions / [.]
KomodoCreated:
BGGet(X,Y,F) return the cell on the coordinate X,Y. X,Y could be pixel unit if F == 1 or tile unit if F == 0.
The first 12 bits represent the tile, the rest are used for transformation.
You could do something like this:
// SP is the management number of the sprite // VX and VY are the speed in pixel unit // Return true if the sprite overlap a tile different to 0 DEF collisionWithBG(SP,VX,VY) VAR X,Y,W,H,C C=0 SPCOL SP OUT X,Y,W,H INC X,VX INC X,VY INC W,VX INC H,VY INC C,BGGET(X,Y,1) INC C,BGGET(X+W,Y,1) INC C,BGGET(X,Y+H,1) INC C,BGGET(X+W,Y+H,1) RETURN C ENDThe code above get the collider of the sprite and then check if it overlap a tile different to 0(Empty). If you want to know if the collider is overlapping certain tile then you could do something like this.
// SP is the management number of the sprite // VX and VY are the speed in pixel unit // T is the tile id without transformation. // Return true if the sprite overlap a tile T. DEF collisionWIthTileT(T,SP,VX,VY) VAR X,Y,W,H,C VAR FILTER=&B111111111111 C=0 SPCOL SP OUT X,Y,W,H INC X,VX INC X,VY INC W,VX INC H,VY INC C, (BGGET(X,Y,1) AND FILTER)==T INC C, (BGGET(X+W,Y,1) AND FILTER)==T INC C, (BGGET(X,Y+H,1) AND FILTER)==T INC C, (BGGET(X+W,Y+H,1) AND FILTER)==T RETURN C END