コード例 #1
0
ファイル: main.cpp プロジェクト: cyclohexanamine/shipbrain
static cpBool scorecollision(cpArbiter *arb, cpSpace *space, void *data)
{
	cpShape** a = new cpShape*;
	cpShape** b = new cpShape*;
	cpArbiterGetShapes(arb, a, b);
	
	Ship* s = 0;
	Shell* sh = 0;
	if (cpShapeGetCollisionType(*a) == 1)
	{
		s = (Ship*)cpShapeGetUserData(*a);
		sh = (Shell*)cpShapeGetUserData(*b);
	}
	else
	{
		s = (Ship*)cpShapeGetUserData(*b);
		sh = (Shell*)cpShapeGetUserData(*a);
	}
	
	s->score -= 1;
	s->target->score += 2;
	
	listappend<Shell*>(rshell, nrshell, sh);
	
	return cpTrue;
}
コード例 #2
0
ファイル: explosive.cpp プロジェクト: teritriano/ftf
int fff::explosive::Begin(cpArbiter *arb, cpSpace *space, void *pengine){
    CP_ARBITER_GET_SHAPES(arb, explosiveshape, kittyshape);
    fff::explosive *explosive = static_cast<fff::explosive *>( cpShapeGetUserData(explosiveshape) );
    fff::kitty *kitty = static_cast<fff::kitty *>( cpShapeGetUserData(kittyshape) );
    kitty->applyImpulse(explosive->impulse);
    explosive->setExploding();
    game.playExplosion(explosive->soundbuffer, explosive->sprite.GetPosition() );
    cpSpaceAddPostStepCallback(space, fff::explosive::postStep, explosiveshape, NULL);
    game.startTheme();
    return 0;
}
コード例 #3
0
cpBool PhysicsWorldCallback::collisionBeginCallbackFunc(cpArbiter *arb, struct cpSpace *space, PhysicsWorld *world)
{
    CP_ARBITER_GET_SHAPES(arb, a, b);
    
    PhysicsShape *shapeA = static_cast<PhysicsShape*>(cpShapeGetUserData(a));
    PhysicsShape *shapeB = static_cast<PhysicsShape*>(cpShapeGetUserData(b));
    CC_ASSERT(shapeA != nullptr && shapeB != nullptr);
    
    auto contact = PhysicsContact::construct(shapeA, shapeB);
    cpArbiterSetUserData(arb, contact);
    contact->_contactInfo = arb;
    
    return world->collisionBeginCallback(*contact);
}
コード例 #4
0
ファイル: rcpcollision.cpp プロジェクト: trsquarelab/csscene
void RCPCollision::separateFunc(cpArbiter *arb, cpSpace *space, cpDataPointer userData)
{
    RCPCollision * collision = (RCPCollision *)userData;
    if (collision && collision->mSeparateFunc) {
        CP_ARBITER_GET_SHAPES(arb, cpsA, cpsB);
        RItem * itemA = (RItem *)cpShapeGetUserData(cpsA);
        RItem * itemB = (RItem *)cpShapeGetUserData(cpsB);

        RCPShapeItem * shapeA = dynamic_cast<RCPShapeItem *>(itemA);
        RCPShapeItem * shapeB = dynamic_cast<RCPShapeItem *>(itemB);

        collision->mSeparateFunc->handle(RCollisionEvent(shapeA, shapeB));
    }
}
コード例 #5
0
PhysicsShape* PhysicsWorld::getShape(const Vec2& point) const
{
    cpShape* shape = cpSpacePointQueryNearest(_cpSpace,
                                    PhysicsHelper::point2cpv(point),
                                    0,
                                    CP_SHAPE_FILTER_ALL,
                                    nullptr);
    return shape == nullptr ? nullptr : static_cast<PhysicsShape*>(cpShapeGetUserData(shape));
}
コード例 #6
0
void PhysicsWorldCallback::queryRectCallbackFunc(cpShape *shape, RectQueryCallbackInfo *info)
{
    PhysicsShape *physicsShape = static_cast<PhysicsShape*>(cpShapeGetUserData(shape));
    CC_ASSERT(physicsShape != nullptr);
    
    if (!PhysicsWorldCallback::continues)
    {
        return;
    }
    
    PhysicsWorldCallback::continues = info->func(*info->world, *physicsShape, info->data);
}
コード例 #7
0
static cpBool
PreSolve(cpArbiter *arb, cpSpace *space, void *ignore)
{
	CP_ARBITER_GET_SHAPES(arb, a, b);
	OneWayPlatform *platform = (OneWayPlatform *)cpShapeGetUserData(a);
		
	if(cpvdot(cpArbiterGetNormal(arb), platform->n) < 0){
		return cpArbiterIgnore(arb);
	}
	
	return cpTrue;
}
コード例 #8
0
ファイル: Renderer.cpp プロジェクト: eka-tel72/tumbler_maze
void Renderer::createDebugTumbler(cpBody* body, const sf::Vector2u& tumblerSize,
                                  std::vector<SpritePiece>* pieces) {
  mTargetSize = tumblerSize;
  initTargets();

  cpBodyEachShape(body, [](cpBody* body, cpShape* shape, void* data) {
    auto type = reinterpret_cast<ShapeType*>(cpShapeGetUserData(shape));
    if (*type != ShapeType::Segment) return;

    reinterpret_cast<Renderer*>(data)->drawBar(shape);
  }, this);

  createPieces(pieces);
}
コード例 #9
0
ファイル: physics.c プロジェクト: andi2/cgame
NearestResult physics_nearest(Vec2 point, Scalar max_dist)
{
    cpNearestPointQueryInfo info;
    NearestResult res;

    if (!cpSpaceNearestPointQueryNearest(space, cpv_of_vec2(point), max_dist,
                                         CP_ALL_LAYERS, CP_NO_GROUP, &info))
    {
        /* no result */
        res.ent = entity_nil;
        return res;
    }

    res.ent = cpShapeGetUserData(info.shape);
    res.p = vec2_of_cpv(info.p);
    res.d = info.d;
    res.g = vec2_of_cpv(info.g);
    return res;
}
コード例 #10
0
void PhysicsWorldCallback::rayCastCallbackFunc(cpShape *shape, cpVect point, cpVect normal, cpFloat alpha, RayCastCallbackInfo *info)
{
    if (!PhysicsWorldCallback::continues)
    {
        return;
    }
    
    PhysicsShape *physicsShape = static_cast<PhysicsShape*>(cpShapeGetUserData(shape));
    CC_ASSERT(physicsShape != nullptr);
    
    PhysicsRayCastInfo callbackInfo =
    {
        physicsShape,
        info->p1,
        info->p2,
        PhysicsHelper::cpv2point(point),
        PhysicsHelper::cpv2point(normal),
        static_cast<float>(alpha),
    };
    
    PhysicsWorldCallback::continues = info->func(*info->world, callbackInfo, info->data);
}
コード例 #11
0
ファイル: core.c プロジェクト: nicole-hedley/asteroid-game
// adds an impulse shape to the cpSpace 
cpBody * core_add_new_shape_with_impulse ( cpSpace *space, const int type, const double p1x, const double p1y, const double p2x, const double p2y, Color *color, const double orientation, const double friction, const double elasticity, const double density, const int index, cpVect impulse, cpVect offset ) {
    
    cpShape * shape;
    
    if ( type == BOX_TYPE || type == CIRCLE_TYPE ) {
        shape = core_add_new_shape ( space, type, p1x, p1y, p2x, p2y, color, orientation, friction, elasticity, density, index );
        
    } else {
        shape = core_add_single_segment_shape ( space, p1x, p1y, p2x, p2y, color, friction, elasticity, density, index );
        
    } if ( shape == NULL ) return NULL;
    
    DrawShapeInfo *info = cpShapeGetUserData ( shape );
    info->space_shape_type = SPACE_TYPE_PLANET_R;

    
    cpBody *body = cpShapeGetBody ( shape );
    
    impulse = cpv ( impulse.x * IMPULSE_MULTIPLIER, impulse.y * IMPULSE_MULTIPLIER );
    
    cpBodyApplyImpulse ( body, impulse, offset );
    
    return body;
}
コード例 #12
0
ファイル: SolArbiter.cpp プロジェクト: gwthomas/sol-framework
 std::pair<Shape*, Shape*> Arbiter::getShapes() const
 {
     cpShape* a, * b;
     cpArbiterGetShapes(_arbiter, &a, &b);
     return std::make_pair((Shape*)cpShapeGetUserData(a), (Shape*)cpShapeGetUserData(b));
 }
