Beispiel #1
0
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;
}
Beispiel #2
0
static cpBool
catcherBarBegin(cpArbiter *arb, cpSpace *space, void *unused)
{
	cpShape *a, *b; cpArbiterGetShapes(arb, &a, &b);
	Emitter *emitter = (Emitter *) a->data;
	
	emitter->queue++;
	cpSpaceAddPostStepCallback(space, (cpPostStepFunc)postStepRemove, b, NULL);
	
	return cpFalse;
}
Beispiel #3
0
void DynamiUint_separate( cpArbiter* arb, cpSpace* space, void* unused )
{
	cpShape *a, *b;
	cpArbiterGetShapes(arb, &a, &b);

	if( a && b ){
		UnitDynamic* ua = reinterpret_cast<UnitDynamic*>(a->body->data);
		Unit* ub = reinterpret_cast<Unit*>(b->body->data);
		if( ua && ub )
			ua->removeFromScope( ub );
	}
}
Beispiel #4
0
int DynamiUint_begin( cpArbiter* arb, cpSpace* space, void* unused )
{
	cpShape *a, *b;
	cpArbiterGetShapes(arb, &a, &b);

	if( a && b ){
		UnitDynamic* ua = reinterpret_cast<UnitDynamic*>(a->body->data);
		Unit* ub = reinterpret_cast<Unit*>(b->body->data);
		if( ua && ub )
			ua->addToScope( ub );
	}
	return 0;
}
static mrb_value
arbiter_shapes(mrb_state* mrb, mrb_value self)
{
  cpArbiter* arbiter;
  cpShape* shape1;
  cpShape* shape2;
  mrb_value argv[2] = { mrb_nil_value(), mrb_nil_value() };
  shape1 = NULL;
  shape2 = NULL;
  arbiter = mrb_cp_get_arbiter_ptr(mrb, self);
  cpArbiterGetShapes(arbiter, &shape1, &shape2);
  argv[0] = mrb_cp_shape_get_mrb_obj(mrb, shape1);
  argv[1] = mrb_cp_shape_get_mrb_obj(mrb, shape2);
  return mrb_ary_new_from_values(mrb, 2, argv);
}
Beispiel #6
0
static cpBool bulletPlaneBeginFunc(cpArbiter *arb, cpSpace *space, void*) {
    cpShape *a,*b;
    cpArbiterGetShapes(arb, &a,&b);
    cpBody *targetBody = cpShapeGetBody(b);
    if (((Bullet *)cpBodyGetUserData(cpShapeGetBody(a)))->player()->body() != targetBody) {
        printf("Hit plane\n");
        Player * player = (Player *)(cpBodyGetUserData(targetBody));
        player->hurt(200);

        cpSpaceAddPostStepCallback( space, (cpPostStepFunc)ammoFree, a, NULL);

        return true;
    }
    return false;
}
Beispiel #7
0
void cArbiter::GetShapes( cShape ** a, cShape ** b ) {
	cpShape * tA;
	cpShape * tB;

	cpArbiterGetShapes( mArbiter, &tA, &tB );

	if ( NULL != tA )
		*a = reinterpret_cast<cShape*>( tA->data );
	else
		*a = NULL;

	if ( NULL != tB )
		*b = reinterpret_cast<cShape*>( tB->data );
	else
		*b = NULL;
}
Beispiel #8
0
//----------------------------------------------------------------//
static int _cpCollisionFunc ( cpArbiter* arb, void* data, u32 eventType, bool checkResult ) {

	MOAICpCollisionHandler* handler = ( MOAICpCollisionHandler* )data;
	if ( handler->mMask & eventType ) {

		// this can be called during shutdown, so make sure the runtime is still valid
		if ( MOAILuaRuntime::IsValid ()) {

			MOAIScopedLuaState state = MOAILuaRuntime::Get ().State ();
			if ( handler->mHandler.PushRef ( state )) {
				
				cpShape* a;
				cpShape* b;
				cpArbiterGetShapes ( arb, &a, &b );
				
				if ( a && b ) {
					
					state.Push ( eventType );
					(( MOAICpShape* )a->data )->PushLuaUserdata ( state );
					(( MOAICpShape* )b->data )->PushLuaUserdata ( state );
					
					MOAICpArbiter* arbiter = handler->mSpace->GetArbiter ();
					arbiter->SetArbiter ( arb );
					arbiter->PushLuaUserdata ( state );
					
					state.DebugCall ( 4, 1 );
					
					//lua_call ( state, 4, 1 );
					
					if ( checkResult ) {
						bool result = state.GetValue < bool >( -1, true );
						return result ? cpTrue : cpFalse;
					}
				}
			}
		}
	}
	return cpTrue;
}
Beispiel #9
0
 std::pair<Shape*, Shape*> Arbiter::getShapes() const
 {
     cpShape* a, * b;
     cpArbiterGetShapes(_arbiter, &a, &b);
     return std::make_pair((Shape*)cpShapeGetUserData(a), (Shape*)cpShapeGetUserData(b));
 }
Beispiel #10
0
static cpBool bulletCloudBeginFunc(cpArbiter *arb, cpSpace *space, void*) {
    cpShape *a,*b;
    cpArbiterGetShapes(arb, &a,&b);

    return false;
}
Beispiel #11
0
static void planeCloudSepFunc(cpArbiter *arb, cpSpace *space, void*) {
    cpShape *a,*b;
    cpArbiterGetShapes(arb, &a,&b);
    planeCloud(a, -5);
}