Esempio n. 1
0
  //Appends a subimage
  void sprite_add_subimage(int sprid, unsigned int w, unsigned int h, unsigned char* chunk, unsigned char* collision_data, collision_type ct)
  {
	unsigned int fullwidth = nlpo2dc(w)+1, fullheight = nlpo2dc(h)+1;
    char *imgpxdata = new char[4*fullwidth*fullheight+1], *imgpxptr = imgpxdata;
    unsigned int rowindex,colindex;
    for (rowindex = 0; rowindex < h; rowindex++)
    {
      for(colindex = 0; colindex < w; colindex++)
      {
        *imgpxptr++ = *chunk++;
        *imgpxptr++ = *chunk++;
        *imgpxptr++ = *chunk++;
        *imgpxptr++ = *chunk++;
      }
      memset(imgpxptr, 0, (fullwidth-colindex) << 2);
      imgpxptr += (fullwidth-colindex) << 2;
    }
    memset(imgpxptr,0,(fullheight-h) * fullwidth);

    unsigned texture = graphics_create_texture(fullwidth,fullheight,imgpxdata,false);

    sprite* sprstr = spritestructarray[sprid];

    sprstr->texturearray.push_back(texture);
    sprstr->texbordxarray.push_back((double) w/fullwidth);
    sprstr->texbordyarray.push_back((double) h/fullheight);
    sprstr->colldata.push_back(get_collision_mask(sprstr,collision_data,ct));
	
	sprstr->subcount += 1;

    delete[] imgpxdata;
  }
Esempio n. 2
0
void SoftBody::set_collision_mask_bit(int p_bit, bool p_value) {
	uint32_t mask = get_collision_mask();
	if (p_value)
		mask |= 1 << p_bit;
	else
		mask &= ~(1 << p_bit);
	set_collision_mask(mask);
}
Esempio n. 3
0
    void sprite_add_to_index(sprite *ns, string filename, int imgnumb, bool precise, bool transparent, bool smooth, int x_offset, int y_offset)
    {
        unsigned int width, height,fullwidth, fullheight;

        unsigned char *pxdata = image_load(filename, &width, &height, &fullwidth, &fullheight);
        
        // If sprite transparent, set the alpha to zero for pixels that should be transparent from lower left pixel color
        if (pxdata && transparent)
        {
          int t_pixel_r = pxdata[(height-1)*width*4]; 
          int t_pixel_g = pxdata[(height-1)*width*4+1]; 
          int t_pixel_b = pxdata[(height-1)*width*4+2];
          unsigned int ih, iw;
          for (ih = 0; ih <= height - 1; ih++)
          {
            int tmp = ih*width*4;
            for (iw=0; iw < width; iw++)
            {
              if (pxdata[tmp] == t_pixel_r && pxdata[tmp+1] == t_pixel_g && pxdata[tmp+2] == t_pixel_b)
                pxdata[tmp+3] = 0;
              
              tmp+=4;
            }
          }
        }
        
        int cellwidth =width/imgnumb;

        ns->id = sprite_idmax;
        ns->subcount  = imgnumb;
        ns->width     = cellwidth;
        ns->height    = height;
        // FIXME: Calculate and assign correct bbox values.
        int bbb = height;
        int bbl = 0;
        int bbt = 0;
        int bbr = cellwidth;
        ns->bbox.bottom  = bbb;
          ns->bbox.left  = bbl;
          ns->bbox.top   = bbt;
          ns->bbox.right = bbr;
        ns->bbox_relative.bottom  = bbb - y_offset;
          ns->bbox_relative.left  = bbl - x_offset;
          ns->bbox_relative.top   = bbt - y_offset;
          ns->bbox_relative.right = bbr - x_offset;
        ns->xoffset   = (int)x_offset;
        ns->yoffset   = (int)y_offset;

        unsigned char* pixels=new unsigned char[cellwidth*height*4]();
        for (int ii=0;ii<imgnumb;ii++) 
        {
                int ih,iw;
                int xcelloffset=ii*cellwidth*4;
                for(ih = height - 1; ih >= 0; ih--)
                {
                        int tmp = ih*fullwidth*4+xcelloffset;
                        int tmpcell = ih*cellwidth*4;
                        for (iw=0; iw < cellwidth; iw++)
                        {
                                pixels[tmpcell+3] = pxdata[tmp+3];
                                pixels[tmpcell+2] = pxdata[tmp+2];
                                pixels[tmpcell+1] = pxdata[tmp+1];
                                pixels[tmpcell] = pxdata[tmp];
                                tmp+=4;
                                tmpcell+=4;
                        }
                }
                unsigned texture = graphics_create_texture(cellwidth, fullheight, pixels, false);
                ns->texturearray.push_back(texture);
                ns->texbordxarray.push_back((double) 1.0);//width/fullwidth;
                ns->texbordyarray.push_back((double) height/fullheight);
				
                collision_type coll_type = precise ? ct_precise : ct_bbox;
                ns->colldata.push_back(get_collision_mask(ns,(unsigned char*)pixels,coll_type));
        }
        delete[] pixels;
        delete[] pxdata;
    }
Esempio n. 4
0
bool Area::get_collision_mask_bit(int p_bit) const{

	return get_collision_mask()&(1<<p_bit);
}
Esempio n. 5
0
bool SoftBody::get_collision_mask_bit(int p_bit) const {
	return get_collision_mask() & (1 << p_bit);
}
Esempio n. 6
0
bool RayCast2D::get_collision_mask_bit(int p_bit) const {

	return get_collision_mask() & (1 << p_bit);
}