コード例 #13
0
void PhysicsWorldCallback::queryPointFunc(cpShape *shape, cpVect point, cpFloat distance, cpVect gradient, PointQueryCallbackInfo *info)
{
    PhysicsShape *physicsShape = static_cast<PhysicsShape*>(cpShapeGetUserData(shape));
    CC_ASSERT(physicsShape != nullptr);
    PhysicsWorldCallback::continues = info->func(*info->world, *physicsShape, info->data);
}
コード例 #14
0
void PhysicsWorldCallback::getShapesAtPointFunc(cpShape *shape, cpVect point, cpFloat distance, cpVect gradient, Vector<PhysicsShape*>* arr)
{
    PhysicsShape *physicsShape = static_cast<PhysicsShape*>(cpShapeGetUserData(shape));
    CC_ASSERT(physicsShape != nullptr);
    arr->pushBack(physicsShape);
}
コード例 #15
0
ファイル: core.c プロジェクト: nicole-hedley/asteroid-game
// make a homebase
void core_make_homebase ( cpSpace *space, const double x, const double y, const int start_index, const int planet_num){
    
    Box *defense[4]; 
    
    double r = (double)rand()/(double)RAND_MAX;
    double g = (double)rand()/(double)RAND_MAX;
    double b = (double)rand()/(double)RAND_MAX;
    
    for( int i = 0; i < 4; i++){
        defense[i] = box_new();
        defense[i]->color->r = r;
        defense[i]->color->g = g;
        defense[i]->color->b = b;
        defense[i]->orientation = 0;
        defense[i]->friction = 0;
        defense[i]->elasticity = 1;
        defense[i]->density = 20;
        defense[i]->width = SIDE_WIDTH;
        defense[i]->height = SIDE_HEIGHT;
    }
    
    defense[0]->x = x-SIDE_HEIGHT/2;
    defense[0]->y = y-SIDE_OFFSET;
    defense[1]->x = x-SIDE_OFFSET;
    defense[1]->y = y+SIDE_HEIGHT/2;
    defense[2]->x = x+SIDE_HEIGHT/2;
    defense[2]->y = y+SIDE_OFFSET;
    defense[3]->x = x+SIDE_OFFSET;
    defense[3]->y = y-SIDE_HEIGHT/2;
    
    cpShape *side;
    BodyInfo *sidebi;

    for(int i = 0; i< 4; i++){

        side = core_add_box_shape (space, defense[i], start_index+i);
        cpBodySetAngle(side->body, PI*i/2);
        
        sidebi = (BodyInfo *) (side->body->data);
        sidebi->space_shape_type = -1; // make it so sides don't timeout

    }
    
    for(int i = 0; i< 4; i++){
       box_destroy (defense[i]); 
    }
    
    Circle *planet; 
    
    
    planet = circle_new();
    planet->color->r = r;
    planet->color->g = g;
    planet->color->b = b;
    planet->orientation = 0;
    planet->friction = 0;
    planet->elasticity = 1;
    planet->density = 200;
    planet->radius = CORE_RADIUS;
    
    planet->x = x;
    planet->y = y;
    
    cpShape *core = core_add_circle_shape (space, planet, start_index+4);
    
    cpShapeSetCollisionType ( core, GOAL_COLLISION_TYPE );

    //pjw midnite
    DrawShapeInfo *info = (DrawShapeInfo *)cpShapeGetUserData(core);
    info->originx = x;
    info->originy = y;

    BodyInfo *bi = (BodyInfo *)core->body->data;
    bi->originx = x;
    bi->originy = y;
    bi->space_shape_type = planet_num;
    
    info->space_shape_type = planet_num;
    
    circle_destroy (planet);
}