/******************************************* isCollide 检查 obj 是否碰撞到 hitter 一般认为hitter比较小 *******************************************/ bool Entity::collide(Entity &hitter) { for (int i = hitter.scr_x; i < hitter.scr_x + hitter.width; i++) { for (int j = hitter.scr_y; j < hitter.scr_y + hitter.height; j++) { if (hitter.getChar(i, j) == JMP_CHAR) continue; if (isInImage(i, j)) return true; } } return false; }
//gets a pixel bounded by the image border pixel_RGB getBoundPixel(ARVP_Image* img,int coordY,int coordX) { //printf("GETTING BOUND PIXEL (%i,%i)\n",coordY,coordX); if(!isInImage(img,coordY,coordX)) { if(coordX<0) coordX=0; else if(coordX>=int(img->width)) coordX=img->width-1; if(coordY<0) coordY=0; else if(coordY>=int(img->height)) coordY=img->height-1; } return img->get((unsigned int)(coordY),(unsigned int)(coordX)); }
//get a pixel but don't go out of bounds unsigned char getBoundChannel(ARVP_Image* img,unsigned int ch,int targY,int targX) { int coordY=targY; int coordX=targX; if(!isInImage(img,coordY,coordX)) { if(coordX<0) coordX=0; else if(coordX>=int(img->width)) coordX=img->width-1; if(coordY<0) coordY=0; else if(coordY>=int(img->height)) coordY=img->height-1; } //printf("GETTING BOUND CHANNEL (%i,%i,%i)\n",(int)ch,coordY,coordX); return img->get_ch(ch,(coordY),(coordX)); }