void WordTreeScene::updatePhysics(Word* word) { cpShape* shape = word->getShape(); if( shape!=NULL ) { cpSpaceRemoveShape(ChipmunkManager::getInstance()->getSpace(), shape); cpShapeDestroy(shape); word->setShape(NULL); } cpBody* body = word->getBody(); if( body!=NULL ) { cpSpaceRemoveBody(ChipmunkManager::getInstance()->getSpace(), body); cpBodyDestroy(body); word->setBody(NULL); } CCLabelTTF* targetLabel = word->getLabel(); CCPoint pos = targetLabel->getPosition(); CCSize contentSize = targetLabel->getContentSize(); // init body body = cpBodyNew(1, INFINITY); body->p = cpv(targetLabel->getPosition().x, targetLabel->getPosition().y); cpSpaceAddBody(ChipmunkManager::getInstance()->getSpace(), body); float size = MAX(targetLabel->getContentSize().width, targetLabel->getContentSize().height); shape = cpBoxShapeNew(body, size+size*0.3f, size+size*0.3f); cpSpaceAddShape(ChipmunkManager::getInstance()->getSpace(), shape); word->setBody(body); word->setShape(shape); }
/** * Initializes a new player. * The player is placed in the queue of available players. */ struct player *player_init(struct player *p, struct game *g, double x, double y, double w, double h, uint32_t score, uint8_t data) { cpVect all[4] = {cpv(0,0), cpv(0,h), cpv(w,h), cpv(w,0)}; cpBody *body = cpBodyInit(&p->body, 10, cpMomentForBox(10, w, h)); if (!body) { ERR_ERRNO(); return 0; } cpBodySetPos(body, cpv(x,y)); //cpShape *shape = cpPolyShapeNew(body,4,all,cpv((p->l+p->r)/2.0,(p->b+p->t)/2.0)); cpShape *shape = cpPolyShapeInit(&p->shape, body, 4, all, cpv(0, 0)); if (!shape) { ERR_ERRNO(); cpBodyDestroy(body); return 0; } shape->data = p; shape->collision_type = PLAYER; if (linkedlist_add_last(g->p_q, p)) { ERR_TRACE(); cpBodyDestroy(body); cpShapeDestroy(shape); return 0; } p->x = x; p->y = y; p->node = g->p_q->last; return p; }
void cpShapeFree(cpShape *shape) { if(shape){ cpShapeDestroy(shape); cpfree(shape); } }
static void free_shape(cpBody *body, cpShape *shape, void *data) { cpSpace *space = cpBodyGetSpace(body); cpSpaceRemoveShape(space, shape); cpShapeDestroy(shape); cpShapeFree(shape); }
void wall_destroy(struct wall *w) { cpShapeDestroy(&w->shape); }
/** * Free up any internal memory. */ void player_destroy(struct player *p) { if (p->client) p->client->p = 0; cpShapeDestroy((struct cpShape *)&p->shape); cpBodyDestroy(&p->body); }
/** * Frees any internal memory of the bubble. */ void bubble_destroy(struct bubble *b) { cpShapeDestroy(&b->shape); cpBodyDestroy(&b->body); }